File tree 2 files changed +21
-6
lines changed
angular/app/components/login-form
app/Http/Controllers/Auth 2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change 1
1
class LoginFormController {
2
- constructor ( $auth ) {
2
+ constructor ( $auth , ToastService ) {
3
3
'ngInject' ;
4
4
5
5
this . $auth = $auth ;
6
+ this . ToastService = ToastService ;
6
7
7
8
this . email = '' ;
8
9
this . password = '' ;
@@ -16,11 +17,20 @@ class LoginFormController {
16
17
17
18
this . $auth . login ( user )
18
19
. then ( ( response ) => {
19
- //save token in localStorage
20
20
this . $auth . setToken ( response . data ) ;
21
21
22
22
//
23
- } ) ;
23
+ } )
24
+ . catch ( this . failedLogin . bind ( this ) ) ;
25
+ }
26
+
27
+ failedLogin ( response ) {
28
+ if ( response . status === 422 ) {
29
+ for ( var error in response . data . errors ) {
30
+ return this . ToastService . error ( response . data . errors [ error ] [ 0 ] ) ;
31
+ }
32
+ }
33
+ this . ToastService . error ( response . statusText ) ;
24
34
}
25
35
}
26
36
Original file line number Diff line number Diff line change @@ -12,6 +12,11 @@ class AuthController extends Controller
12
12
{
13
13
public function postLogin (Request $ request )
14
14
{
15
+ $ this ->validate ($ request , [
16
+ 'email ' => 'required|email ' ,
17
+ 'password ' => 'required|min:8 ' ,
18
+ ]);
19
+
15
20
$ credentials = $ request ->only ('email ' , 'password ' );
16
21
17
22
try {
@@ -36,9 +41,9 @@ public function postRegister()
36
41
'password ' => 'required|min:8 ' ,
37
42
]);
38
43
39
- $ user = new User ;
40
- $ user ->name = trim ($ request ->name );
41
- $ user ->email = trim (strtolower ($ request ->email ));
44
+ $ user = new User ;
45
+ $ user ->name = trim ($ request ->name );
46
+ $ user ->email = trim (strtolower ($ request ->email ));
42
47
$ user ->password = bcrypt ($ request ->password );
43
48
$ user ->save ();
44
49
You can’t perform that action at this time.
0 commit comments