Overview

The Authentication class extends MY_Controller and provides functionality for user authentication, login, password reset, and user settings management.

Methods

getUser

Retrieves the currently logged-in user’s data.

static function getUser()
Returns
object|null

User data object if a user is logged in, null otherwise.

showLogin

Displays the login page.

public function showLogin($errormessage = '')

checkLogin

Checks if a user is currently logged in.

public function checkLogin()
Returns
json

JSON object containing login status and menu text.

loginUser

Processes user login attempt.

public function loginUser()

This method handles form submission from the login page and redirects the user based on authentication results.

resetPw

Initiates the password reset process for a given email address.

public function resetPw()

This method sends a password reset email to the user if the email address is valid and associated with an account.

logout

Logs out the current user and destroys the session.

public function logout()

usersettings

Displays the user settings page.

public function usersettings($success = false)

updateUser

Updates user information based on form submission.

public function updateUser()

This method handles form validation and updates user data, including password if provided.

Helper Methods

password_check

Validates password strength.

public function password_check($password)
Returns
boolean

True if the password meets the required criteria, false otherwise.

email_exists

Checks if an email address exists in the newsletter subscribers list.

public function email_exists($email)
Returns
boolean

True if the email exists, false otherwise.

Dependencies

  • This class relies on the Authentication_model for database operations.
  • PHPMailer is used for sending password reset emails.
  • A custom PasswordHash library is used for password hashing.

Make sure to configure the email settings properly for the password reset functionality to work correctly.