mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 12:12:18 +00:00
New code for email address change in profile. See #857
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
@@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user