File tree Expand file tree Collapse file tree 2 files changed +36
-5
lines changed
app/Http/Controllers/Auth Expand file tree Collapse file tree 2 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 22
33namespace App \Http \Controllers \Auth ;
44
5+ use Illuminate \Http \Request ;
56use App \Http \Controllers \Controller ;
67use Illuminate \Foundation \Auth \AuthenticatesUsers ;
78
@@ -36,4 +37,34 @@ public function __construct()
3637 {
3738 $ this ->middleware ('guest ' , ['except ' => 'logout ' ]);
3839 }
40+
41+ /**
42+ * Get the login username to be used by the controller.
43+ * Overirden as you allow both username and email during login
44+ *
45+ * @return string
46+ */
47+ public function username ()
48+ {
49+ return 'login ' ;
50+ }
51+
52+ /**
53+ * Get the needed authorization credentials from the request.
54+ * Overirden as you allow both username and email during login
55+ *
56+ * @param \Illuminate\Http\Request $request
57+ * @return array
58+ */
59+ protected function credentials (Request $ request )
60+ {
61+ $ login = $ request ->get ('login ' );
62+ $ field = filter_var ($ login , FILTER_VALIDATE_EMAIL ) ? 'email ' : 'username ' ;
63+
64+ return [
65+ $ field => $ login ,
66+ 'password ' => $ request ->get ('password ' ),
67+ ];
68+ }
69+
3970}
Original file line number Diff line number Diff line change 44
55<h2 >Log In</h2 >
66
7- <p >Enter your email address and password to log in.</p >
7+ <p >Enter your email address or username and password to log in.</p >
88
99<form role =" form" method =" POST" action =" {{ url (' /login' ) } }" >
1010 {{ csrf_field () } }
1111
1212 <div class =" row" >
13- <label for =" email " class =" form-label" >E-Mail</label >
13+ <label for =" login " class =" form-label" >E-Mail or Username </label >
1414 <div class =" form-control" >
15- <input id =" email " type =" email " name =" email " value =" {{ old (' email ' ) } }" required autofocus >
15+ <input id =" login " type =" text " name =" login " value =" {{ old (' login ' ) } }" required autofocus >
1616
17- @if ($errors -> has (' email ' ) )
17+ @if ($errors -> has (' login ' ) )
1818 <p class =" help-text" >
19- <strong >{{ $errors -> first (' email ' ) } } </strong >
19+ <strong >{{ $errors -> first (' login ' ) } } </strong >
2020 </p >
2121 @endif
2222 </div >
You can’t perform that action at this time.
0 commit comments