AuthService
class AuthService
Supports authentication operations.
Constants
| PENDING_PASSWORD_RESET |
Session key holding the id of the user who has just proven their
credentials and must set a new password. The reset page only acts on
this user, so the user id in the URL cannot be used to reset someone
else's password. |
Methods
Checks if a user is logged in.
Hashes a plain text password using PHP's password_hash() with the default algorithm.
Tests for login attempts and sets session messages when there is a failed attempt or when account is locked.
Logs in user from cookie.
Perform logout operation on current logged in user. The record for the current logged in user is removed from the user_session table and the corresponding cookie is deleted.
Handles the complete flow of resetting a user’s password, including setting the confirmation field and updating the record.
Records that a user has proven their credentials and must now set a new password. Call this when login detects the reset_password flag, before redirecting to the reset page.
Returns the user whose password may be reset in this session. The id must match the user recorded by beginPasswordReset() and that user must still have the reset_password flag set.
Details
at line 36
static string
confirm(Input $request)
Gets value of password confirm field. Assumes field value is "confirm".
at line 46
static User|false|null
currentUser()
Checks if a user is logged in.
at line 57
static string
hashPassword(string $password)
Hashes a plain text password using PHP's password_hash() with the default algorithm.
at line 73
static Login
login(Input $request, Login $loginModel, string $username, bool $mailer = false)
Attempts to log a user in. If successful, resets login attempts and creates a session. Otherwise, tracks failed attempts and optionally triggers an email notification.
at line 114
static Login
loginAttempts(User $user, Login $loginModel, bool $mailer = false)
Tests for login attempts and sets session messages when there is a failed attempt or when account is locked.
at line 143
static void
loginUser(User $loginUser, bool $rememberMe = false)
Creates a session when the user logs in. A new record is added to the user_sessions table and a cookie is created if remember me is selected.
at line 166
static User|null
loginUserFromCookie()
Logs in user from cookie.
at line 185
static void
logout(Input $request)
Logs out the currently logged-in user by clearing the session and deleting any active cookies.
at line 206
static bool
logoutUser(User $user)
Perform logout operation on current logged in user. The record for the current logged in user is removed from the user_session table and the corresponding cookie is deleted.
at line 220
static void
passwordReset(Input $request, User $user)
Handles the complete flow of resetting a user’s password, including setting the confirmation field and updating the record.
at line 254
static void
beginPasswordReset(User $user)
Records that a user has proven their credentials and must now set a new password. Call this when login detects the reset_password flag, before redirecting to the reset page.
at line 267
static User|null
pendingPasswordResetUser(int $id)
Returns the user whose password may be reset in this session. The id must match the user recorded by beginPasswordReset() and that user must still have the reset_password flag set.
at line 288
static Uploads|null
profileImageUpload(User $user)
Processes a profile image upload and returns an Uploads object.
Assumes the input name is profileImage.