Login with username OR email

Hitler

Member
Apr 21, 2013
33
8
Hello,
I'm not sure how I could go about allowing the user to login with their username or email. I'm think it would be something like this, but if it's wrong and you know how to fix it up, please tell me.

PHP:
if(isset($_POST['login']))
        {
            $template->form->setData();
            unset($template->form->error);
         
            if($this->nameTaken($template->form->log_username))
            {
                if($this->isBanned($template->form->log_username) == false || $this->isBanned($_SERVER['REMOTE_ADDR']) == false)
                {
                    if($this->userValidation($template->form->log_username || $template->form->log_email, $core->hashed($template->form->log_password)))
                    {
                        $this->turnOn($template->form->log_username || $template->form->log_email);
                        $this->updateUser($_SESSION['user']['id'], 'ip_last', $_SERVER['REMOTE_ADDR']);
                        $template->form->unsetData();
                        header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
                        exit;
                    }
                    else
                    {
                        $template->form->error = 'Details do not match';
                        return;
                    }
                }
                else
                {
                    $template->form->error = 'Sorry, it appears this user is banned<br />';
                    $template->form->error .= 'Reason: ' . $this->getReason($template->form->log_username);
                    return;
                }
            }
            else
            {
                $template->form->error = 'Username does not exist';
                return;
            }
        }
    }

And what would you need to edit for it to work in the form, it's currently this.
HTML:
<form method="post" action="index">
Email:<br />
<input type="text" class="txt" style="width: 40%;" name="log_username" value="" /><br />
<br />
Password:<br />
<input type="password" class="txt" style="width: 40%;" name="log_password" value="" /><br />
<br />
<input type="submit" name="login" class="buttonize green" value="Login" />
</form>

Sorry if I'm off by a long shot, I'm not that familiar with PHP.
Thanks,
Hitler.
 

Users who are viewing this thread

Top