1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Auth; |
4
|
|
|
|
5
|
|
|
use App\User; |
6
|
|
|
use Validator; |
7
|
|
|
use App\Http\Controllers\Controller; |
8
|
|
|
use Illuminate\Foundation\Auth\ThrottlesLogins; |
9
|
|
|
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; |
10
|
|
|
use Bouncer; |
11
|
|
|
|
12
|
|
|
class AuthController extends Controller |
13
|
|
|
{ |
14
|
|
|
/* |
15
|
|
|
|-------------------------------------------------------------------------- |
16
|
|
|
| Registration & Login Controller |
17
|
|
|
|-------------------------------------------------------------------------- |
18
|
|
|
| |
19
|
|
|
| This controller handles the registration of new users, as well as the |
20
|
|
|
| authentication of existing users. By default, this controller uses |
21
|
|
|
| a simple trait to add these behaviors. Why don't you explore it? |
22
|
|
|
| |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
use AuthenticatesAndRegistersUsers, ThrottlesLogins; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Where to redirect users after login / registration. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $redirectTo = '/'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Create a new authentication controller instance. |
36
|
|
|
* |
37
|
|
|
* @return void |
|
|
|
|
38
|
|
|
*/ |
39
|
|
|
public function __construct() |
40
|
|
|
{ |
41
|
|
|
$this->middleware($this->guestMiddleware(), ['except' => 'logout']); |
42
|
|
|
$this->middleware('lang'); |
43
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
View Code Duplication |
protected function authenticated() |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$user = auth()->user(); |
|
|
|
|
50
|
|
|
|
51
|
|
|
if(Bouncer::is($user)->a('Administrator', 'Manager')) { |
52
|
|
|
return redirect()->route('dashboard.administration'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
elseif(Bouncer::is($user)->an('Agents')) { |
56
|
|
|
return redirect()->route('dashboard.agent'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
elseif(Bouncer::is($user)->an('Customer')) { |
60
|
|
|
return redirect('/'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return redirect('/'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get a validator for an incoming registration request. |
68
|
|
|
* |
69
|
|
|
* @param array $data |
70
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
71
|
|
|
*/ |
72
|
|
|
protected function validator(array $data) |
73
|
|
|
{ |
74
|
|
|
return Validator::make($data, [ |
75
|
|
|
'fname' => 'required|max:255', |
76
|
|
|
'name' => 'required|max:255', |
77
|
|
|
'email' => 'required|email|max:255|unique:users', |
78
|
|
|
'password' => 'required|min:6|confirmed', |
79
|
|
|
]); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Create a new user instance after a valid registration. |
84
|
|
|
* |
85
|
|
|
* @param array $data |
86
|
|
|
* @return User |
87
|
|
|
*/ |
88
|
|
|
protected function create(array $data) |
89
|
|
|
{ |
90
|
|
|
$newUser = User::create([ |
91
|
|
|
'fname' => $data['fname'], |
92
|
|
|
'name' => $data['name'], |
93
|
|
|
'email' => $data['email'], |
94
|
|
|
'password' => bcrypt($data['password']), |
95
|
|
|
]); |
96
|
|
|
|
97
|
|
|
Bouncer::assign('Guest')->to($newUser); |
98
|
|
|
|
99
|
|
|
return $newUser; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.