public function testIndexNoAdmin() { $s = new UserSession('azerty', 'azerty'); $s->save(); $this->request('admin'); $this->assertRedirected(''); $this->assertFlashError('You don\'t have the rights to view this page'); }
/** * @param $user User * @param $sessionOnly boolean * @param null $expireDate int * @return UserSession */ public static function createForUser($user, $expireDate) { $session = new UserSession(); $session->user = $user->id; $session->token = Auth::generateSessionToken($user->salt); $session->createDate = Database::now(); $session->expireDate = CommonUtil::sqlTimeStamp($expireDate); $session->expired = 0; $session->save(); return $session; }
/** * @post */ public function executeLogin($username, $password, $redirect = '/') { $session = new UserSession($username, $password); try { $session->save(); $this->notice(t('You are now logged in')); $this->redirect($redirect); } catch (ValidationException $e) { $this->error(t('You are not logged in')); $this->redirect = $redirect; $this->session = $session; $this->render('login'); } }
public function checkAuthentication() { $this->user = null; if (isset($_COOKIE[$this->cookie_name])) { $arr = explode('-', $_COOKIE[$this->cookie_name]); $session_id = intval($arr[0]); $session_token = $arr[1]; } if (isset($session_id)) { $this->session = new UserSession($this->db, $session_id); if (isset($this->session) && $this->session->is_loaded && Authentication::verifyPassword($session_token, $this->session->val('user_session_token_hash'))) { $expires = time() + Authentication::$session_expire; $session = new UserSession($this->db); $session->data['user_session_id'] = $session_id; $session->data['user_session_expires'] = SqlQuery::mysqlTimestamp($expires); $session->save(); setcookie($this->cookie_name, $this->session->val('user_session_id') . '-' . $session_token, $expires, '/', false, false); $this->user = new User($this->db, $this->session->val('user_session_user_id')); $this->updateLastAccess(); } } }
/** * @remotable * @formHandler */ public function doLogin($params) { $userName = $params['login']; $isDesktop = false; if (isset($params['isdesktop'])) { $isDesktop = true; } $this->setSessionValue('isDesktop', $isDesktop); $q = Doctrine_Query::create()->select("u.*")->from("User u")->where('u.login = ?', $userName)->andWhere('u.isActive = ?', 1); $user = $q->fetchOne(); if (isset($params['password'])) { $success = $user != null && $user->password == $this->generateHash($params['password']); } else { $success = $user != null && $user->devicePin == $params['devicePin']; } if ($success) { //detect environments and set debug: 0:false/debug off 1:true/debug on $fullPath = $_SERVER["REQUEST_URI"]; if (stristr($fullPath, "uat")) { $userSession->debug = 1; } elseif (stristr($fullPath, "moqoldWeb")) { $userSession->debug = 1; } else { $userSession->debug = 0; } $this->setSessionValue('user', $user->ID); $this->setSessionValue('userRole', $user->userRoleID); $this->setSessionValue('contactID', $user->contactID); $userSession = new UserSession(); $userSession->userID = $user->ID; $userSession->hostIP = $this->getRealIpAddr(); $userSession->userAgent = $_SERVER['HTTP_USER_AGENT']; //$userSession->refererName = -- useless in AJAX apps $userSession->startTime = $this->getDateFormat(); $userSession->endTime = $userSession->startTime; $userSession->save(); $this->setSessionValue('sessionId', $userSession->ID); } return $this->isLoggedIn($isDesktop); }
private function login($u) { $s = new UserSession($u, $u); $s->save(); }
private function login($name) { $s = new UserSession($name, $name); $s->save(); }
private function login($user = '******') { $s = new UserSession($user, $user); $s->save(); }
private function login($u = 'nathan') { $session = new UserSession($u, $u); $session->save(); }
public function testModelsNoAdmin() { $s = new UserSession('azerty', 'azerty'); $s->save(); $modules = Admin::modules(); $this->assertNull($modules); $s->delete(); $modules = Admin::modules(); $this->assertNull($modules); }
public function testUserLocked() { $user = new User; $user->username = '******'; $user->email = '*****@*****.**'; $user->password = '******'; $user->passwordConfirmation = 'thepass'; $key = $user->save(); $session = new UserSession('someuser', 'thepass'); try { $session->save(); $this->fail('Expected exception'); } catch (ValidationException $e) { $this->assertEquals('User is not activated', $session->username_error); } }