1 | <?php |
||
20 | class User extends CActiveRecord |
||
21 | { |
||
22 | |||
23 | const ROLE_ADMIN = 'admin'; |
||
24 | const ROLE_USER = 'user'; |
||
25 | const ROLE_SPECTATOR = 'spectator'; |
||
26 | const ROLE_NONE = ''; |
||
27 | |||
28 | const START_PAGE_MOVIES_BROWSE = 'movie/index'; |
||
29 | const START_PAGE_MOVIES_RECENTLY_ADDED = 'movie/recentlyAdded'; |
||
30 | const START_PAGE_TVSHOWS_BROWSE = 'tvShow/index'; |
||
31 | const START_PAGE_TVSHOWS_RECENTLY_ADDED = 'tvShow/recentlyAdded'; |
||
32 | |||
33 | const DEFAULT_START_PAGE = self::START_PAGE_MOVIES_BROWSE; |
||
34 | |||
35 | /** |
||
36 | * The base-2 logarithm of the iteration count used for password stretching |
||
37 | */ |
||
38 | const PHPASS_ITERATIONS = 8; |
||
39 | |||
40 | /** |
||
41 | * @var boolean whether to hash the password before saving the model. |
||
42 | * Defaults to true. |
||
43 | */ |
||
44 | private $_hashPasswordBeforeSave = true; |
||
45 | |||
46 | /** |
||
47 | * Returns the static model of the specified AR class. |
||
48 | * @param string $className active record class name. |
||
49 | * @return User the static model class |
||
50 | */ |
||
51 | public static function model($className = __CLASS__) |
||
55 | |||
56 | /** |
||
57 | * @return string the associated database table name |
||
58 | */ |
||
59 | public function tableName() |
||
63 | |||
64 | /** |
||
65 | * @return array validation rules for model attributes. |
||
66 | */ |
||
67 | public function rules() |
||
82 | |||
83 | /** |
||
84 | * Checks that there is at least one administrator configured |
||
85 | * @param string $attribute |
||
86 | */ |
||
87 | public function validateRole($attribute) |
||
101 | |||
102 | /** |
||
103 | * @return array customized attribute labels (name=>label) |
||
104 | */ |
||
105 | public function attributeLabels() |
||
114 | |||
115 | /** |
||
116 | * Hashes the password before saving the model, unless hashing has been |
||
117 | * inhibited |
||
118 | */ |
||
119 | protected function beforeSave() |
||
126 | |||
127 | /** |
||
128 | * Inhibits the automatic hashing of the password on save |
||
129 | */ |
||
130 | public function inhibitPasswordHash() |
||
134 | |||
135 | /** |
||
136 | * @return User the model for the currently logged in user |
||
137 | */ |
||
138 | public function findCurrent() |
||
142 | |||
143 | /** |
||
144 | * Returns the possible roles |
||
145 | * @return array |
||
146 | */ |
||
147 | public function getRoles() |
||
155 | |||
156 | /** |
||
157 | * Returns the name of the user's role |
||
158 | * @return string |
||
159 | */ |
||
160 | public function getRoleName() |
||
166 | |||
167 | /** |
||
168 | * @return array the available start pages and their descriptions |
||
169 | */ |
||
170 | public function getStartPages() |
||
179 | |||
180 | /** |
||
181 | * @return array the route to the currently set start page, or the default one if |
||
182 | * none has been set |
||
183 | */ |
||
184 | public function getStartPage() |
||
191 | |||
192 | |||
193 | /** |
||
194 | * @return array the route to the start page |
||
195 | */ |
||
196 | public function getStartPageRoute() |
||
200 | |||
201 | |||
202 | /** |
||
203 | * Returns a data provider for this model |
||
204 | * @return \CActiveDataProvider |
||
205 | */ |
||
206 | public function getDataProvider() |
||
212 | |||
213 | /** |
||
214 | * Returns the hash for the specified password |
||
215 | * @param string $password |
||
216 | * @return string |
||
217 | */ |
||
218 | public static function hashPassword($password) |
||
222 | |||
223 | /** |
||
224 | * Checks whether the given password matches the given hash |
||
225 | * @param string $password |
||
226 | * @param string $hash |
||
227 | * @return boolean |
||
228 | */ |
||
229 | public static function checkPassword($password, $hash) |
||
233 | |||
234 | /** |
||
235 | * Returns the password hasher |
||
236 | * @return \Hautelook\Phpass\PasswordHash |
||
237 | */ |
||
238 | private static function getPasswordHasher() |
||
242 | |||
243 | } |
||
244 | |||
245 |