lonnieezell / myth-auth

One-stop Auth package for CodeIgniter 4
MIT License
637 stars 208 forks source link

Help Error! Unable to locate a user with that activation code. #600

Open rifqmd opened 1 year ago

rifqmd commented 1 year ago

Php V8.2 Codeigniter V4.3

The SMTP email has been successfully sent to the email of the user who wants to activate the account, then click Activate account and will redirect to the login page, but the error appears on the login page. guess what the solution is, please

Screenshot 2023-08-04 at 2 40 06 PM
manageruz commented 1 year ago

Hi @rifqmd Can you share with your auth.php config file?

manageruz commented 1 year ago

and please show me your Activate account url

manageruz commented 1 year ago

After email has been successfully sent, but before hitting the activate account URL, check your database that the new registered user has been successfully created and the activation hash value is present.

rifqmd commented 1 year ago

Alright, here's the auth.php config file

class Auth extends BaseConfig
{
    public $defaultUserGroup = 'user';

    public $landingRoute = '/';

    public $reservedRoutes = [
        'login'                   => 'login',
        'logout'                  => 'logout',
        'register'                => 'register',
        'activate-account'        => 'activate-account',
        'resend-activate-account' => 'resend-activate-account',
        'forgot'                  => 'forgot',
        'reset-password'          => 'reset-password',
    ];

    public $authenticationLibs = [
        'local' => 'Myth\Auth\Authentication\LocalAuthenticator',
    ];

    public $views = [
        // 'login'           => 'Myth\Auth\Views\login',
        // 'register'        => 'Myth\Auth\Views\register',
        // 'forgot'          => 'Myth\Auth\Views\forgot',
        'login'           => '\App\Views\pages\auth\login',
        'register'        => '\App\Views\pages\auth\register',
        'forgot'          => '\App\Views\pages\auth\forgetPassword',
        'reset'           => 'Myth\Auth\Views\reset',
        'emailForgot'     => 'Myth\Auth\Views\emails\forgot',
        'emailActivation' => 'Myth\Auth\Views\emails\activation',
    ];

    public $viewLayout = 'Myth\Auth\Views\layout';

    public $validFields = ['email', 'username'];

    public $personalFields = ['fullname'];

    public $maxSimilarity = 50;

    public $allowRegistration = false;

    public $requireActivation = 'Myth\Auth\Authentication\Activators\EmailActivator';

    public $activeResetter = 'Myth\Auth\Authentication\Resetters\EmailResetter';

    public $allowRemembering = false;

    public $rememberLength = 30 * DAY;

    public $silent = false;

    public $hashAlgorithm = PASSWORD_DEFAULT;

    public $hashMemoryCost = 2048; // PASSWORD_ARGON2_DEFAULT_MEMORY_COST;

    public $hashTimeCost = 4; // PASSWORD_ARGON2_DEFAULT_TIME_COST;

    public $hashThreads = 4; // PASSWORD_ARGON2_DEFAULT_THREADS;

    public $hashCost = 10;

    public $minimumPasswordLength = 8;

    public $passwordValidators = [
        'Myth\Auth\Authentication\Passwords\CompositionValidator',
        // 'Myth\Auth\Authentication\Passwords\NothingPersonalValidator',
        // 'Myth\Auth\Authentication\Passwords\DictionaryValidator',
        // 'Myth\Auth\Authentication\Passwords\PwnedValidator',
    ];

    public $userActivators = [
        'Myth\Auth\Authentication\Activators\EmailActivator' => [
            'fromEmail' => null,
            'fromName'  => null,
        ],
    ];

    public $userResetters = [
        'Myth\Auth\Authentication\Resetters\EmailResetter' => [
            'fromEmail' => null,
            'fromName'  => null,
        ],
    ];

    public $resetTime = 3600;
}

And this is the HTML that links to the activation URL

<p>Activate my account or simply copy and then paste the link below to your web browser, <?= site_url() ?>.</p>

<p>To activate your account use this URL:</p>

<p><a href="<?= url_to('activate-account') . '?token=' . $hash ?>">Activate account</a>.</p>

<p>In case our email has been delivered into your SPAM / Bulk / Trash, kindly click "Not Spam" button to make sure that every single email from us is not going to your SPAM / Bulk / Trash folder.</p>
<p>If you did not registered on this website, you can safely ignore this email.</p>
rifqmd commented 1 year ago

each account creation has successfully entered the database and if activated at the stage click the url from the link but the error is considered 'Unable to locate a user with that activation code.' and hash activation does not exist in the database

manageruz commented 1 year ago

and hash activation does not exist in the database

Ok. Then in the AuthController.php file after the code below (it's inside attemptRegister() method) dump the $user variable and show me it's values please: $this->config->requireActivation === null ? $user->activate() : $user->generateActivateHash();

rifqmd commented 1 year ago

that part of the source code

// Save the user
$allowedPostFields = array_merge(['password'], $this->config->validFields, $this->config->personalFields);
$user              = new User($this->request->getPost($allowedPostFields));

$this->config->requireActivation === null ? $user->activate() : $user->generateActivateHash();
manageruz commented 1 year ago

after your above code just insert var_dump($user); die();