Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Check if user or email already registered before adding a new user

givanzc44ecfa59c56
diff --git a/admin/controller/user/user.php b/admin/controller/user/user.php
index 5d8e5d1..4b57ef5 100755
--- a/admin/controller/user/user.php
+++ b/admin/controller/user/user.php
@@ -26,8 +26,10 @@ use function Vvveb\__;
use Vvveb\Controller\Base;
use Vvveb\System\Core\View;
use Vvveb\System\Images;
+use Vvveb\System\User\Admin;
use Vvveb\System\User\Auth;
use Vvveb\System\User\User as UserLogin;
+use Vvveb\System\User\User as UserSystem;
use Vvveb\System\Validator;
class User extends Base {
@@ -46,7 +48,7 @@ class User extends Base {
$user = $users->get($options);
if (! $user) {
- return $this->notFound(true, __('Page not found!'));
+ return $this->notFound(true, __('User not found!'));
}
if (isset($user['password'])) {
@@ -131,14 +133,35 @@ class User extends Base {
$this->view->errors[] = $users->error;
}
} else {
- $return = $users->add([$this->type => $user]);
- $id = $return[$this->type];
+ if ($this->type == 'admin') {
+ $result = Admin::add($user);
+ } else {
+ $result = UserSystem::add($user);
+ }
- if (! $id) {
- $view->errors = [$users->error];
+ //$result = $users->add([$this->type => $user]);
+
+ if ($result) {
+ if (isset($result[$this->type])) {
+ $id = $result[$this->type];
+
+ if (! $id) {
+ $view->errors[] = $users->error;
+ } else {
+ $view->success['get'] = ucfirst($this->type) . __(' added!');
+ $this->redirect(['module'=> $this->type . '/user', $this->type . '_id' => $id, 'success' => ucfirst(__($this->type)) . __(' added!')]);
+ }
+ } else {
+ if ($result['email'] == $user['email']) {
+ $view->errors[] = __('This email is already in use. Please use another one.');
+ }
+
+ if ($result['username'] == $user['username']) {
+ $view->errors[] = __('This username is already in use. Please use another one.');
+ }
+ }
} else {
- $view->success['get'] = ucfirst($this->type) . __(' added!');
- $this->redirect(['module'=> $this->type . '/user', $this->type . '_id' => $id, 'success' => $this->type . __(' added!')]);
+ $view->errors[] = __('Error creating account!');
}
}
} else {
diff --git a/app/controller/user/signup.php b/app/controller/user/signup.php
index 8edd05c..b754839 100755
--- a/app/controller/user/signup.php
+++ b/app/controller/user/signup.php
@@ -45,8 +45,11 @@ class Signup extends \Vvveb\Controller\Base {
//allow only fields that are in the validator list and remove the rest
$userInfo = $validator->filter($this->request->post);
- $userInfo['display_name'] = $userInfo['first_name'] . ' ' . $userInfo['last_name'];
- $userInfo['username'] = $userInfo['first_name'] . $userInfo['last_name'];
+ $userInfo['display_name'] = $userInfo['username'] ?? '';
+
+ if (! isset($userInfo['username']) && isset($userInfo['first_name'])) {
+ $userInfo['username'] = $userInfo['first_name'] . $userInfo['last_name'];
+ }
$userInfo['spam'] = $isSpam;
list($userInfo) = Event :: trigger(__CLASS__, __FUNCTION__ , $userInfo);
@@ -59,7 +62,7 @@ class Signup extends \Vvveb\Controller\Base {
}
if ($userInfo) {
- $result = User::add($userInfo);
+ $result = User::add($userInfo);
$this->view->errors['login'] = [];
@@ -94,9 +97,17 @@ class Signup extends \Vvveb\Controller\Base {
$this->view->errors['login'] = $error;
}
- return $this->redirect('user/index');
+ return $this->redirect('user/login/index');
} else {
- $this->view->errors['login'] = __('This email is already in use. Please use another one.');
+ $this->view->errors['login'] = '';
+
+ if ($result['email'] == $userInfo['email']) {
+ $this->view->errors['login'] = __('This email is already in use. Please use another one.');
+ }
+
+ if ($result['username'] == $userInfo['username']) {
+ $this->view->errors['login'] .= __('This username is already in use. Please use another one.');
+ }
}
} else {
$this->view->errors['login'] = __('Error creating account!');
diff --git a/app/validate/signup.php b/app/validate/signup.php
index 50ea5c4..dbaca16 100755
--- a/app/validate/signup.php
+++ b/app/validate/signup.php
@@ -21,6 +21,7 @@
*/
return [
+ /*
'first_name' => [
'notEmpty' => '',
'maxLength' => 100,
@@ -29,6 +30,11 @@ return [
'notEmpty' => '',
'maxLength' => 100,
],
+*/
+ 'username' => [
+ 'notEmpty' => '',
+ 'maxLength' => 100,
+ ],
'email' => [
'notEmpty' => '',
'maxLength' => 100,