add email to user service

master
Corne Oppelaar 9 years ago
parent 86f878acae
commit 837a990f59
No known key found for this signature in database
GPG Key ID: FF32F66315D2E8E5

@ -12,11 +12,12 @@ class User extends Main
/** /**
* @param string $invite * @param string $invite
* @param string $username * @param string $username
* @param string $email
* @param string $password * @param string $password
* @return UserModel * @return UserModel
* @throws \Exception * @throws \Exception
*/ */
public function register($invite, $username, $password) public function register($invite, $username, $email, $password)
{ {
$invite = InviteQuery::create()->findOneByInvite($invite); $invite = InviteQuery::create()->findOneByInvite($invite);
@ -24,12 +25,13 @@ class User extends Main
throw new \Exception("Invalid invite code"); throw new \Exception("Invalid invite code");
} }
$this->validateUserParams($username, $password); $this->validateUserParams($username, $email, $password);
$inviteUser = $invite->getUser(); $inviteUser = $invite->getUser();
$user = new UserModel(); $user = new UserModel();
$user->setUsername($username); $user->setUsername($username);
$user->setEmail($email);
$user->setPassword(\password_hash($password, PASSWORD_DEFAULT)); $user->setPassword(\password_hash($password, PASSWORD_DEFAULT));
if ($inviteUser === null || $inviteUser->getMaxInvites() === -1) { if ($inviteUser === null || $inviteUser->getMaxInvites() === -1) {
@ -47,7 +49,7 @@ class User extends Main
return $user; return $user;
} }
public function validateUserParams($username, $password) { public function validateUserParams($username, $email, $password) {
if ($username === "") { if ($username === "") {
throw new \Exception("No username given"); throw new \Exception("No username given");
} }
@ -56,6 +58,10 @@ class User extends Main
throw new \Exception("Username can only consist of a-z, 0-9 and -"); throw new \Exception("Username can only consist of a-z, 0-9 and -");
} }
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new \Exception("Email is invalid");
}
if ($password === "") { if ($password === "") {
throw new \Exception("Password is nothing, though strong. we rather not have you use that"); throw new \Exception("Password is nothing, though strong. we rather not have you use that");
} }
@ -69,9 +75,9 @@ class User extends Main
} }
} }
public function createSuperuser($username, $password) { public function createSuperuser($username, $email, $password) {
$this->validateUserParams($username, $password); $this->validateUserParams($username, $email, $password);
$user = new UserModel(); $user = new UserModel();
$user->setUsername($username); $user->setUsername($username);

Loading…
Cancel
Save