예제 #1
0
 public function registerUser(array $params)
 {
     if (empty($params)) {
         throw new \Exception('Empty params passed to create new user');
     }
     $missingData = array();
     if (!isset($params[StorouConstants::KEY_USER_NAME_STRING])) {
         $missingData[] = StorouConstants::KEY_USER_NAME_STRING;
     }
     if (!isset($params[StorouConstants::KEY_USER_EMAIL_STRING])) {
         $missingData[] = StorouConstants::KEY_USER_EMAIL_STRING;
     }
     if (!isset($params[StorouConstants::KEY_USER_PASSWORD_STRING])) {
         $missingData[] = StorouConstants::KEY_USER_PASSWORD_STRING;
     }
     if (!isset($params[StorouConstants::KEY_USER_DISPLAY_NAME_STRING])) {
         $missingData[] = StorouConstants::KEY_USER_DISPLAY_NAME_STRING;
     }
     if (!empty($missingData)) {
         throw new \Exception('Missing data ' . implode(", ", $missingData));
     }
     /*
      * Validate name
      */
     $userName = SanitationUtils::getCleanedString($params[StorouConstants::KEY_USER_NAME_STRING]);
     if (!ValidationUtils::isValidUserName($userName)) {
         throw new \InvalidArgumentException('Invalid name provided. (Make sure name has at least 3 characters) ');
     }
     /*
      * Validate email
      */
     $email = SanitationUtils::getCleanedEmail($params[StorouConstants::KEY_USER_EMAIL_STRING]);
     if (!ValidationUtils::isValidEmail($email)) {
         throw new \InvalidArgumentException('Invalid email provided');
     }
     /*
      * Validate password.
      */
     $password = SanitationUtils::getCleanedEmail($params[StorouConstants::KEY_USER_PASSWORD_STRING]);
     if (!ValidationUtils::isValidPassword($password)) {
         throw new \InvalidArgumentException('Invalid password. Password should have 6 characters, including one digit. ');
     }
     /*
      * Validate country name
      */
     $displayName = SanitationUtils::getCleanedEmail($params[StorouConstants::KEY_USER_DISPLAY_NAME_STRING]);
     if (!ValidationUtils::isValidUserName($displayName)) {
         throw new \InvalidArgumentException('Invalid display name');
     }
     /*
      * Check is user already exists in the system
      */
     $user = $this->dataAccessService->getUserByKey('email', $email);
     if ($user && !empty($user->getEmail()) && $user->getEmail() == $email) {
         throw new \Exception('User already registered');
     }
     if (!$this->checkUserNameAvailable($userName)) {
         throw new \InvalidArgumentException('Username Already exists');
     }
     /*
      * Construct new user with provided data
      */
     $user = new StorouUser();
     $passwordHash = PasswordUtils::getHashedPassword($password);
     $user->setUserName($userName);
     $user->setEmail($email);
     $user->setPassword($passwordHash);
     $user->setDisplayName($displayName);
     return $this->userDataProvider->addUser($user);
 }