Example #1
0
 public function Register($username, $email, $firstName, $lastName, $password, $timezone, $language, $homepageId, $additionalFields = array(), $attributeValues = array(), $groups = null)
 {
     $encryptedPassword = $this->_passwordEncryption->EncryptPassword($password);
     $attributes = new UserAttribute($additionalFields);
     if ($this->CreatePending()) {
         $user = User::CreatePending($firstName, $lastName, $email, $username, $language, $timezone, $encryptedPassword->EncryptedPassword(), $encryptedPassword->Salt(), $homepageId);
     } else {
         $user = User::Create($firstName, $lastName, $email, $username, $language, $timezone, $encryptedPassword->EncryptedPassword(), $encryptedPassword->Salt(), $homepageId);
     }
     $user->ChangeAttributes($attributes->Get(UserAttribute::Phone), $attributes->Get(UserAttribute::Organization), $attributes->Get(UserAttribute::Position));
     $user->ChangeCustomAttributes($attributeValues);
     if ($groups != null) {
         $user->WithGroups($groups);
     }
     if (Configuration::Instance()->GetKey(ConfigKeys::REGISTRATION_AUTO_SUBSCRIBE_EMAIL, new BooleanConverter())) {
         foreach (ReservationEvent::AllEvents() as $event) {
             $user->ChangeEmailPreference($event, true);
         }
     }
     $userId = $this->_userRepository->Add($user);
     $this->AutoAssignPermissions($userId);
     if (Configuration::Instance()->GetKey(ConfigKeys::REGISTRATION_NOTIFY, new BooleanConverter())) {
         ServiceLocator::GetEmailService()->Send(new AccountCreationEmail($user, ServiceLocator::GetServer()->GetUserSession()));
     }
     return $user;
 }
Example #2
0
 public function Register($username, $email, $firstName, $lastName, $password, $timezone, $language, $homepageId, $additionalFields = array(), $attributeValues = array())
 {
     $encryptedPassword = $this->_passwordEncryption->EncryptPassword($password);
     $attributes = new UserAttribute($additionalFields);
     if ($this->CreatePending()) {
         $user = User::CreatePending($firstName, $lastName, $email, $username, $language, $timezone, $encryptedPassword->EncryptedPassword(), $encryptedPassword->Salt(), $homepageId);
     } else {
         $user = User::Create($firstName, $lastName, $email, $username, $language, $timezone, $encryptedPassword->EncryptedPassword(), $encryptedPassword->Salt(), $homepageId);
     }
     $user->ChangeAttributes($attributes->Get(UserAttribute::Phone), $attributes->Get(UserAttribute::Organization), $attributes->Get(UserAttribute::Position));
     $user->ChangeCustomAttributes($attributeValues);
     if (Configuration::Instance()->GetKey(ConfigKeys::REGISTRATION_AUTO_SUBSCRIBE_EMAIL, new BooleanConverter())) {
         foreach (ReservationEvent::AllEvents() as $event) {
             $user->ChangeEmailPreference($event, true);
         }
     }
     $userId = $this->_userRepository->Add($user);
     $this->AutoAssignPermissions($userId);
     $addgroupname = Configuration::Instance()->GetKey(ConfigKeys::NEW_USER_GROUP);
     // Match group name to group_id
     $addgroupid_res = ServiceLocator::GetDatabase()->Query(new AdHocCommand("select group_id from groups where name = '{$addgroupname}'"));
     while ($row = $addgroupid_res->GetRow()) {
         $addgroupid = $row['group_id'];
     }
     //Add user to group
     if ($addgroupid != NULL) {
         ServiceLocator::GetDatabase()->Execute(new AdHocCommand("insert into user_groups(user_id, group_id) VALUES ({$userId}, {$addgroupid})"));
     }
     return $user;
 }
Example #3
0
 public function testDoesNotActivateUserIfManualActivationIsRequired()
 {
     $this->fakeConfig->SetKey(ConfigKeys::REGISTRATION_REQUIRE_ACTIVATION, 'true');
     $user = User::CreatePending($this->fname, $this->lname, $this->email, $this->login, $this->language, $this->timezone, $this->fakeEncryption->_Encrypted, $this->fakeEncryption->_Salt, $this->homepageId);
     $user->ChangeAttributes($this->phone, $this->organization, $this->position);
     $user->ChangeCustomAttributes($this->attributes);
     $this->userRepository->expects($this->once())->method('Add')->with($this->equalTo($user));
     $registeredUser = $this->registration->Register($this->login, $this->email, $this->fname, $this->lname, $this->password, $this->timezone, $this->language, $this->homepageId, $this->additionalFields, $this->attributes);
     $this->assertTrue($this->fakeEncryption->_EncryptPasswordCalled);
     $this->assertEquals($this->password, $this->fakeEncryption->_LastPassword);
     $this->assertEquals($user, $registeredUser);
 }