Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

User login feedback for more info when login fails, to differentiate between non existing users and wrong password

givanz9948f6da8349
diff --git a/system/user/user.php b/system/user/user.php
index 48c84dc..f7d370d 100755
--- a/system/user/user.php
+++ b/system/user/user.php
@@ -22,6 +22,7 @@
namespace Vvveb\System\User;
+use function Vvveb\__;
use function Vvveb\session as sess;
use Vvveb\Sql\UserSQL;
use Vvveb\System\PageCache;
@@ -37,11 +38,13 @@ class User extends Auth {
return false;
}
+ self::sanitize($data);
+
//check if email or username is already registered
- $check = ['email'=> $data['email']];
+ $check = ['username'=> $data['username']];
- if (isset($data['username'])) {
- $check['username'] = $data['username'];
+ if (isset($data['email'])) {
+ $check['email'] = $data['email'];
}
if ($userInfo = $user->get($check)) {
@@ -69,6 +72,8 @@ class User extends Auth {
}
//$data['status'] = 0;
+ self::sanitize($data);
+
return $user->edit(array_merge([self :: $namespace => $data], $condition));
}
@@ -111,24 +116,36 @@ class User extends Auth {
return $userInfo;
}
- public static function login($data) {
- $data['status'] = 1;
- $userInfo = self::get($data);
+ public static function login($data, $additionalInfo = [], &$feedback = []) {
+ $data['status'] = 1;
+ $userInfo = self::get($data);
+ $passwordCorrect = false;
+ $userExists = ($userInfo && isset($userInfo['password']));
- if (! $userInfo) {
- return null;
+ if ($userExists) {
+ $passwordCorrect = self::checkPassword($data['password'], $userInfo['password']);
}
- if (! self::checkPassword($data['password'], $userInfo['password'])) {
+ if (! $userExists || ! $passwordCorrect) {
+ if ($userExists) {
+ $message = __('Password incorrect!');
+ $code = 0;
+ } else {
+ $message = __('User not found or has status inactive!');
+ $code = 1;
+ }
+
+ $feedback = ['message' => $message, 'code' => $code];
+
return false;
}
$session = Session :: getInstance();
$session->regenerateId(true);
unset($userInfo['password']);
- $session->set(self :: $namespace, $userInfo);
+ $session->set(self :: $namespace, $userInfo + $additionalInfo);
- PageCache::disable(self :: $namespace);
+ PageCache::disable('user');
return $userInfo;
}