2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 require_once('initialize.php');
32 import('ttUserHelper');
34 if ($auth->isPasswordExternal()) {
35 header('Location: login.php');
39 $form = new Form('resetPasswordForm');
40 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'login','style'=>'width: 300px;'));
41 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.reset_password')));
43 if ($request->isPost()) {
44 $cl_login = $request->getParameter('login');
46 // Validate user input.
47 if (!ttValidString($cl_login)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.login'));
49 if ($err->IsEmpty()) {
50 if (!ttUserHelper::getUserByLogin($cl_login)) {
51 // User with a specified login was not found.
52 // In this case, if login looks like email, try finding user by email.
53 if (ttValidEmail($cl_login)) {
54 $login = ttUserHelper::getUserByEmail($cl_login);
58 $err->add($i18n->getKey('error.no_login'));
60 $err->add($i18n->getKey('error.no_login'));
64 if ($err->IsEmpty()) {
65 $user = new ttUser($cl_login); // Note: reusing $user from initialize.php here.
67 // Prepare and save a temporary reference for user.
68 $temp_ref = md5(uniqid());
69 ttUserHelper::saveTmpRef($temp_ref, $user->id);
72 if ($user->lang != $i18n->lang) {
73 $user_i18n = new I18n();
74 $user_i18n->load($user->lang);
78 // Where do we email to?
81 $receiver = $user->email;
83 if (ttValidEmail($cl_login))
84 $receiver = $cl_login;
86 $err->add($i18n->getKey('error.no_email'));
90 import('mail.Mailer');
91 $sender = new Mailer();
92 $sender->setCharSet(CHARSET);
93 $sender->setSender(SENDER);
94 $sender->setReceiver("$receiver");
95 if ((!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] !== 'off')) || ($_SERVER['SERVER_PORT'] == 443))
96 $secure_connection = true;
97 if($secure_connection)
102 $cl_subject = $user_i18n->getKey('form.reset_password.email_subject');
104 $pass_edit_url = $http.'://'.$_SERVER['HTTP_HOST'].'/'.APP_NAME.'/password_change.php?ref='.$temp_ref;
106 $pass_edit_url = $http.'://'.$_SERVER['HTTP_HOST'].'/password_change.php?ref='.$temp_ref;
108 $sender->setSendType(MAIL_MODE);
109 $res = $sender->send($cl_subject, sprintf($user_i18n->getKey('form.reset_password.email_body'), $pass_edit_url));
110 $smarty->assign('result_message', $res ? $i18n->getKey('form.reset_password.message') : $i18n->getKey('error.mail_send'));
115 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
116 $smarty->assign('onload', 'onLoad="document.resetPasswordForm.login.focus()"');
117 $smarty->assign('title', $i18n->getKey('title.reset_password'));
118 $smarty->assign('content_page_name', 'password_reset.tpl');
119 $smarty->display('index.tpl');