33
44use Bubu \Database \Database ;
55use Bubu \Http \Session \Session ;
6- use Bubu \Lang \Lang ;
76use Bubu \Mail \MailTemplate ;
87
98class Account
@@ -12,38 +11,33 @@ class Account
1211
1312 /**
1413 * login
15- * @param string $username
14+ * @param string $email
1615 * @param string $password
1716 * @param bool $keepSession
1817 *
1918 * @return bool|string
2019 */
21- public static function login (string $ username , string $ password , bool $ keepSession = false )
20+ public static function login (string $ email , string $ password , bool $ keepSession = false )
2221 {
2322 $ dbData = Database::queryBuilder ('Users ' )
2423 ->select ('id ' , 'password ' , 'email_verified_at ' , 'token ' )
25- ->where (Database::expr ()::eq ('username ' , $ username ))
24+ ->where (Database::expr ()::eq ('email ' , $ email ))
2625 ->fetch ();
2726
28- if ($ dbData === false || count ($ dbData ) === 0 ) {
29- return Lang::get ('account-not-found ' );
30- } elseif (!password_verify ($ password , $ dbData ['password ' ])) {
31- return Lang::get ('incorrect-password ' );
32- } elseif (is_null ($ dbData ['email_verified_at ' ])) {
33- return Lang::get ('email-not-verified ' );
34- } else {
27+ if ($ dbData === false || count ($ dbData ) === 0 ) return 'account_not_found ' ;
28+ elseif (!password_verify ($ password , $ dbData ['password ' ])) return 'wrong_password ' ;
29+ elseif (is_null ($ dbData ['email_verified_at ' ])) return 'email_not_verified ' ;
30+ else {
3531 Session::set ('token ' , $ dbData ['token ' ]);
36- if ($ keepSession ) {
37- Session::changeSessionLifetime ($ _ENV ['SESSION_KEEP_CONNECT ' ]);
38- }
32+ if ($ keepSession ) Session::changeSessionLifetime ($ _ENV ['SESSION_KEEP_CONNECT ' ]);
3933 return true ;
4034 }
4135 }
4236
4337 public static function regexPassword (string $ password , string $ confim )
4438 {
45- if (strlen ($ password ) < 10 ) return Lang:: get ( ' password-length ' ) ;
46- elseif ($ password !== $ confim ) return Lang:: get ( ' not-same-password ' ) ;
39+ if (strlen ($ password ) < 10 ) return ' password_too_short ' ;
40+ elseif ($ password !== $ confim ) return ' password_not_match ' ;
4741 else return true ;
4842 }
4943
@@ -72,11 +66,8 @@ public static function signup(
7266 ->where (Database::expr ()::eq ('email ' , $ email ))
7367 ->fetch ();
7468
75- if ($ usernameFetch !== false && count ($ usernameFetch ) !== 0 ) {
76- return Lang::get ('existing-username ' );
77- } elseif ($ emailFetch !== false && count ($ emailFetch ) !== 0 ) {
78- return Lang::get ('existing-email ' );
79- }
69+ if ($ usernameFetch !== false && count ($ usernameFetch ) !== 0 ) return 'username_already_used ' ;
70+ elseif ($ emailFetch !== false && count ($ emailFetch ) !== 0 ) return 'email_already_used ' ;
8071
8172 $ passCheck = self ::regexPassword ($ password , $ passwordConfirm );
8273 if ($ passCheck !== true ) return $ passCheck ;
@@ -111,7 +102,7 @@ public static function checkPassword(string $password, ?string $tokenPassed): bo
111102
112103 public static function updateToken (string $ password , ?string $ token ): string
113104 {
114- if (!self ::checkPassword ($ password , $ token )) return Lang:: get ( ' incorrect-password ' ) ;
105+ if (!self ::checkPassword ($ password , $ token )) return ' wrong_password ' ;
115106
116107 $ newToken = bin2hex (random_bytes (30 ));
117108
@@ -129,7 +120,7 @@ public static function updateToken(string $password, ?string $token): string
129120
130121 public static function updateEmail (string $ newMail , string $ password , ?string $ token )
131122 {
132- if (!self ::checkPassword ($ password , $ token )) return Lang:: get ( ' incorrect-password ' ) ;
123+ if (!self ::checkPassword ($ password , $ token )) return ' wrong_password ' ;
133124
134125 $ emailCode = bin2hex (random_bytes (10 ));
135126
@@ -163,7 +154,7 @@ public static function updatePassword(
163154 string $ confirm ,
164155 ?string $ token
165156 ) {
166- if (!self ::checkPassword ($ currentPassword , $ token )) return Lang:: get ( ' incorrect-password ' ) ;
157+ if (!self ::checkPassword ($ currentPassword , $ token )) return ' wrong_password ' ;
167158
168159 $ passCheck = self ::regexPassword ($ newPassword , $ confirm );
169160 if ($ passCheck !== true ) return $ passCheck ;
0 commit comments