|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* UsersController Class |
|
7
|
|
|
* |
|
8
|
|
|
* Implements actions regarding user management |
|
9
|
|
|
*/ |
|
10
|
|
|
class UsersController extends Controller |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Displays the form for account creation |
|
15
|
|
|
* |
|
16
|
|
|
* @return Illuminate\Http\Response |
|
17
|
|
|
*/ |
|
18
|
|
|
public function create() |
|
19
|
|
|
{ |
|
20
|
|
|
return View::make(Config::get('confide::signup_form')); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Stores new account |
|
25
|
|
|
* |
|
26
|
|
|
* @return Illuminate\Http\Response |
|
27
|
|
|
*/ |
|
28
|
|
|
public function store() |
|
29
|
|
|
{ |
|
30
|
|
|
$repo = App::make('UserRepository'); |
|
31
|
|
|
$user = $repo->signup(Input::all()); |
|
32
|
|
|
|
|
33
|
|
|
if ($user->id) { |
|
34
|
|
|
if (Config::get('confide::signup_email')) { |
|
35
|
|
|
Mail::queueOn( |
|
36
|
|
|
Config::get('confide::email_queue'), |
|
37
|
|
|
Config::get('confide::email_account_confirmation'), |
|
38
|
|
|
compact('user'), |
|
39
|
|
|
function ($message) use ($user) { |
|
40
|
|
|
$message |
|
41
|
|
|
->to($user->email, $user->username) |
|
42
|
|
|
->subject(Lang::get('confide::confide.email.account_confirmation.subject')); |
|
43
|
|
|
} |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return Redirect::action('UsersController@login') |
|
48
|
|
|
->with('notice', Lang::get('confide::confide.alerts.account_created')); |
|
49
|
|
|
} else { |
|
50
|
|
|
$error = $user->errors()->all(':message'); |
|
51
|
|
|
|
|
52
|
|
|
return Redirect::action('UsersController@create') |
|
53
|
|
|
->withInput(Input::except('password')) |
|
54
|
|
|
->with('error', $error); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Displays the login form |
|
60
|
|
|
* |
|
61
|
|
|
* @return Illuminate\Http\Response |
|
62
|
|
|
*/ |
|
63
|
|
|
public function login() |
|
64
|
|
|
{ |
|
65
|
|
|
if (Confide::user()) { |
|
66
|
|
|
return Redirect::to('/'); |
|
|
|
|
|
|
67
|
|
|
} else { |
|
68
|
|
|
return View::make(Config::get('confide::login_form')); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Attempt to do login |
|
74
|
|
|
* |
|
75
|
|
|
* @return Illuminate\Http\Response |
|
76
|
|
|
*/ |
|
77
|
|
|
public function doLogin() |
|
78
|
|
|
{ |
|
79
|
|
|
$repo = App::make('UserRepository'); |
|
80
|
|
|
$input = Input::all(); |
|
81
|
|
|
|
|
82
|
|
|
if ($repo->login($input)) { |
|
83
|
|
|
return Redirect::intended('/'); |
|
|
|
|
|
|
84
|
|
|
} else { |
|
85
|
|
|
if ($repo->isThrottled($input)) { |
|
86
|
|
|
$err_msg = Lang::get('confide::confide.alerts.too_many_attempts'); |
|
87
|
|
|
} elseif ($repo->existsButNotConfirmed($input)) { |
|
88
|
|
|
$err_msg = Lang::get('confide::confide.alerts.not_confirmed'); |
|
89
|
|
|
} else { |
|
90
|
|
|
$err_msg = Lang::get('confide::confide.alerts.wrong_credentials'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return Redirect::action('UsersController@login') |
|
94
|
|
|
->withInput(Input::except('password')) |
|
95
|
|
|
->with('error', $err_msg); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Attempt to confirm account with code |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $code |
|
103
|
|
|
* |
|
104
|
|
|
* @return Illuminate\Http\Response |
|
105
|
|
|
*/ |
|
106
|
|
|
public function confirm($code) |
|
107
|
|
|
{ |
|
108
|
|
|
if (Confide::confirm($code)) { |
|
109
|
|
|
$notice_msg = Lang::get('confide::confide.alerts.confirmation'); |
|
110
|
|
|
return Redirect::action('UsersController@login') |
|
111
|
|
|
->with('notice', $notice_msg); |
|
112
|
|
|
} else { |
|
113
|
|
|
$error_msg = Lang::get('confide::confide.alerts.wrong_confirmation'); |
|
114
|
|
|
return Redirect::action('UsersController@login') |
|
115
|
|
|
->with('error', $error_msg); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Displays the forgot password form |
|
121
|
|
|
* |
|
122
|
|
|
* @return Illuminate\Http\Response |
|
123
|
|
|
*/ |
|
124
|
|
|
public function forgotPassword() |
|
125
|
|
|
{ |
|
126
|
|
|
return View::make(Config::get('confide::forgot_password_form')); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Attempt to send change password link to the given email |
|
131
|
|
|
* |
|
132
|
|
|
* @return Illuminate\Http\Response |
|
133
|
|
|
*/ |
|
134
|
|
|
public function doForgotPassword() |
|
135
|
|
|
{ |
|
136
|
|
|
if (Confide::forgotPassword(Input::get('email'))) { |
|
137
|
|
|
$notice_msg = Lang::get('confide::confide.alerts.password_forgot'); |
|
138
|
|
|
return Redirect::action('UsersController@login') |
|
139
|
|
|
->with('notice', $notice_msg); |
|
140
|
|
|
} else { |
|
141
|
|
|
$error_msg = Lang::get('confide::confide.alerts.wrong_password_forgot'); |
|
142
|
|
|
return Redirect::action('UsersController@doForgotPassword') |
|
143
|
|
|
->withInput() |
|
144
|
|
|
->with('error', $error_msg); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Shows the change password form with the given token |
|
150
|
|
|
* |
|
151
|
|
|
* @param string $token |
|
152
|
|
|
* |
|
153
|
|
|
* @return Illuminate\Http\Response |
|
154
|
|
|
*/ |
|
155
|
|
|
public function resetPassword($token) |
|
156
|
|
|
{ |
|
157
|
|
|
return View::make(Config::get('confide::reset_password_form')) |
|
158
|
|
|
->with('token', $token); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Attempt change password of the user |
|
163
|
|
|
* |
|
164
|
|
|
* @return Illuminate\Http\Response |
|
165
|
|
|
*/ |
|
166
|
|
|
public function doResetPassword() |
|
167
|
|
|
{ |
|
168
|
|
|
$repo = App::make('UserRepository'); |
|
169
|
|
|
$input = array( |
|
170
|
|
|
'token' =>Input::get('token'), |
|
171
|
|
|
'password' =>Input::get('password'), |
|
172
|
|
|
'password_confirmation' =>Input::get('password_confirmation'), |
|
173
|
|
|
); |
|
174
|
|
|
|
|
175
|
|
|
// By passing an array with the token, password and confirmation |
|
176
|
|
|
if ($repo->resetPassword($input)) { |
|
177
|
|
|
$notice_msg = Lang::get('confide::confide.alerts.password_reset'); |
|
178
|
|
|
return Redirect::action('UsersController@login') |
|
179
|
|
|
->with('notice', $notice_msg); |
|
180
|
|
|
} else { |
|
181
|
|
|
$error_msg = Lang::get('confide::confide.alerts.wrong_password_reset'); |
|
182
|
|
|
return Redirect::action('UsersController@resetPassword', array('token'=>$input['token'])) |
|
183
|
|
|
->withInput() |
|
184
|
|
|
->with('error', $error_msg); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Log the user out of the application. |
|
190
|
|
|
* |
|
191
|
|
|
* @return Illuminate\Http\Response |
|
192
|
|
|
*/ |
|
193
|
|
|
public function logout() |
|
194
|
|
|
{ |
|
195
|
|
|
Confide::logout(); |
|
196
|
|
|
|
|
197
|
|
|
return Redirect::to('/'); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.