Redaxscript\Auth::login PHP Метод

login() публичный Метод

login the user
С версии: 3.0.0
public login ( integer $userId = null ) : boolean
$userId integer identifier of the user
Результат boolean
    public function login($userId = null)
    {
        $user = Db::forTablePrefix('users')->whereIdIs($userId)->where('status', 1)->findOne();
        if ($user) {
            $groupArray = array_map('intval', explode(',', $user->groups));
            $group = Db::forTablePrefix('groups')->whereIdIn($groupArray)->where('status', 1)->select($this->_typeArray)->findArray();
            /* set filter */
            $this->setPermission('filter', [1]);
            /* process groups */
            foreach ($group as $key => $value) {
                foreach ($value as $keySub => $valueSub) {
                    $valueArray = array_map('intval', explode(',', $valueSub));
                    $this->setPermission($keySub, $valueArray);
                }
            }
            /* set user */
            $this->setUser('id', $user->id);
            $this->setUser('name', $user->name);
            $this->setUser('user', $user->user);
            $this->setUser('email', $user->email);
            $this->setUser('language', $user->language);
            $this->setUser('groups', $user->groups);
            /* save user and permission */
            $this->save();
        }
        return $this->getStatus();
    }

Usage Example

Пример #1
0
 /**
  * process the class
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     $emailValidator = new Validator\Email();
     $loginValidator = new Validator\Login();
     $auth = new Auth($this->_request);
     /* process post */
     $postArray = ['password' => $specialFilter->sanitize($this->_request->getPost('password')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')];
     /* user and email */
     $users = Db::forTablePrefix('users');
     if ($emailValidator->validate($this->_request->getPost('user')) === Validator\ValidatorInterface::PASSED) {
         $postArray['user'] = $emailFilter->sanitize($this->_request->getPost('user'));
         $users->where('email', $postArray['user']);
     } else {
         if ($loginValidator->validate($this->_request->getPost('user')) === Validator\ValidatorInterface::PASSED) {
             $postArray['user'] = $specialFilter->sanitize($this->_request->getPost('user'));
             $users->where('user', $postArray['user']);
         }
     }
     $user = $users->where('status', 1)->findOne();
     /* handle error */
     $messageArray = $this->_validate($postArray, $user);
     if ($messageArray) {
         return $this->_error(['message' => $messageArray]);
     }
     /* handle success */
     if ($auth->login($user->id)) {
         return $this->_success();
     }
     return $this->_error(['message' => $this->_language->get('something_wrong')]);
 }
All Usage Examples Of Redaxscript\Auth::login