Exemplo n.º 1
0
 /**
  * @param User $user
  * @param string $loginTime
  * @return UserSession
  */
 private function GetUserSession(User $user, $loginTime)
 {
     $userSession = new UserSession($user->Id());
     $userSession->Email = $user->EmailAddress();
     $userSession->FirstName = $user->FirstName();
     $userSession->LastName = $user->LastName();
     $userSession->Timezone = $user->Timezone();
     $userSession->HomepageId = $user->Homepage();
     $userSession->LanguageCode = $user->Language();
     $userSession->LoginTime = $loginTime;
     $userSession->PublicId = $user->GetPublicId();
     $userSession->ScheduleId = $user->GetDefaultScheduleId();
     $userSession->IsAdmin = $this->roleService->IsApplicationAdministrator($user);
     $userSession->IsGroupAdmin = $this->roleService->IsGroupAdministrator($user);
     $userSession->IsResourceAdmin = $this->roleService->IsResourceAdministrator($user);
     $userSession->IsScheduleAdmin = $this->roleService->IsScheduleAdministrator($user);
     $userSession->CSRFToken = base64_encode(md5(uniqid(rand(), true)));
     foreach ($user->Groups() as $group) {
         $userSession->Groups[] = $group->GroupId;
     }
     foreach ($user->GetAdminGroups() as $group) {
         $userSession->AdminGroups[] = $group->GroupId;
     }
     return $userSession;
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 public function AllowUsernameChange($user)
 {
     return $this->roleService->IsApplicationAdministrator($user);
 }