summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2011-09-30 23:48:20 +0200
committerBart Visscher <bartv@thisnet.nl>2011-09-30 23:48:20 +0200
commit21a88613a150c550e32d63df9a9ef8bf3d5107d0 (patch)
tree45e76fbae9349265489dbebe5aef090f45e49a85
parentddd28aae67d7e67b7e39c1fe58fe52659d1dd755 (diff)
parent5fbf378d1021da91977caa6c7df9944c353d4786 (diff)
downloadnextcloud-server-21a88613a150c550e32d63df9a9ef8bf3d5107d0.tar.gz
nextcloud-server-21a88613a150c550e32d63df9a9ef8bf3d5107d0.zip
Merge branch 'lostpassword'
Conflicts: core/templates/login.php index.php lib/util.php
-rw-r--r--core/templates/login.php4
-rw-r--r--index.php40
-rw-r--r--lib/util.php8
-rw-r--r--lostpassword/index.php32
-rw-r--r--lostpassword/resetpassword.php27
-rw-r--r--lostpassword/templates/email.php1
-rw-r--r--lostpassword/templates/lostpassword.php (renamed from core/templates/lostpassword.php)6
-rw-r--r--lostpassword/templates/resetpassword.php (renamed from core/templates/resetpassword.php)5
-rw-r--r--settings/ajax/lostpassword.php19
-rw-r--r--settings/js/personal.js9
-rw-r--r--settings/personal.php3
-rw-r--r--settings/templates/personal.php8
12 files changed, 119 insertions, 43 deletions
diff --git a/core/templates/login.php b/core/templates/login.php
index 641e0adb6e0..6564847014b 100644
--- a/core/templates/login.php
+++ b/core/templates/login.php
@@ -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':''; ?> />
diff --git a/index.php b/index.php
index 68754fcc567..17429b97476 100644
--- a/index.php
+++ b/index.php
@@ -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));
}
-?> \ No newline at end of file
+?>
diff --git a/lib/util.php b/lib/util.php
index 26d718da944..f21ec8208b4 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -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
diff --git a/lostpassword/index.php b/lostpassword/index.php
new file mode 100644
index 00000000000..6d629a71089
--- /dev/null
+++ b/lostpassword/index.php
@@ -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));
+}
diff --git a/lostpassword/resetpassword.php b/lostpassword/resetpassword.php
new file mode 100644
index 00000000000..1a6a74e5ff4
--- /dev/null
+++ b/lostpassword/resetpassword.php
@@ -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));
+}
diff --git a/lostpassword/templates/email.php b/lostpassword/templates/email.php
new file mode 100644
index 00000000000..d146d8e4c37
--- /dev/null
+++ b/lostpassword/templates/email.php
@@ -0,0 +1 @@
+<?php echo str_replace('{link}', $_['link'], $l->t('Use the following link to reset your password: {link}')) ?>
diff --git a/core/templates/lostpassword.php b/lostpassword/templates/lostpassword.php
index 67e34164d08..2c38a1562fe 100644
--- a/core/templates/lostpassword.php
+++ b/lostpassword/templates/lostpassword.php
@@ -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> \ No newline at end of file
+</form>
diff --git a/core/templates/resetpassword.php b/lostpassword/templates/resetpassword.php
index 2f43a93cfb5..3ab9dd6543c 100644
--- a/core/templates/resetpassword.php
+++ b/lostpassword/templates/resetpassword.php
@@ -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'); ?>" />
diff --git a/settings/ajax/lostpassword.php b/settings/ajax/lostpassword.php
new file mode 100644
index 00000000000..a2dfc033206
--- /dev/null
+++ b/settings/ajax/lostpassword.php
@@ -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") )));
+}
+
+?>
diff --git a/settings/js/personal.js b/settings/js/personal.js
index 9578fb2c890..8108da433c8 100644
--- a/settings/js/personal.js
+++ b/settings/js/personal.js
@@ -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(){
diff --git a/settings/personal.php b/settings/personal.php
index 05dbda473ac..687b1a7aa34 100644
--- a/settings/personal.php
+++ b/settings/personal.php
@@ -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');
diff --git a/settings/templates/personal.php b/settings/templates/personal.php
index 4406c080edc..3c4ad085165 100644
--- a/settings/templates/personal.php
+++ b/settings/templates/personal.php
@@ -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>