New code for email address change in profile. See #857

This commit is contained in:
James Cole
2017-09-26 08:52:16 +02:00
parent ea1d543795
commit 91e96aa4b9
22 changed files with 612 additions and 9 deletions

View File

@@ -52,6 +52,33 @@ class UserRepository implements UserRepositoryInterface
return true;
}
/**
* @param User $user
* @param string $newEmail
*
* @return bool
*/
public function changeEmail(User $user, string $newEmail): bool
{
$oldEmail = $user->email;
// save old email as pref
Preferences::setForUser($user, 'previous_email_latest', $oldEmail);
Preferences::setForUser($user, 'previous_email_' . date('Y-m-d-H-i-s'), $oldEmail);
// set undo and confirm token:
Preferences::setForUser($user, 'email_change_undo_token', strval(bin2hex(random_bytes(16))));
Preferences::setForUser($user, 'email_change_confirm_token', strval(bin2hex(random_bytes(16))));
// update user
$user->email = $newEmail;
$user->blocked = 1;
$user->blocked_code = 'email_changed';
$user->save();
return true;
}
/**
* @param User $user
* @param string $password
@@ -119,6 +146,16 @@ class UserRepository implements UserRepositoryInterface
return new User;
}
/**
* @param string $email
*
* @return User|null
*/
public function findByEmail(string $email): ?User
{
return User::where('email', $email)->first();
}
/**
* Return basic user information.
*

View File

@@ -42,6 +42,14 @@ interface UserRepositoryInterface
*/
public function attachRole(User $user, string $role): bool;
/**
* @param User $user
* @param string $newEmail
*
* @return bool
*/
public function changeEmail(User $user, string $newEmail): bool;
/**
* @param User $user
* @param string $password
@@ -80,6 +88,13 @@ interface UserRepositoryInterface
*/
public function find(int $userId): User;
/**
* @param string $email
*
* @return User|null
*/
public function findByEmail(string $email): ?User;
/**
* Return basic user information.
*