Passed
Push — master ( b534e3...17b30a )
by Mihail
19:51
created

ActionPassword::password()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 26
Code Lines 12

Duplication

Lines 8
Ratio 30.77 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 4
eloc 12
c 1
b 1
f 0
nc 3
nop 0
dl 8
loc 26
rs 8.5806
1
<?php
2
3
4
namespace Apps\Controller\Front\Profile;
5
6
use Apps\Model\Front\Profile\FormPasswordChange;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Exception\ForbiddenException;
10
use Ffcms\Core\Network\Response;
11
use Symfony\Component\HttpFoundation\Request;
12
13
/**
14
 * Trait ActionPassword
15
 * @package Apps\Controller\Front\Profile
16
 * @property View $view
17
 * @property Request $request
18
 * @property Response $response
19
 * @method array getConfigs
20
 */
21
trait ActionPassword
22
{
23
24
    /**
25
     * Action change user password
26
     * @return string
27
     * @throws \Ffcms\Core\Exception\SyntaxException
28
     * @throws ForbiddenException
29
     */
30
    public function password()
31
    {
32
        // check if user is authed
33
        if (!App::$User->isAuth()) {
34
            throw new ForbiddenException();
35
        }
36
37
        // get user object and create model with user object
38
        $user = App::$User->identity();
39
        $model = new FormPasswordChange($user);
40
41
        // check if form is submited and validation is passed
42 View Code Duplication
        if ($model->send() && $model->validate()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
            $model->make();
44
            App::$Event->run(static::EVENT_CHANGE_PASSWORD, [
45
                'model' => $model
46
            ]);
47
48
            App::$Session->getFlashBag()->add('success', __('Password is successful changed'));
49
        }
50
51
        // set response output
52
        return $this->view->render('password', [
53
            'model' => $model
54
        ]);
55
    }
56
}
57