Exemple #1
0
 public function Login($username, $loginContext)
 {
     Log::Debug('Logging in with user: %s', $username);
     $user = $this->userRepository->LoadByUsername($username);
     if ($user->StatusId() == AccountStatus::ACTIVE) {
         $loginData = $loginContext->GetData();
         $loginTime = LoginTime::Now();
         $language = $user->Language();
         if (!empty($loginData->Language)) {
             $language = $loginData->Language;
         }
         $user->Login($loginTime, $language);
         $this->userRepository->Update($user);
         return $this->GetUserSession($user, $loginTime);
     }
     return new NullUserSession();
 }
 function testLoginGetsUserDataFromDatabase()
 {
     $language = 'en_gb';
     $this->userRepository->expects($this->once())->method('LoadByUsername')->with($this->equalTo($this->username))->will($this->returnValue($this->user));
     LoginTime::$Now = time();
     $this->user->Login(LoginTime::Now(), $language);
     $this->userRepository->expects($this->once())->method('Update')->with($this->equalTo($this->user));
     $this->authorization->expects($this->once())->method('IsApplicationAdministrator')->with($this->equalTo($this->user))->will($this->returnValue(true));
     $this->authorization->expects($this->once())->method('IsGroupAdministrator')->with($this->equalTo($this->user))->will($this->returnValue(true));
     $this->authorization->expects($this->once())->method('IsResourceAdministrator')->with($this->equalTo($this->user))->will($this->returnValue(true));
     $this->authorization->expects($this->once())->method('IsScheduleAdministrator')->with($this->equalTo($this->user))->will($this->returnValue(true));
     $context = new WebLoginContext(new LoginData(false, $language));
     $actualSession = $this->auth->Login($this->username, $context);
     $user = new UserSession($this->id);
     $user->FirstName = $this->fname;
     $user->LastName = $this->lname;
     $user->Email = $this->email;
     $user->Timezone = $this->timezone;
     $user->HomepageId = $this->homepageId;
     $user->IsAdmin = true;
     $user->IsGroupAdmin = true;
     $user->IsResourceAdmin = true;
     $user->IsScheduleAdmin = true;
     $user->LanguageCode = $language;
     $user->LoginTime = LoginTime::Now();
     $user->PublicId = $this->publicId;
     $user->ScheduleId = $this->scheduleId;
     foreach ($this->groups as $group) {
         $user->Groups[] = $group->GroupId;
     }
     $this->assertEquals($user, $actualSession);
 }
 public function testDoesNotAutoLoginIfLastLoginDateOnCookieDoesNotMatch()
 {
     $userid = 'userid';
     $lastLogin = LoginTime::Now();
     $email = '*****@*****.**';
     $cookie = new LoginCookie($userid, $lastLogin);
     $rows = array(array(ColumnNames::USER_ID => $userid, ColumnNames::LAST_LOGIN => 'not the same thing', ColumnNames::EMAIL => $email));
     $this->db->SetRows($rows);
     $valid = $this->webAuth->CookieLogin($cookie->Value, $this->loginContext);
     $this->assertFalse($valid, 'should not be valid if cookie does not match');
     $this->assertEquals(1, count($this->db->_Commands));
     $this->assertFalse($this->fakeAuth->_LoginCalled);
     $this->assertEquals(new NullUserSession(), $this->fakeServer->GetUserSession());
 }