AuthController::postResetComplete()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 21
rs 9.3143
c 2
b 0
f 0
cc 3
eloc 13
nc 3
nop 3
1
<?php namespace Modules\User\Http\Controllers;
2
3
use Illuminate\Foundation\Bus\DispatchesJobs;
4
use Modules\Core\Http\Controllers\BasePublicController;
5
use Modules\User\Exceptions\InvalidOrExpiredResetCode;
6
use Modules\User\Exceptions\UserNotFoundException;
7
use Modules\User\Http\Requests\LoginRequest;
8
use Modules\User\Http\Requests\RegisterRequest;
9
use Modules\User\Http\Requests\ResetCompleteRequest;
10
use Modules\User\Http\Requests\ResetRequest;
11
12
class AuthController extends BasePublicController
13
{
14
    use DispatchesJobs;
15
16
    public function getLogin()
17
    {
18
        return view('user::public.login');
19
    }
20
21
    public function postLogin(LoginRequest $request)
22
    {
23
        $credentials = [
24
            'email' => $request->email,
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<Modules\User\Http\Requests\LoginRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
25
            'password' => $request->password,
0 ignored issues
show
Documentation introduced by
The property password does not exist on object<Modules\User\Http\Requests\LoginRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
26
        ];
27
        $remember = (bool) $request->get('remember_me', false);
28
29
        $error = $this->auth->login($credentials, $remember);
30
        if (!$error) {
31
            flash()->success(trans('user::messages.successfully logged in'));
32
33
            return redirect()->intended('/');
34
        }
35
36
        flash()->error($error);
37
38
        return redirect()->back()->withInput();
39
    }
40
41
    public function getRegister()
42
    {
43
        return view('user::public.register');
44
    }
45
46
    public function postRegister(RegisterRequest $request)
47
    {
48
        app('Modules\User\Services\UserRegistration')->register($request->all());
49
50
        flash()->success(trans('user::messages.account created check email for activation'));
51
52
        return redirect()->route('register');
53
    }
54
55
    public function getLogout()
56
    {
57
        $this->auth->logout();
58
59
        return redirect()->route('login');
60
    }
61
62
    public function getActivate($userId, $code)
63
    {
64
        if ($this->auth->activate($userId, $code)) {
65
            flash()->success(trans('user::messages.account activated you can now login'));
66
67
            return redirect()->route('login');
68
        }
69
        flash()->error(trans('user::messages.there was an error with the activation'));
70
71
        return redirect()->route('register');
72
    }
73
74
    public function getReset()
75
    {
76
        return view('user::public.reset.begin');
77
    }
78
79
    public function postReset(ResetRequest $request)
80
    {
81
        try {
82
            $this->dispatchFrom('Modules\User\Commands\BeginResetProcessCommand', $request);
83
        } catch (UserNotFoundException $e) {
84
            flash()->error(trans('user::messages.no user found'));
85
86
            return redirect()->back()->withInput();
87
        }
88
89
        flash()->success(trans('user::messages.check email to reset password'));
90
91
        return redirect()->route('reset');
92
    }
93
94
    public function getResetComplete()
95
    {
96
        return view('user::public.reset.complete');
97
    }
98
99
    public function postResetComplete($userId, $code, ResetCompleteRequest $request)
100
    {
101
        try {
102
            $this->dispatchFromArray(
103
                'Modules\User\Commands\CompleteResetProcessCommand',
104
                array_merge($request->all(), ['userId' => $userId, 'code' => $code])
105
            );
106
        } catch (UserNotFoundException $e) {
107
            flash()->error(trans('user::messages.user no longer exists'));
108
109
            return redirect()->back()->withInput();
110
        } catch (InvalidOrExpiredResetCode $e) {
111
            flash()->error(trans('user::messages.invalid reset code'));
112
113
            return redirect()->back()->withInput();
114
        }
115
116
        flash()->success(trans('user::messages.password reset'));
117
118
        return redirect()->route('login');
119
    }
120
}
121