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

modules/users/controllers/activation.php (3 issues)

Labels
Severity
1
<?php
2
/**
3
 * User Activation
4
 *
5
 * @category Application
6
 *
7
 * @author   Anton Shevchuk
8
 * @created  05.12.12 15:17
9
 */
10
11
namespace Application;
12
13
use Application\Roles;
14
use Application\Roles\Table;
15
use Application\Users;
16
use Application\UsersActions;
17
use Application\UsersRoles;
18
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...
19
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...
20
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...
21
22
/**
23
 * @param int $id User UID
24
 * @param string $code
25
 *
26
 * @return bool
27
 */
28
return function ($id, $code) {
29
    /**
30
     * @var Controller $this
31
     */
32
    $actionRow = UsersActions\Table::findRow(['userId' => $id, 'code' => $code]);
33
34
    if (!$actionRow) {
35
        Messages::addError('Invalid activation code');
36
        Response::redirectTo('index', 'index');
37
        return false;
38
    }
39
40
    $datetime1 = new \DateTime(); // now
41
    $datetime2 = new \DateTime($actionRow->expired);
42
    $interval = $datetime1->diff($datetime2);
43
44
    if ($actionRow->action !== UsersActions\Table::ACTION_ACTIVATION) {
45
        Messages::addError('Invalid activation code');
46
    } elseif ($interval->invert) {
47
        Messages::addError('The activation code has expired');
48
        $actionRow->delete();
49
    } else {
50
        // change user status
51
        $userRow = Users\Table::findRow($id);
52
        $userRow->status = Users\Table::STATUS_ACTIVE;
53
        $userRow->save();
54
55
        // create user role
56
        // get member role
57
        $roleRow = Roles\Table::findRowWhere(['name' => Table::BASIC_MEMBER]);
58
        // create relation user to role
59
        $usersRoleRow = new UsersRoles\Row();
60
        $usersRoleRow->roleId = $roleRow->id;
61
        $usersRoleRow->userId = $userRow->id;
62
        $usersRoleRow->save();
63
64
        // remove old code
65
        $actionRow->delete();
66
67
        Messages::addSuccess(
68
            'Your Account has been successfully activated. <br/>' .
69
            'You can now log in using the username and password you chose during the registration.'
70
        );
71
        Response::redirectTo('users', 'signin');
72
    }
73
    Response::redirectTo('index', 'index');
74
};
75