|
1
|
|
|
<?php defined('SYSPATH') OR die('No direct access allowed.'); |
|
2
|
|
|
/** |
|
3
|
|
|
* Default auth user toke |
|
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_Token extends Jam_Model { |
|
13
|
|
|
|
|
14
|
|
|
public static function initialize(Jam_Meta $meta) |
|
15
|
|
|
{ |
|
16
|
|
|
$meta |
|
17
|
|
|
->name_key('token') |
|
18
|
|
|
|
|
19
|
|
|
->behaviors(array( |
|
20
|
|
|
'auth_user_token' => Jam::behavior('auth_user_token'), |
|
21
|
|
|
)) |
|
22
|
|
|
|
|
23
|
|
|
->fields(array( |
|
24
|
|
|
'id' => Jam::field('primary'), |
|
25
|
|
|
'user_agent' => Jam::field('string'), |
|
26
|
|
|
'token' => Jam::field('string'), |
|
27
|
|
|
'type' => Jam::field('string'), |
|
28
|
|
|
'created' => Jam::field('timestamp', array( |
|
29
|
|
|
'auto_now_create' => TRUE, |
|
30
|
|
|
)), |
|
31
|
|
|
'expires' => Jam::field('timestamp', array( |
|
32
|
|
|
'filters' => array('Model_Auth_User_Token::convert_expires') |
|
33
|
|
|
)), |
|
34
|
|
|
)) |
|
35
|
|
|
|
|
36
|
|
|
->associations(array( |
|
37
|
|
|
'user' => Jam::association('belongsto'), |
|
38
|
|
|
)) |
|
39
|
|
|
|
|
40
|
|
|
->validator('token', array("unique" => TRUE)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
6 |
|
public static function convert_expires($value) |
|
44
|
|
|
{ |
|
45
|
6 |
|
if ( ! is_numeric($value) AND $time = strtotime($value)) |
|
46
|
|
|
{ |
|
47
|
1 |
|
return $time; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
5 |
|
return $value; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function expired() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->expires < time(); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
2 |
|
public static function generate_token() |
|
59
|
|
|
{ |
|
60
|
2 |
|
return sha1(uniqid(Text::random('alnum', 32), TRUE)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
2 |
|
public function generate_unique_token() |
|
64
|
|
|
{ |
|
65
|
|
|
do |
|
66
|
|
|
{ |
|
67
|
2 |
|
$this->token = Model_Auth_User_Token::generate_token(); |
|
|
|
|
|
|
68
|
2 |
|
$collection = Jam::all($this->meta()->model())->where_key($this->token)->limit(1); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
2 |
|
while (Jam::all($this)->where('token', '=', $this->token)->limit(1)->count_all() > 0); |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
2 |
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read 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.