From 806dde3c7931d1a0d13c4f0469013a79e6198dcc Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 25 Mar 2016 09:59:24 -0700 Subject: [PATCH] Added an option to change admin login, name, and email. --- WEB-INF/lib/auth/Auth_ldap.class.php | 30 ++++++------------ WEB-INF/templates/admin_options.tpl | 18 +++++++++++ WEB-INF/templates/footer.tpl | 2 +- admin_options.php | 46 ++++++++++++++++++++++------ 4 files changed, 66 insertions(+), 30 deletions(-) diff --git a/WEB-INF/lib/auth/Auth_ldap.class.php b/WEB-INF/lib/auth/Auth_ldap.class.php index 93fdebf4..25d375bc 100644 --- a/WEB-INF/lib/auth/Auth_ldap.class.php +++ b/WEB-INF/lib/auth/Auth_ldap.class.php @@ -97,16 +97,16 @@ class Auth_ldap extends Auth { } if (!$lc) return false; - + ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($lc, LDAP_OPT_REFERRALS, 0); if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { ldap_set_option($lc, LDAP_OPT_DEBUG_LEVEL, 7); } - + // We need to handle Windows AD and OpenLDAP differently. if ($this->params['type'] != 'openldap') { - + // check if the user specified full login if (strpos($login, '@') === false) { // append default domain @@ -119,7 +119,7 @@ class Auth_ldap extends Auth { } $lb = @ldap_bind($lc, $login, $password); - + if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { echo '$lb='; var_dump($lb); echo '
'; echo 'ldap_error()='; echo ldap_error($lc); echo '
'; @@ -130,7 +130,7 @@ class Auth_ldap extends Auth { return false; } - if ($member_of) { + if ($member_of) { // get groups $filter = 'samaccountname='.Auth_ldap::ldap_escape($login); @@ -185,21 +185,16 @@ class Auth_ldap extends Auth { ldap_unbind($lc); - // handle special case - admin account, strip domain part - if (strpos($login, 'admin@') !== false) { - $login = substr($login, 0, 5); - } - return array('login' => $login, 'data' => $entries, 'member_of' => $groups); } else { - + // Assuming OpenLDAP server. $login_oldap = 'uid='.$login.','.$this->params['base_dn']; if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { echo '$login_oldap='; var_dump($login_oldap); echo '
'; } - + // check if the user specified full login if (strpos($login, '@') === false) { // append default domain @@ -207,7 +202,7 @@ class Auth_ldap extends Auth { } $lb = @ldap_bind($lc, $login_oldap, $password); - + if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { echo '$lb='; var_dump($lb); echo '
'; echo 'ldap_error()='; echo ldap_error($lc); echo '
'; @@ -218,7 +213,7 @@ class Auth_ldap extends Auth { return false; } - if ($member_of) { + if ($member_of) { // get groups $filter = 'samaccountname='.Auth_ldap::ldap_escape($login_oldap); @@ -273,11 +268,6 @@ class Auth_ldap extends Auth { ldap_unbind($lc); - // handle special case - admin account, strip domain part - if (strpos($login, 'admin@') !== false) { - $login = substr($login, 0, 5); - } - return array('login' => $login, 'data' => $entries, 'member_of' => $groups); } } @@ -285,4 +275,4 @@ class Auth_ldap extends Auth { function isPasswordExternal() { return true; } -} \ No newline at end of file +} diff --git a/WEB-INF/templates/admin_options.tpl b/WEB-INF/templates/admin_options.tpl index b97312cc..2d8cb865 100644 --- a/WEB-INF/templates/admin_options.tpl +++ b/WEB-INF/templates/admin_options.tpl @@ -3,6 +3,15 @@ + + + + + + + + +{if !$auth_external} @@ -11,6 +20,15 @@ +{/if} + + + + + + + + diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index ad799bc2..d4174240 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
{$i18n.label.person_name} (*):{$forms.optionsForm.name.control}
{$i18n.label.login} (*):{$forms.optionsForm.login.control}
{$i18n.label.password}: {$forms.optionsForm.password1.control}{$i18n.label.confirm_password}: {$forms.optionsForm.password2.control}
{$i18n.label.email}:{$forms.optionsForm.email.control}
{$i18n.label.required_fields}
{$forms.optionsForm.btn_submit.control}
-
 Anuko Time Tracker 1.9.18.3440 | Copyright © Anuko | +  Anuko Time Tracker 1.9.19.3441 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/admin_options.php b/admin_options.php index 05fa4800..5431b22a 100644 --- a/admin_options.php +++ b/admin_options.php @@ -37,33 +37,61 @@ if (!ttAccessCheck(right_administer_site)) { } if ($request->isPost()) { - $cl_password1 = $request->getParameter('password1'); - $cl_password2 = $request->getParameter('password2'); + $cl_name = trim($request->getParameter('name')); + $cl_login = trim($request->getParameter('login')); + if (!$auth->isPasswordExternal()) { + $cl_password1 = $request->getParameter('password1'); + $cl_password2 = $request->getParameter('password2'); + } + $cl_email = trim($request->getParameter('email')); +} else { + $cl_name = $user->name; + $cl_login = $user->login; + $cl_email = $user->email; } $form = new Form('optionsForm'); -$form->addInput(array('type'=>'text','aspassword'=>true,'maxlength'=>'30','name'=>'password1','style'=>'width: 150px;','value'=>$cl_password1)); -$form->addInput(array('type'=>'text','aspassword'=>true,'maxlength'=>'30','name'=>'password2','style'=>"width: 150px;",'value'=>$cl_password2)); +$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','value'=>$cl_name)); +$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'login','value'=>$cl_login)); +if (!$auth->isPasswordExternal()) { + $form->addInput(array('type'=>'text','maxlength'=>'30','name'=>'password1','aspassword'=>true,'value'=>$cl_password1)); + $form->addInput(array('type'=>'text','maxlength'=>'30','name'=>'password2','aspassword'=>true,'value'=>$cl_password2)); +} +$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','value'=>$cl_email)); $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.submit'))); if ($request->isPost()) { - if ($cl_password1 || $cl_password2) { - // Validate user input. + // Validate user input. + if (!ttValidString($cl_name)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.person_name')); + if (!ttValidString($cl_login)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.login')); + // New login must be unique. + if ($cl_login != $user->login && ttUserHelper::getUserByLogin($cl_login)) + $err->add($i18n->getKey('error.user_exists')); + if (!$auth->isPasswordExternal() && ($cl_password1 || $cl_password2)) { if (!ttValidString($cl_password1)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.password')); if (!ttValidString($cl_password2)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password')); if ($cl_password1 !== $cl_password2) $err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password')); } + if (!ttValidEmail($cl_email, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.email')); + // Finished validating user input. - if ($err->no() && $cl_password1) { - if (ttUserHelper::setPassword($user->id, $cl_password1)) { + if ($err->no()) { + if (ttUserHelper::update($user->id, array( + 'name' => $cl_name, + 'login' => $cl_login, + 'password' => $cl_password1, + 'email' => $cl_email, + 'status' => ACTIVE))) { header('Location: admin_teams.php'); exit(); - } else + } else { $err->add($i18n->getKey('error.db')); + } } } // isPost +$smarty->assign('auth_external', $auth->isPasswordExternal()); $smarty->assign('forms', array($form->getName()=>$form->toArray())); $smarty->assign('title', $i18n->getKey('title.options')); $smarty->assign('content_page_name', 'admin_options.tpl'); -- 2.20.1