Created
September 13, 2013 00:57
-
-
Save jdart/6545755 to your computer and use it in GitHub Desktop.
Custom Login Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SpexLogin extends ProcessLogin | |
{ | |
public static function getModuleInfo() | |
{ | |
return array( | |
'title' => 'Spex Login', | |
'summary' => 'Frontend Login to ProcessWire', | |
'version' => 001, | |
); | |
} | |
protected function performSystemChecks() { } | |
public function ___execute() { | |
if ($this->user->isLoggedin()) { | |
if ($this->input->get->logout) { | |
$this->session->logout(); | |
$this->session->redirect($this->page->url); | |
} | |
return; | |
} | |
// if($this->input->get->forgot && $this->allowForgot) { | |
// $process = $this->modules->get("ProcessForgotPassword"); | |
// return $process->execute(); | |
// } | |
$this->buildLoginForm(); | |
if(isset($_POST['login_submit'])) $this->form->processInput($this->input->post); | |
if(!$this->nameField->value || !$this->passField->value) return $this->renderLoginForm(); | |
$name = $this->fuel('sanitizer')->username($this->nameField->value); | |
$pass = substr($this->passField->value, 0, 50); | |
if($this->fuel('session')->login($name, $pass)) { | |
$this->session->message($name . ' - ' . $this->_("Successful login")); | |
$this->session->remove('error'); | |
$this->afterLoginRedirect(); | |
} else { | |
$this->error($name . " - " . $this->_("Login failed")); | |
} | |
return $this->renderLoginForm(); | |
} | |
protected function ___renderLoginForm() { | |
if ($login_redirect = $this->input->get->redirect) { | |
$this->session->login_redirect = $login_redirect; | |
} | |
if(isset($_GET['login'])) { | |
$this->afterLoginRedirect(); | |
} else { | |
// note the space after 'Login ' is intentional to separate it from the Login button for translation purposes | |
$this->setFuel('processHeadline', $this->_('Login ')); // Headline for login form page | |
$this->passField->attr('value', ''); | |
$out = $this->form->render(); | |
// $links = ''; | |
// if($this->allowForgot) { | |
// $links .= "<div><span class='ui-icon ui-icon-locked'></span><a href='./?forgot=1'>" . $this->_("Forgot your password?") . "</a></div>"; // Forgot password link text | |
// } | |
// $home = $this->pages->get("/"); | |
// if($links) $out .= "<p>$links</p>"; | |
return $out; | |
} | |
} | |
protected function ___afterLoginRedirect() { | |
if ($login_redirect = $this->session->login_redirect) { | |
$this->session->login_redirect = null; | |
$login_redirect = $this->pages->get($login_redirect); | |
if ($login_redirect && $login_redirect->id) | |
$this->session->redirect($login_redirect->url); | |
} | |
$this->session->redirect('/'); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment