@@ -36,17 +36,27 @@ public function basicLogin($username, $password, $password_encode = "md5") {
3636 "username " => "validusername " ,
3737 "password " => "required "
3838 ]);
39+ if (!$ this ->select ("users " , "* " , "username = ? " , [$ username ])->fetchObj ()) {
40+ $ this ->form ->errorsArray ["username " ] = "Username doesn't exist " ;
41+ }
3942 if (!empty ($ this ->form ->errors ())) {
4043 $ this ->response ->respond ([
4144 "errors " => $ this ->form ->errors ()
42- ]);
45+ ]);
46+ exit ();
4347 } else {
4448 if ($ password_encode == "md5 " ) {
4549 $ password = md5 ($ password );
4650 } else {
4751 $ password = \base64_encode ($ password );
4852 }
4953 $ user = $ this ->select ("users " , "* " , "username = ? AND password = ? " , [$ username , $ password ])->fetchObj ();
54+ if (!$ user ) {
55+ $ this ->response ->respond ([
56+ "errors " => "Password is incorrect "
57+ ]);
58+ exit ();
59+ }
5060 $ token = $ this ->token ->generateSimpleToken ($ user ->id , "User secret key " );
5161 $ user ->token = $ token ;
5262 unset($ user ->password );
@@ -62,13 +72,20 @@ public function basicRegister($username, $email, $password, $confirm_password, $
6272 "password " => "required " ,
6373 "confirm_password " => "required "
6474 ]);
75+ if ($ this ->select ("users " , "* " , "username = ? " , [$ username ])->fetchObj ()) {
76+ $ this ->form ->errorsArray ["username " ] = "Username already exists " ;
77+ }
78+ if ($ this ->select ("users " , "* " , "email = ? " , [$ email ])->fetchObj ()) {
79+ $ this ->form ->errorsArray ["email " ] = "Email is already registered " ;
80+ }
6581 if ($ password != $ confirm_password ) {
66- $ this ->form ->errors ["password " ] = "Your passwords don't match " ;
82+ $ this ->form ->errorsArray ["password " ] = "Your passwords don't match " ;
6783 }
6884 if (!empty ($ this ->form ->errors ())) {
6985 $ this ->response ->respond ([
7086 "errors " => $ this ->form ->errors ()
71- ]);
87+ ]);
88+ exit ();
7289 } else {
7390 if ($ password_encode == "md5 " ) {
7491 $ password = md5 ($ password );
0 commit comments