1: <?php
2:
3: class UserResetPasswordRequest extends AppModel {
4:
5: // 48 horas = 48*60*60
6:
7: const LIFE_TIME_LIMIT = 172800;
8:
9: public $validate = array(
10: 'chave' => array(
11: 'rule' => array('isUnique'),
12: ),
13: );
14:
15: public function expired($instance) {
16: return ((mktime() - strtotime($instance[$this->alias]['created'])) > self::LIFE_TIME_LIMIT);
17: }
18:
19: public function createNewRequest($userId) {
20: return $this->save(array(
21: $this->alias => array(
22: 'user_id' => $userId,
23: 'chave' => $this->_generateNewChave(),
24: 'usado' => null,
25: )
26: ));
27: }
28:
29: private function _generateNewChave() {
30: do {
31: $chave = $this->_generateChave();
32: } while ($this->findByChave($chave));
33:
34: return $chave;
35: }
36:
37: private function _generateChave() {
38: return substr(
39: str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
40: , 0
41: , 32
42: );
43: }
44:
45: }
46:
47: ?>
48: