Merge branch 'lostpassword'

Conflicts:
	core/templates/login.php
	index.php
	lib/util.php
This commit is contained in:
Bart Visscher 2011-09-30 23:48:20 +02:00
commit 21a88613a1
12 changed files with 119 additions and 43 deletions

View File

@ -1,8 +1,8 @@
<form action="index.php" method="post">
<fieldset>
<?php /*if($_['error']): ?>
<?php if($_['error']): ?>
<a href="index.php?lostpassword"><?php echo $l->t('Lost your password?'); ?></a>
<?php endif;*/ ?>
<?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':''; ?> />

View File

@ -63,7 +63,7 @@ elseif(isset($_COOKIE["oc_remember_login"]) && isset($_COOKIE["oc_token"]) && is
OC_Util::redirectToDefaultPage();
}
else {
OC_Template::printGuestPage("", "login", array("error" => true, 'username' => isset($_COOKIE['oc_username'])?$_COOKIE['oc_username']:'' ));
OC_Util::displayLoginPage(array('error' => true));
}
}
@ -82,46 +82,14 @@ elseif(isset($_POST["user"]) && isset($_POST['password'])) {
}
OC_Util::redirectToDefaultPage();
} else {
OC_Template::printGuestPage('', 'login', array('error' => true, 'username' => isset($_COOKIE['oc_username'])?$_COOKIE['oc_username']:'' ));
}
}
// Someone lost their password:
elseif(isset($_GET['lostpassword'])) {
OC_App::loadApps();
if (isset($_POST['user'])) {
if (OC_User::userExists($_POST['user'])) {
$token = sha1($_POST['user']+uniqId());
OC_Preferences::setValue($_POST['user'], "owncloud", "lostpassword", $token);
// TODO send email with link+token
OC_Template::printGuestPage("", "lostpassword", array("error" => false, "requested" => true));
} else {
OC_Template::printGuestPage("", "lostpassword", array("error" => true, "requested" => false));
}
} else {
OC_Template::printGuestPage("", "lostpassword", array("error" => false, "requested" => false));
}
}
// Someone wants to reset their password:
elseif(isset($_GET['resetpassword']) && isset($_GET['token']) && isset($_GET['user']) && OC_Preferences::getValue($_GET['user'], "owncloud", "lostpassword") === $_GET['token']) {
OC_App::loadApps();
if (isset($_POST['password'])) {
if (OC_User::setPassword($_GET['user'], $_POST['password'])) {
OC_Preferences::deleteKey($_GET['user'], "owncloud", "lostpassword");
OC_Template::printGuestPage("", "resetpassword", array("success" => true));
} else {
OC_Template::printGuestPage("", "resetpassword", array("success" => false));
}
} else {
OC_Template::printGuestPage("", "resetpassword", array("success" => false));
OC_Util::displayLoginPage(array('error' => true));
}
}
// For all others cases, we display the guest page :
else {
OC_App::loadApps();
OC_Template::printGuestPage('', 'login', array('error' => false, 'username' => isset($_COOKIE['oc_username'])?$_COOKIE['oc_username']:'' ));
OC_Util::displayLoginPage(array('error' => false));
}
?>
?>

View File

