|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sxbxstxxn Smarty n00b
Joined: 21 Jul 2017 Posts: 1
|
Posted: Fri Jul 21, 2017 9:14 am Post subject: Login/Logout im Template nur nach Page-Reload sichtbar |
|
|
Hallo,
ich bin neu bei SMARTY und probiere daher etwas rum. 1. Versuch ist ein Login Formular im Header. Sowohl login, als auch logout funktionieren zwar, aber das Ergebnis im header bzw Formular selbst ist erst nach einem reload der Seite zu sehen.
Header.tpl
Code: |
{if isset($user) }
<form class="logoutform col-md-12 nopadding" method="post">
<div class="col-md-10"><p class="welcometext">Hello {$user.username}!</p></div>
<div class="hidden"><input type="hidden" name="action" value="logout"></div>
<div class="col-md-2"><button type="submit">Logout</button></div>
</form>
{else}
<form class="loginform col-md-12 nopadding" method="post">
<div class="col-md-5"><input type="text" placeholder="Username" name="username"></div>
<div class="col-md-5"><input type="password" placeholder="Password" name="password"></div>
<div class="hidden">
<input type="hidden" name="action" value="login">
</div>
<div class="col-md-2"><button type="submit">Login</button></div>
</form>
{/if}
|
function login & logout in der page.class.php
Code: |
function logout()
{
session_destroy();
//header('Location: '.BASEURL);
}
function login($username, $password)
{
$pdo = new PDO('mysql:host='.HOST.';dbname='.DATABASE, USER, PASSWORD);
$statement = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$result = $statement->execute(array('username' => $username));
$user = $statement->fetch(PDO::FETCH_ASSOC);
//DB Abfrage in user class exportieren? checkUserLogin, dann return true oder errormeldung
if ($user == false || password_verify($password, $user['password']) == false) {
$loginerror = 'username or password wrong';
}
else {
if ($user['email_confirmed']==0) {
//$this->assign('error', 'Please confirm your e-mail adress.');
$loginerror = 'please confirm your e-mail adress.';
}
else {
//$_SESSION['loggedUser'] = $user['id'];
$_SESSION['user'] = $user;
return true;
}
}
$this->assign('loginerror', $loginerror);
}
}
|
Jemand eine Idee wo ich einen Knoten im Kopf habe, dass das nicht funktioniert? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jul 21, 2017 10:31 am Post subject: |
|
|
The problem is exactly what you said is the problem.
You must redirect (in the end - refresh) the page for the session to return to you.
And also to prevent repetitive form submissions. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|