2
2
3
3
namespace BookStack \Http \Controllers \Auth ;
4
4
5
+ use Illuminate \Contracts \Auth \Authenticatable ;
5
6
use Illuminate \Http \Request ;
6
7
use BookStack \Exceptions \SocialSignInException ;
7
8
use BookStack \Exceptions \UserRegistrationException ;
@@ -29,9 +30,10 @@ class AuthController extends Controller
29
30
30
31
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
31
32
32
- protected $ loginPath = '/login ' ;
33
33
protected $ redirectPath = '/ ' ;
34
34
protected $ redirectAfterLogout = '/login ' ;
35
+ protected $ username = 'email ' ;
36
+
35
37
36
38
protected $ socialAuthService ;
37
39
protected $ emailConfirmationService ;
@@ -49,6 +51,7 @@ public function __construct(SocialAuthService $socialAuthService, EmailConfirmat
49
51
$ this ->socialAuthService = $ socialAuthService ;
50
52
$ this ->emailConfirmationService = $ emailConfirmationService ;
51
53
$ this ->userRepo = $ userRepo ;
54
+ $ this ->username = config ('auth.method ' ) === 'standard ' ? 'email ' : 'username ' ;
52
55
parent ::__construct ();
53
56
}
54
57
@@ -105,6 +108,38 @@ public function postRegister(Request $request)
105
108
return $ this ->registerUser ($ userData );
106
109
}
107
110
111
+
112
+ /**
113
+ * Overrides the action when a user is authenticated.
114
+ * If the user authenticated but does not exist in the user table we create them.
115
+ * @param Request $request
116
+ * @param Authenticatable $user
117
+ * @return \Illuminate\Http\RedirectResponse
118
+ */
119
+ protected function authenticated (Request $ request , Authenticatable $ user )
120
+ {
121
+ // Explicitly log them out for now if they do no exist.
122
+ if (!$ user ->exists ) auth ()->logout ($ user );
123
+
124
+ if (!$ user ->exists && $ user ->email === null && !$ request ->has ('email ' )) {
125
+ $ request ->flash ();
126
+ session ()->flash ('request-email ' , true );
127
+ return redirect ('/login ' );
128
+ }
129
+
130
+ if (!$ user ->exists && $ user ->email === null && $ request ->has ('email ' )) {
131
+ $ user ->email = $ request ->get ('email ' );
132
+ }
133
+
134
+ if (!$ user ->exists ) {
135
+ $ user ->save ();
136
+ $ this ->userRepo ->attachDefaultRole ($ user );
137
+ auth ()->login ($ user );
138
+ }
139
+
140
+ return redirect ()->intended ($ this ->redirectPath ());
141
+ }
142
+
108
143
/**
109
144
* Register a new user after a registration callback.
110
145
* @param $socialDriver
@@ -156,13 +191,14 @@ protected function registerUser(array $userData, $socialAccount = false)
156
191
}
157
192
158
193
$ newUser ->email_confirmed = true ;
194
+
159
195
auth ()->login ($ newUser );
160
196
session ()->flash ('success ' , 'Thanks for signing up! You are now registered and signed in. ' );
161
197
return redirect ($ this ->redirectPath ());
162
198
}
163
199
164
200
/**
165
- * Show the page to tell the user to check thier email
201
+ * Show the page to tell the user to check their email
166
202
* and confirm their address.
167
203
*/
168
204
public function getRegisterConfirmation ()
@@ -222,7 +258,7 @@ public function resendConfirmation(Request $request)
222
258
]);
223
259
$ user = $ this ->userRepo ->getByEmail ($ request ->get ('email ' ));
224
260
$ this ->emailConfirmationService ->sendConfirmation ($ user );
225
- \Session:: flash ('success ' , 'Confirmation email resent, Please check your inbox. ' );
261
+ session ()-> flash ('success ' , 'Confirmation email resent, Please check your inbox. ' );
226
262
return redirect ('/register/confirm ' );
227
263
}
228
264
@@ -232,13 +268,9 @@ public function resendConfirmation(Request $request)
232
268
*/
233
269
public function getLogin ()
234
270
{
235
-
236
- if (view ()->exists ('auth.authenticate ' )) {
237
- return view ('auth.authenticate ' );
238
- }
239
-
240
271
$ socialDrivers = $ this ->socialAuthService ->getActiveDrivers ();
241
- return view ('auth.login ' , ['socialDrivers ' => $ socialDrivers ]);
272
+ $ authMethod = config ('auth.method ' );
273
+ return view ('auth/login ' , ['socialDrivers ' => $ socialDrivers , 'authMethod ' => $ authMethod ]);
242
274
}
243
275
244
276
/**
@@ -253,7 +285,7 @@ public function getSocialLogin($socialDriver)
253
285
}
254
286
255
287
/**
256
- * Redirect to the social site for authentication initended to register.
288
+ * Redirect to the social site for authentication intended to register.
257
289
* @param $socialDriver
258
290
* @return mixed
259
291
*/
0 commit comments