Ejemplo n.º 1
0
 /**
  * POST: /account/register
  */
 public function registerPost()
 {
     $model = new AccountRegisterModel(Language::$REGISTER[Config::$LANGUAGE], true);
     if ($model->validation) {
         $userDAO = new UserDAO();
         $hasUser = $userDAO->hasUser($model->email);
         if (!$hasUser) {
             $uniqueId = $userDAO->createUser($model->email, $model->password);
             $userEntity = $userDAO->getUserWithRolesByUniqueId($uniqueId);
             $roleDAO = new RoleDAO();
             if ($userDAO->countUsers() == 0) {
                 $roleDAO->addedRoleToUser('admin', $userEntity->id);
             }
             $roleDAO->addedRoleToUser('user', $userEntity->id);
             (new BrowsingDAO())->addedBrowsingToUser($userEntity->id, Browsing::getBrowsingId());
             if (Config::$SMTP) {
                 //Send email for confirm email address
                 (new Email())->send($model->email, Language::$CONFIRM_EMAIL[Config::$LANGUAGE], Language::$CONFIRM_EMAIL[Config::$LANGUAGE] . ' http://' . $_SERVER['SERVER_NAME'] . '/account/confirm-email/' . $uniqueId);
             }
             Authentication::signIn($uniqueId);
             parent::redirectToUrlFromArray(explode('/', $model->url));
         }
         $model->emailValidation = Language::$DUPLICATE_EMAIL[Config::$LANGUAGE];
         $model->validation = false;
     }
     parent::view(new Register(), $model);
 }