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');
31 import('ttUserHelper');
36 $cl_ref = $request->getParameter('ref');
37 if (!$cl_ref || $auth->isPasswordExternal()) {
38 header('Location: login.php');
43 $user_id = ttUserHelper::getUserIdByTmpRef($cl_ref);
45 $user = new ttUser(null, $user_id); // Note: reusing $user from initialize.php.
46 // In case user language is different - reload $i18n.
47 if ($i18n->lang != $user->lang) {
48 $i18n->load($user->lang);
49 $smarty->assign('i18n', $i18n->keys);
51 if ($user->custom_logo) {
52 $smarty->assign('custom_logo', 'images/'.$user->team_id.'.png');
53 $smarty->assign('mobile_custom_logo', '../images/'.$user->team_id.'.png');
55 $smarty->assign('user', $user);
58 $cl_password1 = $request->getParameter('password1');
59 $cl_password2 = $request->getParameter('password2');
61 $form = new Form('newPasswordForm');
62 $form->addInput(array('type'=>'text','maxlength'=>'120','name'=>'password1','aspassword'=>true,'value'=>$cl_password1));
63 $form->addInput(array('type'=>'text','maxlength'=>'120','name'=>'password2','aspassword'=>true,'value'=>$cl_password2));
64 $form->addInput(array('type'=>'hidden','name'=>'ref','value'=>$cl_ref));
65 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->getKey('button.save')));
67 if ($request->isPost()) {
68 // Validate user input.
69 if (!ttValidString($cl_password1)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.password'));
70 if (!ttValidString($cl_password2)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password'));
71 if ($cl_password1 !== $cl_password2)
72 $err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password'));
75 // Use the "limit" plugin if we have one. Ignore include errors.
76 // The "limit" plugin is not required for normal operation of Time Tracker.
77 $cl_login = $user->login; // $cl_login is used in access_check.cpp.
78 @include('plugins/limit/access_check.php');
80 ttUserHelper::setPassword($user_id, $cl_password1);
82 if ($auth->doLogin($user->login, $cl_password1)) {
83 setcookie('tt_login', $user->login, time() + COOKIE_EXPIRE, '/');
84 // Redirect, depending on user role.
85 if ($user->isAdmin()) {
86 header('Location: admin_teams.php');
87 } elseif ($user->isClient()) {
88 header('Location: reports.php');
90 header('Location: time.php');
94 $err->add($i18n->getKey('error.auth'));
99 $smarty->assign('forms', array($form->getName() => $form->toArray()));
100 $smarty->assign('title', $i18n->getKey('title.change_password'));
101 $smarty->assign('content_page_name', 'password_change.tpl');
102 $smarty->display('index.tpl');