コード例 #1
0
 /**
  * Return errors array or a Member object.
  * 
  * @param string $login
  * @param string $password
  * @param string $confirmationPassword
  * @param string $email
  * @param int    $countryId
  * @param int    $regionId
  *
  * @return bool | array
  */
 public function create($login, $password, $confirmationPassword, $email, $countryId, $regionId)
 {
     $errors = [];
     if (($country = $this->countryManager->get($countryId)) === null) {
         $errors[] = $this->translator->translate('registration.invalid_country');
     }
     if (($region = $this->regionManager->get($regionId)) === null) {
         $errors[] = $this->translator->translate('registration.invalid_region');
     }
     $errors = array_merge($errors, $this->validate($login, $password, $confirmationPassword, $email));
     if (count($errors) > 0) {
         return $errors;
     }
     try {
         return $this->repository->create((new Member())->setLogin($login)->setPassword(hash('sha512', $password))->setSalt(md5(uniqid() . time()))->setIdentity($login)->setEmail($email)->setCountry($country)->setRegion($region)->setLanguage($this->translator->getBrowserLang())->setCreatedAt(new \DateTime())->setLastConnectedAt(new \DateTime())->setIsEnabled(true)->setIsBanned(false));
     } catch (\Exception $ex) {
         return [$ex->getMessage()];
     }
 }
コード例 #2
0
 public function testCreate()
 {
     $this->repository->create($this->getMemberMock());
     $this->assertEquals($this->repository->findOneBy(['login' => 'toto', 'password' => 'totor12']), $this->getMemberMock());
 }