<?php

/**
 * Auth module routes.
 * @var \CodeIgniter\Router\RouteCollection $routes
 */

// Guest-only (redirect away if already logged in).
$routes->group('', ['filter' => 'guest'], static function ($routes) {
    $routes->get('login', '\Modules\Auth\Controllers\LoginController::show');
    $routes->post('login', '\Modules\Auth\Controllers\LoginController::attempt');

    $routes->get('password/forgot', '\Modules\Auth\Controllers\PasswordController::forgotForm');
    $routes->post('password/forgot', '\Modules\Auth\Controllers\PasswordController::forgotSubmit');

    $routes->get('password/reset/(:segment)', '\Modules\Auth\Controllers\PasswordController::resetForm/$1');
    $routes->post('password/reset', '\Modules\Auth\Controllers\PasswordController::resetSubmit');
});

// Authenticated-only.
$routes->group('', ['filter' => 'auth'], static function ($routes) {
    $routes->get('logout', '\Modules\Auth\Controllers\LogoutController::index');

    $routes->get('password/change', '\Modules\Auth\Controllers\PasswordController::changeForm');
    $routes->post('password/change', '\Modules\Auth\Controllers\PasswordController::changeSubmit');

    $routes->get('account/sessions', '\Modules\Auth\Controllers\SessionController::index');
    $routes->post('account/sessions/revoke-others', '\Modules\Auth\Controllers\SessionController::revokeOthers');

    $routes->get('profile', '\Modules\Auth\Controllers\ProfileController::index');
});
