]> source.dussan.org Git - nextcloud-server.git/commitdiff
Move lostpassword code to own app
authorBart Visscher <bartv@thisnet.nl>
Sun, 25 Sep 2011 21:33:22 +0000 (23:33 +0200)
committerBart Visscher <bartv@thisnet.nl>
Mon, 26 Sep 2011 19:17:26 +0000 (21:17 +0200)
core/templates/login.php
core/templates/lostpassword.php [deleted file]
core/templates/resetpassword.php [deleted file]
index.php
lostpassword/index.php [new file with mode: 0644]
lostpassword/resetpassword.php [new file with mode: 0644]
lostpassword/templates/lostpassword.php [new file with mode: 0644]
lostpassword/templates/resetpassword.php [new file with mode: 0644]

index 717f6bcabdaf8cb7b42ffc8e1fe3b5668e0bdc1b..c8a86d71a910a347c8ba1166a875a0e71170598c 100644 (file)
@@ -1,7 +1,7 @@
 <form action="index.php" method="post">
        <fieldset>
                <?php if($_['error']): ?>
-                       <a href="index.php?lostpassword"><?php echo $l->t('Lost your password?'); ?></a>
+                       <a href="lostpassword/index.php"><?php echo $l->t('Lost your password?'); ?></a>
                <?php endif; ?>
                <?php if(empty($_["username"])): ?>
                        <input type="text" name="user" id="user" placeholder="Username" value="" autocomplete="off" required autofocus />
diff --git a/core/templates/lostpassword.php b/core/templates/lostpassword.php
deleted file mode 100644 (file)
index 67e3416..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<form action="index.php?lostpassword" method="post">
-       <fieldset>
-               <?php echo $l->t('You will receive a link to reset your password via Email.'); ?>
-               <?php if ($_['requested']): ?>
-                       <?php echo $l->t('Requested'); ?>
-               <?php else: ?>
-                       <?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="submit" id="submit" value="<?php echo $l->t('Request reset'); ?>" />
-               <?php endif; ?>
-       </fieldset>
-</form>
\ No newline at end of file
diff --git a/core/templates/resetpassword.php b/core/templates/resetpassword.php
deleted file mode 100644 (file)
index 2f43a93..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<form action="<?php echo 'index.php?'.$_SERVER['QUERY_STRING']; ?>" method="post">
-       <fieldset>
-               <?php if($_['success']): ?>
-                       <?php echo $l->t('Your password was reset'); ?>
-               <?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'); ?>" />
-               <?php endif; ?>
-       </fieldset>
-</form>
index bb1e370d241d8f696e2d302a9366b9fb55c1a98a..0db8ad126ce7ae2755b24a3dc7c4088cf36a3e1f 100644 (file)
--- a/index.php
+++ b/index.php
@@ -87,38 +87,6 @@ elseif(isset($_POST["user"]) && isset($_POST['password'])) {
        }
 }
 
-// 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));
-       }
-}
-
 // For all others cases, we display the guest page :
 else {
        OC_App::loadApps();
diff --git a/lostpassword/index.php b/lostpassword/index.php
new file mode 100644 (file)
index 0000000..0c07834
--- /dev/null
@@ -0,0 +1,25 @@
+<?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);
+               // TODO send email with link+token
+               $link = OC_Helper::linkTo('lostpassword', 'resetpassword.php', null, true).'?user='.$_POST['user'].'&token='.$token;
+               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 (file)
index 0000000..1a6a74e
--- /dev/null
@@ -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/lostpassword.php b/lostpassword/templates/lostpassword.php
new file mode 100644 (file)
index 0000000..1c95e0b
--- /dev/null
@@ -0,0 +1,14 @@
+<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']): ?>
+                       <?php echo $l->t('Requested'); ?>
+               <?php else: ?>
+                       <?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="submit" id="submit" value="<?php echo $l->t('Request reset'); ?>" />
+               <?php endif; ?>
+       </fieldset>
+</form>
diff --git a/lostpassword/templates/resetpassword.php b/lostpassword/templates/resetpassword.php
new file mode 100644 (file)
index 0000000..888d98e
--- /dev/null
@@ -0,0 +1,10 @@
+<form action="<?php echo 'resetpassword.php?'.$_SERVER['QUERY_STRING']; ?>" method="post">
+       <fieldset>
+               <?php if($_['success']): ?>
+                       <?php echo $l->t('Your password was reset'); ?>
+               <?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'); ?>" />
+               <?php endif; ?>
+       </fieldset>
+</form>