public function testSendSignup_WithProject_PropertiesToFromBodyOk()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $userId = $e->createUser('User', 'Name', '*****@*****.**');
     $user = new UserModel($userId);
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $project->projectCode = 'test_project';
     $project->write();
     $delivery = new MockCommunicateDelivery();
     $website = Website::get('scriptureforge.org');
     $website->defaultProjectCode = 'test_project';
     Communicate::sendSignup($user, $website, $delivery);
     // What's in the delivery?
     $senderEmail = 'no-reply@' . $e->website->domain;
     $expectedTo = array($user->emailPending => $user->name);
     $this->assertPattern('/' . $e->website->name . '/', $delivery->from[$senderEmail]);
     $this->assertEqual($expectedTo, $delivery->to);
     $this->assertPattern('/' . $e->website->name . '/', $delivery->subject);
     $this->assertPattern('/Name/', $delivery->content);
     $this->assertPattern('/' . $user->validationKey . '/', $delivery->content);
 }
Exemplo n.º 2
0
 /**
  * Register a new user
  * @param array $params
  * @param string $captcha_info
  * @param Website $website
  * @param DeliveryInterface $delivery
  * @throws \Exception
  * @return string $userId
  */
 public static function register($params, $captcha_info, $website, DeliveryInterface $delivery = null)
 {
     if (strtolower($captcha_info['code']) != strtolower($params['captcha'])) {
         return false;
         // captcha does not match
     }
     $user = new UserModel();
     JsonDecoder::decode($user, $params);
     UserCommands::assertUniqueIdentity($user, $params['username'], $params['email'], $website);
     $user->active = false;
     $user->role = SystemRoles::USER;
     $user->siteRole[$website->domain] = $website->userDefaultSiteRole;
     if (!$user->emailPending) {
         if (!$user->email) {
             throw new \Exception("Error: no email set for user signup.");
         }
         $user->emailPending = $user->email;
         $user->email = '';
     }
     $userId = $user->write();
     // Write the password
     $userPassword = new UserModelWithPassword($userId);
     $userPassword->setPassword($params['password']);
     $userPassword->write();
     // if website has a default project then add them to that project
     $project = ProjectModel::getDefaultProject($website);
     if ($project) {
         $project->addUser($user->id->asString(), ProjectRoles::CONTRIBUTOR);
         $user->addProject($project->id->asString());
         $project->write();
         $user->write();
     }
     Communicate::sendSignup($user, $website, $delivery);
     return $userId;
 }