@ -258,6 +258,14 @@ class OC_Util {
return $errors;
}
public static function displayLoginPage($parameters = array()){
if(isset($_COOKIE["username"])){
$parameters["username"] = $_COOKIE["username"];
} else {
$parameters["username"] = '';
}
OC_Template::printGuestPage("", "login", $parameters);
}
/**
* Try to get the username the httpd server runs on, used in hints

32
lostpassword/index.php Normal file
View File

@ -0,0 +1,32 @@
<?php
/**
* Copyright (c) 2010 Frank Karlitschek karlitschek@kde.org
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
$RUNTIME_NOAPPS = TRUE; //no apps
require_once('../lib/base.php');
// Someone lost their password:
if (isset($_POST['user'])) {
if (OC_User::userExists($_POST['user'])) {
$token = sha1($_POST['user']+uniqId());
OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', $token);
$email = OC_Preferences::getValue($_POST['user'], 'lostpassword', 'email', '');
if (!empty($email)) {
$link = OC_Helper::linkTo('lostpassword', 'resetpassword.php', null, true).'?user='.$_POST['user'].'&token='.$token;
$tmpl = new OC_Template('lostpassword', 'email');
$tmpl->assign('link', $link);
$msg = $tmpl->fetchPage();
$l = new OC_L10N('core');
mail($email, $l->t('Owncloud password reset'), $msg);
}
OC_Template::printGuestPage('lostpassword', 'lostpassword', array('error' => false, 'requested' => true));
} else {
OC_Template::printGuestPage('lostpassword', 'lostpassword', array('error' => true, 'requested' => false));
}
} else {
OC_Template::printGuestPage('lostpassword', 'lostpassword', array('error' => false, 'requested' => false));
}

View File

@ -0,0 +1,27 @@
<?php
/**
* Copyright (c) 2010 Frank Karlitschek karlitschek@kde.org
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
$RUNTIME_NOAPPS = TRUE; //no apps
require_once('../lib/base.php');
// Someone wants to reset their password:
if(isset($_GET['token']) && isset($_GET['user']) && OC_Preferences::getValue($_GET['user'], 'owncloud', 'lostpassword') === $_GET['token']) {
if (isset($_POST['password'])) {
if (OC_User::setPassword($_GET['user'], $_POST['password'])) {
OC_Preferences::deleteKey($_GET['user'], 'owncloud', 'lostpassword');
OC_Template::printGuestPage('lostpassword', 'resetpassword', array('success' => true));
} else {
OC_Template::printGuestPage('lostpassword', 'resetpassword', array('success' => false));
}
} else {
OC_Template::printGuestPage('lostpassword', 'resetpassword', array('success' => false));
}
} else {
// Someone lost their password
OC_Template::printGuestPage('lostpassword', 'lostpassword', array('error' => false, 'requested' => false));
}

View File

@ -0,0 +1 @@
<?php echo str_replace('{link}', $_['link'], $l->t('Use the following link to reset your password: {link}')) ?>

View File

@ -1,4 +1,4 @@
<form action="index.php?lostpassword" method="post">
<form action="index.php" method="post">
<fieldset>
<?php echo $l->t('You will receive a link to reset your password via Email.'); ?>
<?php if ($_['requested']): ?>
@ -7,8 +7,8 @@
<?php if ($_['error']): ?>
<?php echo $l->t('Login failed!'); ?>
<?php endif; ?>
<input type="text" name="user" id="user" placeholder="<?php echo $l->t('Username or Email'); ?>" value="" autocomplete="off" required autofocus />
<input type="text" name="user" id="user" placeholder="<?php echo $l->t('Username'); ?>" value="" autocomplete="off" required autofocus />
<input type="submit" id="submit" value="<?php echo $l->t('Request reset'); ?>" />
<?php endif; ?>
</fieldset>
</form>
</form>

View File

@ -1,7 +1,8 @@
<form action="<?php echo 'index.php?'.$_SERVER['QUERY_STRING']; ?>" method="post">
<form action="<?php echo 'resetpassword.php?'.$_SERVER['QUERY_STRING']; ?>" method="post">
<fieldset>
<?php if($_['success']): ?>
<?php echo $l->t('Your password was reset'); ?>
<h1><?php echo $l->t('Your password was reset'); ?></h1>
<p><a href="<?php echo OC::$WEBROOT ?>/"><?php echo $l->t('To login page'); ?></a></p>
<?php else: ?>
<input type="password" name="password" id="password" placeholder="<?php echo $l->t('New password'); ?>" value="" required />
<input type="submit" id="submit" value="<?php echo $l->t('Reset password'); ?>" />

View File

@ -0,0 +1,19 @@
<?php
// Init owncloud
require_once('../../lib/base.php');
OC_JSON::checkLoggedIn();
$l=new OC_L10N('core');
// Get data
if( isset( $_POST['email'] ) ){
$email=trim($_POST['email']);
OC_Preferences::setValue(OC_User::getUser(),'settings','email',$email);
OC_JSON::success(array("data" => array( "message" => $l->t("email Changed") )));
}else{
OC_JSON::error(array("data" => array( "message" => $l->t("Invalid request") )));
}
?>

View File

@ -32,6 +32,15 @@ $(document).ready(function(){
});
$('#lostpassword #email').blur(function(event){
event.preventDefault();
OC.msg.startSaving('#lostpassword .msg');
var post = $( "#lostpassword" ).serialize();
$.post( 'ajax/lostpassword.php', post, function(data){
OC.msg.finishedSaving('#lostpassword .msg', data);
});
});
$("#languageinput").chosen();
$("#languageinput").change( function(){

View File

@ -19,6 +19,8 @@ $free=OC_Filesystem::free_space();
$total=$free+$used;
$relative=round(($used/$total)*10000)/100;
$email=OC_Preferences::getValue(OC_User::getUser(), 'settings','email','');
$lang=OC_Preferences::getValue( OC_User::getUser(), 'core', 'lang', 'en' );
$languageCodes=OC_L10N::findAvailableLanguages();
//put the current language in the front
@ -35,6 +37,7 @@ $tmpl = new OC_Template( "settings", "personal", "user");
$tmpl->assign('usage',OC_Helper::humanFileSize($used));
$tmpl->assign('total_space',OC_Helper::humanFileSize($total));
$tmpl->assign('usage_relative',$relative);
$tmpl->assign('email',$email);
$tmpl->assign('languages',$languages);
$forms=OC_App::getForms('personal');

View File

@ -19,6 +19,14 @@
</fieldset>
</form>
<form id="lostpassword">
<fieldset class="personalblock">
<label for="email"><strong><?php echo $l->t('Email');?></strong></label>
<input type="text" name="email" id="email" value="<?php echo $_['email']; ?>" placeholder="<?php echo $l->t('Your email address');?>" /><span class="msg"></span><br />
<em><?php echo $l->t('Fill in an email address to enable password recovery');?></em>
</fieldset>
</form>
<form>
<fieldset class="personalblock">
<label for="languageinput"><strong><?php echo $l->t('Language');?></strong></label>