1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Users;
13
14 15 16 17 18 19 20
21 class UnlockLoginOperation extends \ICanBoogie\Operation
22 {
23 protected function lazy_get_record()
24 {
25 $username = $this->request['username'];
26
27 return $this->module->model->where('username = ? OR email = ?', $username, $username)->one;
28 }
29
30 protected function validate(\ICanboogie\Errors $errors)
31 {
32 global $core;
33
34 $token = $this->request['token'];
35
36 if (!$this->request['username'] || !$token)
37 {
38 return false;
39 }
40
41 $user = $this->record;
42
43 if (!$user)
44 {
45 throw new \Exception('Unknown user');
46 }
47
48 if ($user->metas['login_unlock_token'] != $token)
49 {
50 throw new \Exception('Invalid token.');
51 }
52
53 return true;
54 }
55
56 protected function process()
57 {
58 global $core;
59
60 $user = $this->record;
61
62 $user->metas['login_unlock_token'] = null;
63 $user->metas['login_unlock_time'] = null;
64 $user->metas['failed_login_count'] = 0;
65
66 $this->response->message = 'Login has been unlocked';
67 $this->response->location = isset($this->request['continue']) ? $this->request['continue'] : '/';
68
69 return true;
70 }
71 }