index.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Copyright (c) 2010 Frank Karlitschek karlitschek@kde.org
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. $RUNTIME_NOAPPS = TRUE; //no apps
  9. require_once('../../lib/base.php');
  10. // Someone lost their password:
  11. if (isset($_POST['user'])) {
  12. if (OC_User::userExists($_POST['user'])) {
  13. $token = sha1($_POST['user'].md5(uniqid(rand(), true)));
  14. OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', $token);
  15. $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
  16. if (!empty($email) and isset($_POST['sectoken']) and isset($_SESSION['sectoken']) and ($_POST['sectoken']==$_SESSION['sectoken']) ) {
  17. $link = OC_Helper::linkToAbsolute('core/lostpassword', 'resetpassword.php').'?user='.$_POST['user'].'&token='.$token;
  18. $tmpl = new OC_Template('core/lostpassword', 'email');
  19. $tmpl->assign('link', $link);
  20. $msg = $tmpl->fetchPage();
  21. $l = OC_L10N::get('core');
  22. $from = 'lostpassword-noreply@' . $_SERVER['HTTP_HOST'];
  23. $r=mail($email, $l->t('Owncloud password reset'), $msg, 'From:' . $from);
  24. OC_MAIL::send($email,$_POST['user'],$l->t('ownCloud password reset'),$msg,$from,'ownCloud');
  25. echo('sent');
  26. }
  27. $sectoken=rand(1000000,9999999);
  28. $_SESSION['sectoken']=$sectoken;
  29. OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => true, 'sectoken' => $sectoken));
  30. } else {
  31. $sectoken=rand(1000000,9999999);
  32. $_SESSION['sectoken']=$sectoken;
  33. OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => true, 'requested' => false, 'sectoken' => $sectoken));
  34. }
  35. } else {
  36. $sectoken=rand(1000000,9999999);
  37. $_SESSION['sectoken']=$sectoken;
  38. OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => false, 'sectoken' => $sectoken));
  39. }