示例#1
0
 /**
  * Upgrades users by assigning them roles at the base of their type field's value
  */
 public function postUpgradeRoles()
 {
     $users = Database::getInstance()->selectAll(array('from' => 'user', 'join' => array(array('LEFT JOIN', 'user_role', 'ON user_role.user_id = user.user_id'))), array(), array('user.user_id', 'user.type', 'user_role.role_id'));
     // because of we add new role, roles numbers are differ from user.types
     // so we use this array to make their conformity
     $typesToRoles = array('3' => 2, '4' => 3, '5' => 1);
     // assigning roles
     $i = 0;
     foreach ($users as $user) {
         // if role not set yet
         if (empty($user['role_id'])) {
             // insert
             if (array_key_exists($user['type'], $typesToRoles)) {
                 if (empty($user['role_id']) or $user['role_id'] == NULL) {
                     $values = array('role_id' => $typesToRoles[$user['type']], 'user_id' => $user['user_id']);
                     Database::getInstance()->insert('user_role', $values);
                     $i++;
                 }
             }
         }
     }
     Messenger::message(" {$i} users was upgraded!");
     return $this->get();
 }
示例#2
0
 protected function requestSuccess()
 {
     if (is_array($this->results)) {
         // HEADERS
         $this->outputCookies();
         $this->redirect();
         // STANDARD OUTPUT
         if (isset($this->results['errors']) && is_array($this->results['errors'])) {
             foreach ($this->results['errors'] as $error) {
                 Messenger::error($error);
             }
         }
         if (isset($this->results['messages']) && is_array($this->results['messages'])) {
             foreach ($this->results['messages'] as $message) {
                 Messenger::message($message);
             }
         }
         return $this->hasErrors() ? false : true;
     } else {
         if ($this->verbose) {
             Output::error("Error reading from application!\n{$this->raw}");
         } else {
             Output::error("Error reading from application!");
         }
     }
 }
示例#3
0
 /**
  * Confirm the user account via the confirmation link.
  */
 public function getConfirm()
 {
     if ($cyphserstring = Request::get('u', 'encrypted')) {
         $user = UserModel::loadByEncryptedUserReference($cyphserstring);
         $user->setConfirmed();
         Messenger::message('Your account ' . $user->email . ' has been confirmed.');
         $this->loginRedirect();
     } else {
         Messenger::error('Invalid request');
     }
 }