1
|
|
|
<?php defined('SYSPATH') OR die('No direct access allowed.'); |
2
|
|
|
/** |
3
|
|
|
* Default auth user. |
4
|
|
|
* |
5
|
|
|
* @package Kohana/Auth |
6
|
|
|
* @author Ivan Kerin |
7
|
|
|
* @copyright (c) 2011-2012 Despark Ltd. |
8
|
|
|
* @author creatoro |
9
|
|
|
* @copyright (c) 2011 creatoro |
10
|
|
|
* @license http://creativecommons.org/licenses/by-sa/3.0/legalcode |
11
|
|
|
*/ |
12
|
|
|
class Kohana_Model_Auth_User extends Jam_Model { |
13
|
|
|
|
14
|
|
|
public $validate_password = FALSE; |
15
|
|
|
|
16
|
|
|
public static function initialize(Jam_Meta $meta) |
17
|
|
|
{ |
18
|
|
|
$meta |
19
|
|
|
->name_key('email') |
20
|
|
|
|
21
|
|
|
->associations(array( |
22
|
|
|
'user_tokens' => Jam::association('hasmany'), |
23
|
|
|
'roles' => Jam::association('manytomany'), |
24
|
|
|
)) |
25
|
|
|
|
26
|
|
|
->fields(array( |
27
|
|
|
'id' => Jam::field('primary'), |
28
|
|
|
'email' => Jam::field('string', array( |
29
|
|
|
'label' => 'email address', |
30
|
|
|
)), |
31
|
|
|
'password' => Jam::field('password', array( |
32
|
|
|
'hash_with' => array(Auth::instance(), 'hash'), |
33
|
|
|
)), |
34
|
|
|
'logins' => Jam::field('integer', array( |
35
|
|
|
'default' => 0, |
36
|
|
|
'convert_empty' => TRUE, |
37
|
|
|
'empty_value' => 0, |
38
|
|
|
)), |
39
|
|
|
'last_login' => Jam::field('timestamp'), |
40
|
|
|
'facebook_uid' => Jam::field('string'), |
41
|
|
|
'twitter_uid' => Jam::field('string'), |
42
|
|
|
'last_login_ip' => Jam::field('string', array('label' => 'Last logged from')), |
43
|
|
|
)) |
44
|
|
|
|
45
|
|
|
->validator('email', array( |
46
|
|
|
'format' => array('email' => TRUE), |
47
|
|
|
'unique' => TRUE |
48
|
|
|
)) |
49
|
|
|
->validator('password', array( |
50
|
|
|
'length' => array('minimum' => 5, 'maximum' => 30), |
51
|
|
|
'if' => 'validate_password', |
52
|
|
|
)) |
53
|
|
|
->validator('last_login_ip', array( |
54
|
|
|
'format' => array('filter' => FILTER_VALIDATE_IP), |
55
|
|
|
)) |
56
|
|
|
->validator('password', array( |
57
|
|
|
'if' => 'validate_password', |
58
|
|
|
'present' => TRUE, |
59
|
|
|
'confirmed' => TRUE, |
60
|
|
|
)) |
61
|
|
|
->validator('password_confirmation', array( |
62
|
|
|
'present' => TRUE, |
63
|
|
|
'if' => 'validate_password', |
64
|
|
|
)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public static function unique_key($value) |
68
|
|
|
{ |
69
|
|
|
return (is_numeric($value) OR $value === NULL) ? 'id' : 'email'; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Complete the login for a user by incrementing the logins and saving login timestamp |
74
|
|
|
* |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
9 |
|
public function complete_login() |
78
|
|
|
{ |
79
|
9 |
|
if ($this->loaded()) |
80
|
|
|
{ |
81
|
|
|
// Update the number of logins |
82
|
9 |
|
$this->logins = $this->logins + 1; |
|
|
|
|
83
|
|
|
|
84
|
|
|
// Set the last login date |
85
|
9 |
|
$this->last_login = time(); |
|
|
|
|
86
|
|
|
|
87
|
|
|
// Save the user |
88
|
9 |
|
$this->save(); |
89
|
|
|
} |
90
|
9 |
|
} |
91
|
|
|
|
92
|
1 |
|
public function load_service_values(Auth_Service $service, array $user_data, $create = FALSE) |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
|
95
|
1 |
|
} |
96
|
|
|
|
97
|
2 |
|
public function build_user_token(array $values = array()) |
98
|
|
|
{ |
99
|
2 |
|
return $this->user_tokens->build(Arr::merge(array( |
|
|
|
|
100
|
2 |
|
'expires' => time() + Kohana::$config->load('auth.lifetime'), |
101
|
2 |
|
), $values))->generate_unique_token(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function has_facebook() |
105
|
|
|
{ |
106
|
|
|
return (bool) $this->facebook_uid; |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
} // End Kohana_Model_Auth_User |
110
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.