diff options
-rw-r--r-- | core/templates/login.php | 14 | ||||
-rw-r--r-- | index.php | 67 |
2 files changed, 37 insertions, 44 deletions
diff --git a/core/templates/login.php b/core/templates/login.php index 6564847014b..f4ee44be4ed 100644 --- a/core/templates/login.php +++ b/core/templates/login.php @@ -1,17 +1,11 @@ <form action="index.php" method="post"> <fieldset> <?php if($_['error']): ?> - <a href="index.php?lostpassword"><?php echo $l->t('Lost your password?'); ?></a> - <?php endif; ?> - <?php if(empty($_['username'])): ?> - <input type="text" name="user" id="user" placeholder="<?php echo $l->t( 'Username' ); ?>" value="<?php echo !empty($_POST['user'])?$_POST['user'].'"':'" autofocus'; ?> autocomplete="off" required /> - <input type="password" name="password" id="password" placeholder="<?php echo $l->t( 'Password' ); ?>" value="" required <?php echo !empty($_POST['user'])?'autofocus':''; ?> /> - <input type="checkbox" name="remember_login" value="1" id="remember_login" /><label for="remember_login"><?php echo $l->t('remember'); ?></label> - <?php else: ?> - <input type="text" name="user" id="user" placeholder="<?php echo $l->t( 'Username' ); ?>" value="<?php echo $_['username']; ?>" autocomplete="off" required > - <input type="password" name="password" id="password" placeholder="<?php echo $l->t( 'Password' ); ?>" value="" required autofocus /> - <input type="checkbox" name="remember_login" value="1" id="remember_login" checked /><label for="remember_login"><?php echo $l->t('remember'); ?></label> + <a href="./lostpassword/"><?php echo $l->t('Lost your password?'); ?></a> <?php endif; ?> + <input type="text" name="user" id="user" placeholder="<?php echo $l->t( 'Username' ); ?>" value="<?php echo !empty($_POST['user'])?$_POST['user'].'"':'" autofocus'; ?> autocomplete="off" required /> + <input type="password" name="password" id="password" placeholder="<?php echo $l->t( 'Password' ); ?>" value="" required <?php echo !empty($_POST['user'])?'autofocus':''; ?> /> + <input type="checkbox" name="remember_login" value="1" id="remember_login" /><label for="remember_login"><?php echo $l->t('remember'); ?></label> <input type="submit" id="submit" class="login" value="<?php echo $l->t( 'Log in' ); ?>" /> </fieldset> </form> diff --git a/index.php b/index.php index 17429b97476..fb8d1922dd4 100644 --- a/index.php +++ b/index.php @@ -52,44 +52,43 @@ elseif(OC_User::isLoggedIn()) { } } -// remember was checked after last login -elseif(isset($_COOKIE["oc_remember_login"]) && isset($_COOKIE["oc_token"]) && isset($_COOKIE["oc_username"]) && $_COOKIE["oc_remember_login"]) { +// For all others cases, we display the guest page : +else { OC_App::loadApps(); - if(defined("DEBUG") && DEBUG) {error_log("Trying to login from cookie");} - // confirm credentials in cookie - if(isset($_COOKIE['oc_token']) && OC_User::userExists($_COOKIE['oc_username']) && - OC_Preferences::getValue($_COOKIE['oc_username'], "login", "token") == $_COOKIE['oc_token']) { - OC_User::setUserId($_COOKIE['oc_username']); - OC_Util::redirectToDefaultPage(); - } - else { - OC_Util::displayLoginPage(array('error' => true)); - } -} + $error = false; -// Someone wants to log in : -elseif(isset($_POST["user"]) && isset($_POST['password'])) { - OC_App::loadApps(); - if(OC_User::login($_POST["user"], $_POST["password"])) { - if(!empty($_POST["remember_login"])){ - if(defined("DEBUG") && DEBUG) {error_log("Setting remember login to cookie");} - $token = md5($_POST["user"].time()); - OC_Preferences::setValue($_POST['user'], 'login', 'token', $token); - OC_User::setMagicInCookie($_POST["user"], $token); + // remember was checked after last login + if(isset($_COOKIE["oc_remember_login"]) && isset($_COOKIE["oc_token"]) && isset($_COOKIE["oc_username"]) && $_COOKIE["oc_remember_login"]) { + if(defined("DEBUG") && DEBUG) { + error_log("Trying to login from cookie"); } - else { - OC_User::unsetMagicInCookie(); + // confirm credentials in cookie + if(isset($_COOKIE['oc_token']) && OC_User::userExists($_COOKIE['oc_username']) && + OC_Preferences::getValue($_COOKIE['oc_username'], "login", "token") == $_COOKIE['oc_token']) { + OC_User::setUserId($_COOKIE['oc_username']); + OC_Util::redirectToDefaultPage(); + } + } + + // Someone wants to log in : + elseif(isset($_POST["user"]) && isset($_POST['password'])) { + if(OC_User::login($_POST["user"], $_POST["password"])) { + if(!empty($_POST["remember_login"])){ + if(defined("DEBUG") && DEBUG) { + error_log("Setting remember login to cookie"); + } + $token = md5($_POST["user"].time()); + OC_Preferences::setValue($_POST['user'], 'login', 'token', $token); + OC_User::setMagicInCookie($_POST["user"], $token); + } + else { + OC_User::unsetMagicInCookie(); + } + OC_Util::redirectToDefaultPage(); + } else { + $error = true; } - OC_Util::redirectToDefaultPage(); - } else { - OC_Util::displayLoginPage(array('error' => true)); } -} -// For all others cases, we display the guest page : -else { - OC_App::loadApps(); - OC_Util::displayLoginPage(array('error' => false)); + OC_Template::printGuestPage('', 'login', array('error' => $error )); } - -?> |