Example #1
0
 public function login($username, $password)
 {
     $ip = ipRequest()->getServer('REMOTE_ADDR');
     $preventReason = ipJob('ipAdminLoginPrevent', array('username' => $username));
     if ($preventReason) {
         $this->errors = array('global_error' => $preventReason);
         ipLog()->notice('Admin.loginPrevented: {username} from {ip}', array('username' => $username, 'ip' => ipRequest()->getServer('REMOTE_ADDR')));
         return false;
     }
     $administrator = \Ip\Internal\Administrators\Service::getByUsername($username);
     if (!$administrator) {
         \Ip\ServiceLocator::dispatcher()->event('ipAdminLoginFailed', array('username' => $username, 'ip' => ipRequest()->getServer('REMOTE_ADDR')));
         ipLog()->info('Admin.incorrectLogin: {username} from {ip}', array('username' => $username, 'ip' => $ip));
         $this->errors = array('login' => __('Following user doesn\'t exist', 'Ip-admin'));
         return false;
     }
     if (\Ip\Internal\Administrators\Service::checkPassword($administrator['id'], $password)) {
         Service::setAdminLogin($username);
         return true;
     } else {
         \Ip\ServiceLocator::dispatcher()->event('ipAdminLoginFailed', array('username' => $username, 'ip' => ipRequest()->getServer('REMOTE_ADDR')));
         ipLog()->info('Admin.incorrectLogin: {username} from {ip}', array('username' => $username, 'ip' => $ip));
         $this->errors = array('password' => __('Incorrect password', 'Ip-admin'));
         return false;
     }
 }