Exemple #1
0
 public function _register()
 {
     if (!$_POST || !isset($_POST['login'], $_POST['email'], $_POST['password']) || trim($_POST['login']) == '') {
         sleep(5);
         go('/');
     }
     // Check user exists
     $user_collection = new AdminUserRepository();
     $user_collection->setWhereLogin($_POST['login']);
     if ($user_collection->hasAnyObjectInCollection()) {
         error('User with this login already exists');
     }
     // Create new user
     $default_group_id = 1;
     $group_collection = new AdminUserGroupRepository();
     $group_collection->setWhereDefault(true);
     /** @var AdminUser $user */
     $group = $group_collection->getFirstObjectFromCollection();
     if ($group) {
         $default_group_id = $group->getId();
     }
     $user = new AdminUser();
     $user->loadDataFromArray($_POST);
     if ($user->getEmail() && !Verify::email($user->getEmail())) {
         error('Wrong email');
     }
     $user->setGroupId($default_group_id);
     $user->setPassword($_POST['password']);
     $user->save();
     // TODO send email to new user with confirmation link
     // TODO make "restore password"
     go(SELF, ['registered' => 1]);
 }