예제 #1
0
 protected function _validateLogin(Model_User $user)
 {
     /* C помощью модели проверяем наличие пользователя с таким логином */
     if ($user->exists($this->login->value)) {
         $this->invalidate();
         $error = 'Указанное имя пользователя уже занято';
         $this->setValidationError('login', $error);
         return false;
     }
     return true;
 }
예제 #2
0
 public function validate(Http_Request $request, Model_User $user)
 {
     /* Выполняем базовую проверку данных формы */
     $result = parent::validate($request);
     if (false === $result) {
         return $result;
     }
     /* Проверяем, есть ли пользователь с таким логином */
     if (!$user->exists($this->login->value)) {
         $this->setValue('login', '');
         $this->setValidationError('login', 'Пользователь не найден');
         return false;
     }
     return $result;
 }
예제 #3
0
 protected function _create_default_admin()
 {
     $user = new Model_User();
     $user->where('email', mdi::config('admin_default_email'))->get();
     if ($user->exists()) {
         return;
     }
     $credential = new MDI_Credential_Native();
     $credential->email = mdi::config('admin_default_email');
     $credential->password = mdi::config('admin_default_password');
     $credential->_need_encrpyt = TRUE;
     $credential->save();
     $user->email = mdi::config('admin_default_email');
     $user->grade = mdi::config('admin_default_grade');
     $user->name = 'Admin';
     $user->phone = '0000-0000';
     $user->save($credential, 'credential_native');
 }
 public function signInAction()
 {
     if (!$this->_request->isXmlHttpRequest()) {
         return;
     }
     $arp = new AjaxResponse();
     $arp->setStatus(AjaxResponse::STATUS_FAILED);
     $email = trim($this->_getParam('email'));
     $password = trim($this->_getParam('password'));
     if (empty($email) || empty($password)) {
         $arp->setMessage('E-mail and password can not be empty.');
         $this->json($arp);
         return;
     }
     $hashedPassword = hash('sha256', $password);
     $user = new Model_User($email);
     if (!$user->exists() || $user->get('password') != $hashedPassword) {
         $arp->setMessage('Authentication failed, You entered an incorrect username, or password.');
         $this->json($arp);
         return;
     }
     $this->setLoginCookie($email, $hashedPassword);
     $arp->setStatus(AjaxResponse::STATUS_OK);
     $this->json($arp);
 }