| <?php |
|
|
| namespace Kanboard\Model; |
|
|
| use Kanboard\Core\Base; |
|
|
| |
| |
| |
| |
| |
| |
| class PasswordResetModel extends Base |
| { |
| |
| |
| |
| |
| |
| const TABLE = 'password_reset'; |
|
|
| |
| |
| |
| |
| |
| const DURATION = 1800; |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getAll($user_id) |
| { |
| return $this->db->table(self::TABLE)->eq('user_id', $user_id)->desc('date_creation')->limit(100)->findAll(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public function create($username, $expiration = 0) |
| { |
| $user_id = $this->db->table(UserModel::TABLE)->eq('username', $username)->neq('email', '')->notNull('email')->findOneColumn('id'); |
|
|
| if (! $user_id) { |
| return false; |
| } |
|
|
| $token = $this->token->getToken(); |
|
|
| $result = $this->db->table(self::TABLE)->insert(array( |
| 'token' => $token, |
| 'user_id' => $user_id, |
| 'date_expiration' => $expiration ?: time() + self::DURATION, |
| 'date_creation' => time(), |
| 'ip' => $this->request->getIpAddress(), |
| 'user_agent' => $this->request->getUserAgent(), |
| 'is_active' => 1, |
| )); |
|
|
| return $result ? $token : false; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getUserIdByToken($token) |
| { |
| return $this->db->table(self::TABLE)->eq('token', $token)->eq('is_active', 1)->gte('date_expiration', time())->findOneColumn('user_id'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function disable($user_id) |
| { |
| return $this->db->table(self::TABLE)->eq('user_id', $user_id)->update(array('is_active' => 0)); |
| } |
| } |
|
|