add login form to 403 error pages and add referrer param for user login
This commit is contained in:
parent
0450340469
commit
5e02062c26
5 changed files with 33 additions and 4 deletions
|
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action: index.
|
* Action: index.
|
||||||
*
|
*
|
||||||
|
|
@ -41,6 +43,7 @@
|
||||||
// Display statuscode and message
|
// Display statuscode and message
|
||||||
$this->set('code', $httpStatusCode);
|
$this->set('code', $httpStatusCode);
|
||||||
$this->set('string', \nre\core\WebUtils::$httpStrings[$httpStatusCode]);
|
$this->set('string', \nre\core\WebUtils::$httpStrings[$httpStatusCode]);
|
||||||
|
$this->set('userId', $this->Auth->getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,11 +117,13 @@
|
||||||
public function login()
|
public function login()
|
||||||
{
|
{
|
||||||
$username = '';
|
$username = '';
|
||||||
|
$referrer = null;
|
||||||
|
|
||||||
// Log the user in
|
// Log the user in
|
||||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('login')))
|
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('login')))
|
||||||
{
|
{
|
||||||
$username = $this->request->getPostParam('username');
|
$username = $this->request->getPostParam('username');
|
||||||
|
$referrer = $this->request->getPostParam('referrer');
|
||||||
$userId = $this->Users->login(
|
$userId = $this->Users->login(
|
||||||
$username,
|
$username,
|
||||||
$this->request->getPostParam('password')
|
$this->request->getPostParam('password')
|
||||||
|
|
@ -131,14 +133,20 @@
|
||||||
{
|
{
|
||||||
$this->Auth->setUserId($userId);
|
$this->Auth->setUserId($userId);
|
||||||
$user = $this->Users->getUserById($userId);
|
$user = $this->Users->getUserById($userId);
|
||||||
|
|
||||||
$this->redirect($this->linker->link(array($user['url']), 1));
|
if(!empty($referrer)) {
|
||||||
|
$this->redirect($referrer);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->redirect($this->linker->link(array($user['url']), 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Pass data to view
|
// Pass data to view
|
||||||
$this->set('username', $username);
|
$this->set('username', $username);
|
||||||
|
$this->set('referrer', $referrer);
|
||||||
$this->set('failed', ($this->request->getRequestMethod() == 'POST'));
|
$this->set('failed', ($this->request->getRequestMethod() == 'POST'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,17 @@
|
||||||
<h1><?=_('Error')?></h1>
|
<h1><?=_('Error')?></h1>
|
||||||
<p class="error"><?=$code?>: <?=$string?></p>
|
<p class="error"><?=$code?>: <?=$string?></p>
|
||||||
|
|
||||||
|
<?php if($code == 403 && $userId <= 0) : ?>
|
||||||
|
<h2><?=_('Login')?></h2>
|
||||||
|
<form method="post" action="<?=$linker->link(array('users','login'))?>" class="logreg">
|
||||||
|
<fieldset>
|
||||||
|
<label for="username"><?=_('Username')?>:</label>
|
||||||
|
<input name="username" type="text" placeholder="<?=_('Username')?>" title="<?=_('Username')?>" required="required" autofocus="autofocus" /><br />
|
||||||
|
<label for="password"><?=_('Password')?>:</label>
|
||||||
|
<input name="password" type="password" placeholder="<?=_('Password')?>" title="<?=_('Password')?>" required="required" /><br />
|
||||||
|
</fieldset>
|
||||||
|
<input type="hidden" name="referrer" value="<?=$linker->link(null, null, false)?>" />
|
||||||
|
<input type="submit" name="login" class="cta" value="<?=_('Login')?>" />
|
||||||
|
<?=_('or')?> <a href="<?=$linker->link(array('users','register'))?>"><?=_('register yourself')?></a>
|
||||||
|
</form>
|
||||||
|
<?php endif ?>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<form method="post" action="<?=$linker->link(array('users','login'))?>" class="logreg">
|
<form method="post" action="<?=$linker->link(array('users','login'))?>" class="logreg">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="username"><?=_('Username')?>:</label>
|
<label for="username"><?=_('Username')?>:</label>
|
||||||
<input name="username" type="text" placeholder="<?=_('Username')?>" title="<?=_('Username')?>" required="required" /><br />
|
<input name="username" type="text" placeholder="<?=_('Username')?>" title="<?=_('Username')?>" required="required" autofocus="autofocus" /><br />
|
||||||
<label for="password"><?=_('Password')?>:</label>
|
<label for="password"><?=_('Password')?>:</label>
|
||||||
<input name="password" type="password" placeholder="<?=_('Password')?>" title="<?=_('Password')?>" required="required" /><br />
|
<input name="password" type="password" placeholder="<?=_('Password')?>" title="<?=_('Password')?>" required="required" /><br />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,12 @@
|
||||||
<form method="post" action="<?=$linker->link(array(), 2)?>" class="logreg">
|
<form method="post" action="<?=$linker->link(array(), 2)?>" class="logreg">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="username"><?=_('Username')?>:</label>
|
<label for="username"><?=_('Username')?>:</label>
|
||||||
<input name="username" type="text" placeholder="<?=_('Username')?>" value="<?=$username?>" required="required" /><br />
|
<input name="username" type="text" placeholder="<?=_('Username')?>" value="<?=$username?>" required="required" autofocus="autofocus" /><br />
|
||||||
<label for="password"><?=_('Password')?>:</label>
|
<label for="password"><?=_('Password')?>:</label>
|
||||||
<input name="password" type="password" placeholder="<?=_('Password')?>" required="required" /><br />
|
<input name="password" type="password" placeholder="<?=_('Password')?>" required="required" /><br />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
<?php if(!empty($referrer)) : ?>
|
||||||
|
<input type="hidden" name="referrer" value="<?=$referrer?>" />
|
||||||
|
<?php endif ?>
|
||||||
<input type="submit" name="login" value="<?=_('Login')?>" />
|
<input type="submit" name="login" value="<?=_('Login')?>" />
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue