Clone wiki

FrontendUser / Login extensions and plugins

Login extensions and plugins

Email address / nickname login

Login with the email address instead of the username.

<?php
    $fieldUser = $fu->form->get('username');
    $fieldUser->addHookBefore('FrontendUser::auth', function($event) {
        $email = wire('fu')->form->fhValue('username', 'email');
        $loginUser = wire('users')->get("email={$email}");

        if ($loginUser instanceof User && !$loginUser->isGuest()) {
            $userObj = $event->arguments[0];
            $userObj->name = $loginUser->name;
        }
    });

Also any other user template field is possible like user id or a "nickname" (defined field).

<?php
    $fieldUser = $fu->form->get('username');
    $fieldUser->addHookBefore('FrontendUser::auth', function($event) {
        $nick = wire('fu')->form->fhValue('username', 'text');
        $loginUser = wire('users')->get("nickname={$nick}");

        if ($loginUser instanceof User && !$loginUser->isGuest()) {
            $userObj = $event->arguments[0];
            $userObj->name = $loginUser->name;
        }
    });

Updated