/** * @param \Lio\Accounts\User $user * @param \Lio\Accounts\UserUpdaterListener $listener * @param array $data * @return mixed */ private function updateUser(User $user, UserUpdaterListener $listener, array $data) { $oldEmail = $user->email; $user->fill($data); // If the email changed, the user will need to re-confirm it. if ($data['email'] !== $oldEmail) { $user->confirmed = false; // Set a confirmation code for the user. He'll need to verify his email address // with this code before he can use certain sections on the website. $confirmationCode = Str::random(30); // We'll generate a new one if we find a user with the same code. while ($this->users->getByConfirmationCode($confirmationCode) !== null) { $confirmationCode = Str::random(30); } $user->confirmation_code = $confirmationCode; } // check the model validation if (!$this->users->save($user)) { return $listener->userValidationError($user->getErrors()); } // Send a confirmation email to the user. if ($data['email'] !== $oldEmail) { $this->confirmation->send($user); } return $listener->userUpdated($user, $data['email'] !== $oldEmail); }
public function putBanAndDeleteThreads($userId) { // Ban the user $user = $this->users->requireById($userId); $user->is_banned = 1; $this->users->save($user); // Remove all threads by the user $this->threads->deleteByAuthorId($userId); return $this->redirectAction('Admin\\UsersController@getIndex', ['success' => 'The user has been banned and its threads have been removed.']); }
private function createValidUserRecord($listener, $data) { $user = $this->users->getNew($data); // Set a confirmation code for the user. He'll need to verify his email address // with this code before he can use certain sections on the website. $confirmationCode = Str::random(30); // We'll generate a new one if we find a user with the same code. while ($this->users->getByConfirmationCode($confirmationCode) !== null) { $confirmationCode = Str::random(30); } $user->confirmation_code = $confirmationCode; // check the model validation if (!$this->users->save($user)) { return $listener->userValidationError($user->getErrors()); } // Send a confirmation email to the user. $this->confirmation->send($user); return $listener->userCreated($user); }