remember login added

This commit is contained in:
Bartek Przybylski 2011-07-20 15:04:14 +02:00
parent 6230001a3c
commit c5776fdae4
4 changed files with 35 additions and 4 deletions

View File

@ -107,7 +107,10 @@ div.controls { width:91%; margin:1em 1em 1em 2em; padding:0.5em 0; background-co
background-color: #666;
color: #FFF;
}
#login_form input[type="checkbox"]
{
width:15px;
}
#setup_form {
margin: 3em auto;

View File

@ -5,8 +5,15 @@
<?php if($_['error']): ?>
<?php echo $l->t( 'Login failed!' ); ?>
<?php endif; ?>
<?php if(empty($_["username"])){?>
<input type="text" name="user" id="user" value="" autofocus />
<input type="checkbox" name="remember_login"/> <?php echo $l->t('Remember login'); ?>
<input type="password" name="password" id="password" value="" />
<?php }else{ ?>
<input type="text" name="user" id="user" value="<?php echo $_['username']; ?>">
<input type="checkbox" name="remember_login" checked /> <?php echo $l->t('Remember login'); ?>
<input type="password" name="password" id="password" value="" autofocus />
<?php } ?>
<input type="submit" value="Log in" />
</fieldset>
</form>

View File

@ -31,7 +31,6 @@ OC_UTIL::addScript('setup');
$not_installed = !OC_CONFIG::getValue('installed', false);
$install_called = (isset($_POST['install']) AND $_POST['install']=='true');
// First step : check if the server is correctly configured for ownCloud :
$errors = OC_UTIL::checkServer();
if(count($errors) > 0) {
@ -61,17 +60,23 @@ elseif(isset($_POST["user"])) {
OC_APP::loadApps();
if(OC_USER::login($_POST["user"], $_POST["password"])) {
header("Location: ".$WEBROOT.'/'.OC_APPCONFIG::getValue("core", "defaultpage", "files/index.php"));
if(!empty($_POST["remember_login"])){
OC_USER::setUsernameInCookie($_POST["user"]);
}
else {
OC_USER::unsetUsernameInCookie();
}
exit();
}
else {
OC_TEMPLATE::printGuestPage("", "login", array("error" => true));
OC_TEMPLATE::printGuestPage("", "login", array("error" => true, "username" => $_COOKIE["username"]));
}
}
// For all others cases, we display the guest page :
else {
OC_APP::loadApps();
OC_TEMPLATE::printGuestPage("", "login", array("error" => false));
OC_TEMPLATE::printGuestPage("", "login", array("error" => false, "username" => $_COOKIE["username"]));
}
?>

View File

@ -337,4 +337,20 @@ class OC_USER {
}
return false;
}
/**
* @brief Set cookie value to use in next page load
* @param string $username username to be set
*/
public static function setUsernameInCookie($username){
setcookie("username", $username, mktime().time()+60*60*24*15);
}
/**
* @brief Remove cookie for "remember username"
*/
public static function unsetUsernameInCookie(){
unset($_COOKIE["username"]);
setcookie("username", NULL, -1);
}
}