Completed
Push — master ( a847a5...2d1915 )
by Nicolas
14:59
created

AuthController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
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
use Modules\User\Services\UserRegistration;
12
use Modules\User\Services\UserResetter;
13
14
class AuthController extends BasePublicController
15
{
16
    use DispatchesJobs;
17
18
    public function __construct()
19
    {
20
        parent::__construct();
21
22
    }
23
24
    public function getLogin()
25
    {
26
        return view('user::public.login');
27
    }
28
29
    public function postLogin(LoginRequest $request)
30
    {
31
        $credentials = [
32
            '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...
33
            '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...
34
        ];
35
        $remember = (bool) $request->get('remember_me', false);
36
37
        $error = $this->auth->login($credentials, $remember);
38
        if (!$error) {
39
            flash()->success(trans('user::messages.successfully logged in'));
40
41
            return redirect()->intended('/');
42
        }
43
44
        flash()->error($error);
45
46
        return redirect()->back()->withInput();
47
    }
48
49
    public function getRegister()
50
    {
51
        return view('user::public.register');
52
    }
53
54
    public function postRegister(RegisterRequest $request)
55
    {
56
        app(UserRegistration::class)->register($request->all());
57
58
        flash()->success(trans('user::messages.account created check email for activation'));
59
60
        return redirect()->route('register');
61
    }
62
63
    public function getLogout()
64
    {
65
        $this->auth->logout();
66
67
        return redirect()->route('login');
68
    }
69
70
    public function getActivate($userId, $code)
71
    {
72
        if ($this->auth->activate($userId, $code)) {
73
            flash()->success(trans('user::messages.account activated you can now login'));
74
75
            return redirect()->route('login');
76
        }
77
        flash()->error(trans('user::messages.there was an error with the activation'));
78
79
        return redirect()->route('register');
80
    }
81
82
    public function getReset()
83
    {
84
        return view('user::public.reset.begin');
85
    }
86
87
    public function postReset(ResetRequest $request)
88
    {
89
        try {
90
            app(UserResetter::class)->startReset($request->all());
91
        } catch (UserNotFoundException $e) {
92
            flash()->error(trans('user::messages.no user found'));
93
94
            return redirect()->back()->withInput();
95
        }
96
97
        flash()->success(trans('user::messages.check email to reset password'));
98
99
        return redirect()->route('reset');
100
    }
101
102
    public function getResetComplete()
103
    {
104
        return view('user::public.reset.complete');
105
    }
106
107
    public function postResetComplete($userId, $code, ResetCompleteRequest $request)
108
    {
109
        try {
110
            app(UserResetter::class)->finishReset(
111
                array_merge($request->all(), ['userId' => $userId, 'code' => $code])
112
            );
113
        } catch (UserNotFoundException $e) {
114
            flash()->error(trans('user::messages.user no longer exists'));
115
116
            return redirect()->back()->withInput();
117
        } catch (InvalidOrExpiredResetCode $e) {
118
            flash()->error(trans('user::messages.invalid reset code'));
119
120
            return redirect()->back()->withInput();
121
        }
122
123
        flash()->success(trans('user::messages.password reset'));
124
125
        return redirect()->route('login');
126
    }
127
}
128