public function addUser(User $l) { $this->collUsers[] = $l; $l->setUserGroup($this); }
/** * Verify the data and create the account. * @param String $username - the username of the user * @param String $password - the password of the user * @param String $email - the email of the user * @param boolean $isTokenValid - the CSRF token is valid * @return an array with data validation result */ public function createAccount($username, $password, $email, $isTokenValid) { $result = array('isSuccessful' => false, 'isUsernameEmpty' => empty($username), 'isUsernameLegal' => $this->isUsernameLegal($username), 'isUsernameExists' => $this->isUsernameExists($username), 'isPasswordEmpty' => empty($password), 'isPasswordLegal' => $this->isPasswordLegal($password), 'isEmailEmpty' => empty($email), 'isEmailLegal' => $this->isEmailLegal($email), 'isEmailExists' => $this->isEmailExists($email), 'isTokenValid' => $isTokenValid); $result['isSuccessful'] = !$result['isUsernameEmpty'] && $result['isUsernameLegal'] && !$result['isUsernameExists'] && !$result['isPasswordEmpty'] && $result['isPasswordLegal'] && !$result['isEmailEmpty'] && $result['isEmailLegal'] && !$result['isEmailExists'] && $result['isTokenValid']; if ($result['isSuccessful']) { $defaultUserGroup = UserGroup::findFirst("user_group_slug = 'user'"); $user = new User(); $user->setUsername($username); $user->setPassword(md5($password)); $user->setEmail($email); $user->setUserGroup($defaultUserGroup); if (!$user->create()) { $result['isSuccessful'] = false; } else { $this->updateUserMeta($user, 'registerTime', date('Y-m-d H:i:s')); $this->sendVerificationEmail('Please Confirm Your Email Address', 'HelloMessage', $username, $email); } } return $result; }