Failed Conditions
Pull Request — master (#321)
by Anton
23:35 queued 08:33
created

modules/users/controllers/recovery-reset.php (4 issues)

Labels
Severity
1
<?php
2
/**
3
 * Reset password procedure
4
 *
5
 * @category Application
6
 *
7
 * @author   Anton Shevchuk
8
 * @created  11.12.12 15:25
9
 */
10
11
namespace Application;
12
13
use Application\Auth;
14
use Application\Users;
15
use Bluz\Controller\Controller;
0 ignored issues
show
The type Bluz\Controller\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Bluz\Proxy\Messages;
0 ignored issues
show
The type Bluz\Proxy\Messages was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Bluz\Proxy\Request;
0 ignored issues
show
The type Bluz\Proxy\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Bluz\Proxy\Response;
0 ignored issues
show
The type Bluz\Proxy\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
20
/**
21
 * @param int $id User UID
22
 * @param string $code
23
 * @param string $password
24
 * @param string $password2
25
 */
26
return function ($id, $code, $password = null, $password2 = null) {
27
    /**
28
     * @var Controller $this
29
     */
30
    // change layout
31
    $this->useLayout('small.phtml');
32
33
    $actionRow = UsersActions\Table::findRow(['userId' => $id, 'code' => $code]);
34
35
    $datetime1 = new \DateTime(); // now
36
    $datetime2 = new \DateTime($actionRow->expired);
37
    $interval = $datetime1->diff($datetime2);
38
39
    if (!$actionRow or $actionRow->action !== UsersActions\Table::ACTION_RECOVERY) {
40
        Messages::addError('Invalid code');
41
        Response::redirectTo('index', 'index');
42
    } elseif ($interval->invert) {
43
        Messages::addError('The activation code has expired');
44
        $actionRow->delete();
45
        Response::redirectTo('index', 'index');
46
    } else {
47
        $user = Users\Table::findRow($id);
48
49
        $this->assign('user', $user);
50
        $this->assign('code', $code);
51
52
        if (Request::isPost()) {
53
            try {
54
                if (empty($password) or empty($password2)) {
55
                    throw new Exception('Please enter your new password');
56
                }
57
58
                if ($password !== $password2) {
59
                    throw new Exception('Please repeat your new password');
60
                }
61
62
                // create new auth record
63
                Auth\Provider\Equals::create($user, $password);
64
65
                // show notification and redirect
66
                Messages::addSuccess(
67
                    'Your password has been updated'
68
                );
69
                Response::redirectTo('users', 'signin');
70
            } catch (Exception $e) {
71
                Messages::addError($e->getMessage());
72
            }
73
        }
74
    }
75
};
76