-
Notifications
You must be signed in to change notification settings - Fork 66
/
user.php
87 lines (78 loc) · 2.25 KB
/
user.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
Purpose: Handles User table structure and password encryption
Copyright (c) 2015 ~ alienwithin
Munir Njiru <munir@skilledsoft.com>
@version 1.0.0
@date: 30.06.2015
@url : http://munir.skilledsoft.com
**/
namespace Model;
/**
* Defines Schema of User Table
* @package Model
*/
class User extends Mth3l3m3nt {
protected
$fieldConf = array(
'username' => array(
'type' => \DB\SQL\Schema::DT_VARCHAR128,
'nullable'=>false,
'required'=>true,
'unique'=>true,
),
'name' => array(
'type' => \DB\SQL\Schema::DT_VARCHAR128,
'required' => true,
),
'password' => array(
'type' => \DB\SQL\Schema::DT_VARCHAR256,
'nullable'=>false,
'required'=>true,
),
'email' => array(
'type' => \DB\SQL\Schema::DT_VARCHAR256,
'unique'=>true,
),
),
$table = 'user',
$db = 'DB';
/**
* crypt password
* Defines whether to use bcrypt or salted MD5
* @param $val
* @return string
*/
public function set_password($val) {
$f3 = \Base::instance();
if (!$val){
$userDetails = new self;
$userDetails->load(array('username = ?',$f3->get('POST.username')));
$val = $userDetails->password;
return $val;
}else{
$hash_engine = $f3->get('password_hash_engine');
switch($hash_engine) {
case 'bcrypt':
$crypt = \Bcrypt::instance();
$val = $crypt->hash($val);
break;
case 'md5':
// fall-through
default:
$val = md5($val.$f3->get('password_md5_salt'));
break;
}
return $val;
}
}
/**
* validate email address
* @param $val
* @return null
*/
public function set_mail($val) {
return \Validation::instance()->email($val)
? $val : null;
}
}