log_user_in()
public function log_user_in(string $username, int $remember): void
Description
Logs a user in by generating an authentication token and storing it in the database. Handles both web and MX (Trongate MX/API) request types.
After successful login, resets failed login counters and lockout information, then redirects to the dashboard home.
For MX requests, returns the token as a plain text response rather than redirecting.
Parameters
| Parameter | Type | Description |
| $username | string | The username to authenticate and log in. |
| $remember | int | 0 for session‑only login, 1 for persistent cookie (30 days). |
Return Value
| Type | Description |
| void | Redirects on success or terminates with 500 error on failure. |
Example Usage
// Login form submission handler
public function submit_login() {
$username = post('username', true);
$password = post('password', true);
$this->validation->set_rules('username', 'username', 'required|callback_login_check');
$this->validation->set_rules('password', 'password', 'required|min_length[5]');
if ($this->validation->run() === true) {
$remember = (int) (bool) post('remember', true);
$this->trongate_administrators->log_user_in($username, $remember);
}
}
// Direct login (bypass validation)
public function auto_login(string $username) {
$this->trongate_administrators->log_user_in($username, 1);
}
// After successful login, user is redirected to:
// trongate_administrators/manage (dashboard home)