/** * @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); }
/** * @param \Lio\Github\GithubAuthenticatorListener $listener * @param \Lio\Accounts\User $user * @return \Illuminate\Http\RedirectResponse */ private function loginUser(GithubAuthenticatorListener $listener, User $user) { if ($user->isBanned()) { return $listener->userIsBanned($user); } return $listener->userFound($user); }
/** * Increases a user's spam count * * @param \Lio\Accounts\User $user */ private function increaseUserSpamCount(User $user) { $user->spam_count = $user->spam_count + 1; // If the user reaches a spam threshold of 3 or more, automatically ban him if ($user->spam_count >= 3) { $user->is_banned = true; } $user->save(); }
/** * Determine if an email already exists for a user * * @param string $email * @return bool */ public function emailExists($email) { return (bool) User::where('email', $email)->count(); }
/** * Find a user by its confirmation code * * @param string $code * @return \Lio\Accounts\User */ public function getByConfirmationCode($code) { return $this->model->where('confirmation_code', $code)->first(); }
public function getArticlesByAuthor(User $author) { return $author->articles()->orderBy('articles.status', 'asc')->orderBy('published_at', 'desc')->orderBy('created_at', 'desc'); }
private function createUsers() { User::create(['email' => '*****@*****.**', 'name' => 'Big Ole User Name']); }