public function testAll() { if ($this->config === null) { $this->sendMessage('Ldap plugin for jauth is not tested because there isn\'t configuration.' . ' To test it, you should create and configure an auth_ldap.coord.ini.php file.'); return; } for ($i = 1; $i <= NB_USERS_LDAP; $i++) { $myUser = jAuth::createUserObject("testldap usr {$i}", "pass{$i}"); $this->assertTrue($myUser instanceof jAuthUserLDAP); jAuth::saveNewUser($myUser); $myUserLDAP = jAuth::getUser("testldap usr {$i}"); $user = "******"jAuthUserLDAP\">\n <string property=\"login\" value=\"testldap usr {$i}\" />\n <string property=\"email\" value=\"\" />\n <array property=\"cn\">array('testldap usr {$i}')</array>\n <array property=\"distinguishedName\">array('CN=testldap usr {$i},{$this->config['ldap']['searchBaseDN']}')</array>\n <array property=\"name\">array('testldap usr {$i}')</array>\n <string property=\"password\" value=\"\" />\n </object>\n "; $this->assertComplexIdenticalStr($myUserLDAP, $user); $myUser->email = "usr{$i}.testldap@domain.com"; jAuth::updateUser($myUser); $myUserLDAP = jAuth::getUser("testldap usr {$i}"); $user = "******"login\" value=\"testldap usr {$i}\" />\n <array property=\"email\">array('usr{$i}.testldap@domain.com')</array>\n <array property=\"cn\">array('testldap usr {$i}')</array>\n <array property=\"distinguishedName\">array('CN=testldap usr {$i},{$this->config['ldap']['searchBaseDN']}')</array>\n <array property=\"name\">array('testldap usr {$i}')</array>\n <string property=\"password\" value=\"\" />\n </object>\n "; $this->assertComplexIdenticalStr($myUserLDAP, $user); $this->assertTrue(jAuth::verifyPassword("testldap usr {$i}", "pass{$i}")); $this->assertTrue(jAuth::changePassword("testldap usr {$i}", "newpass{$i}")); } $myUsersLDAP = jAuth::getUserList('testldap usr*'); $users = "<array>"; for ($i = 1; $i <= NB_USERS_LDAP; $i++) { $users .= "\n <object>\n <array property=\"login\">array('testldap usr {$i}')</array>\n <array property=\"email\">array('usr{$i}.testldap@domain.com')</array>\n <array property=\"cn\">array('testldap usr {$i}')</array>\n <array property=\"distinguishedName\">array('CN=testldap usr {$i},{$this->config['ldap']['searchBaseDN']}')</array>\n <array property=\"name\">array('testldap usr {$i}')</array>\n <string property=\"password\" value=\"\" />\n </object>\n "; } $users .= "</array>"; $this->assertComplexIdenticalStr($myUsersLDAP, $users); for ($i = 1; $i <= NB_USERS_LDAP; $i++) { $this->assertTrue(jAuth::removeUser("testldap usr {$i}")); } $myUsersLDAP = jAuth::getUserList('testldap usr*'); $this->assertFalse(count($myUsersLDAP) > 0); }
/** * */ function update() { $id = $this->param('j_user_login'); $pwd = $this->param('pwd'); $pwdconf = $this->param('pwd_confirm'); $rep = $this->getResponse('redirect'); if ($this->personalView && $id != jAuth::getUserSession()->login) { jMessage::add(jLocale::get('jelix~errors.acl.action.right.needed'), 'error'); $rep->action = 'master_admin~default:index'; return $rep; } if (trim($pwd) == '' || $pwd != $pwdconf) { jMessage::add(jLocale::get('crud.message.bad.password'), 'error'); $rep->action = 'password:index'; $rep->params['j_user_login'] = $id; return $rep; } if (jAuth::changePassword($id, $pwd)) { jMessage::add(jLocale::get('crud.message.change.password.ok', $id), 'notice'); if ($this->personalView) { $rep->action = 'user:index'; } else { $rep->action = 'default:view'; } $rep->params['j_user_login'] = $id; return $rep; } else { jMessage::add(jLocale::get('crud.message.change.password.notok'), 'error'); $rep->action = 'password:index'; $rep->params['j_user_login'] = $id; } return $rep; }
/** * */ function update() { $id = $this->param('id'); $pwd = $this->param('pwd'); $pwdconf = $this->param('pwd_confirm'); $rep = $this->getResponse('redirect'); if (trim($pwd) == '' || $pwd != $pwdconf) { jMessage::add(jLocale::get('crud.message.bad.password'), 'error'); $rep->action = 'password:index'; $rep->params['id'] = $id; return $rep; } if (jAuth::changePassword($id, $pwd)) { jMessage::add(jLocale::get('crud.message.change.password.ok', $id), 'notice'); if ($this->personalView) { $rep->action = 'user:index'; } else { $rep->action = 'default:view'; } $rep->params['id'] = $id; return $rep; } else { jMessage::add(jLocale::get('crud.message.change.password.notok'), 'error'); $rep->action = 'password:index'; $rep->params['id'] = $id; } return $rep; }
/** * */ function save() { $rep = $this->getResponse('json'); //parametres $password = $this->param('password'); $lastname = $this->param('lastname'); $firstname = $this->param('firstname'); $email = $this->param('email'); //alert $success = false; $msg = "Profile non modifié"; //verification //update if (!empty($firstname) && !empty($lastname) && jFilter::isEmail($email)) { // instanciation de la factory $user = jAuth::getUser(jAuth::getUserSession()->id); // infos user $user->lastname = $lastname; $user->firstname = $firstname; $user->email = $email; // on le sauvegarde dans la base try { jAuth::updateUser($user); if (!empty($password) && $user->password != $password) { jAuth::changePassword($user->login, $password); } $success = true; } catch (Exception $e) { $success = false; $msg = "Profile non modifié"; } if ($success) { $msg = "profile modifié "; } } $rep->data = array('success' => $success, 'msg' => $msg); return $rep; }
function cryptUsersPassword() { $and = ' AND 1>2 '; $cnx = jDb::getConnection('jauthdb~jelixuser', 'jauth'); $sql = "\n SELECT u.usr_login, u.usr_password\n FROM jlx_user u INNER JOIN lizlogin l\n ON l.usr_password = u.usr_password AND l.usr_login = u.usr_login\n WHERE 2>1\n "; $sql .= $and; $res = $cnx->query($sql); foreach ($res as $rec) { jAuth::changePassword($rec->usr_login, $rec->usr_password); } }
/** * activate a new password. the key should be given as a parameter */ function confirm() { $repError = $this->_check(); if ($repError) { return $repError; } $rep = $this->getResponse("redirect"); $rep->action = "password:confirmform"; if ($_SERVER['REQUEST_METHOD'] != 'POST') { return $rep; } $form = jForms::fill('confirmation'); if ($form == null) { return $rep; } if (!$form->check()) { return $rep; } $login = $form->getData('conf_login'); $user = jAuth::getUser($login); if (!$user) { $form->setErrorOn('conf_login', jLocale::get('password.form.confirm.login.doesnt.exist')); return $rep; } if ($user->status != JCOMMUNITY_STATUS_PWD_CHANGED) { jForms::destroy('confirmation'); $rep = $this->getResponse('html'); $tpl = new jTpl(); $tpl->assign('status', JCOMMUNITY_STATUS_VALID); $rep->body->assign('MAIN', $tpl->fetch('password_ok')); return $rep; } if (strcmp($user->request_date, date('Y-m-d H:i:s', time() - 48 * 60 * 60)) < 0) { jForms::destroy('confirmation'); $rep = $this->getResponse('html'); $tpl = new jTpl(); $tpl->assign('status', JCOMMUNITY_STATUS_MAIL_CHANGED); $rep->body->assign('MAIN', $tpl->fetch('password_ok')); return $rep; } if ($form->getData('conf_key') != $user->keyactivate) { $form->setErrorOn('conf_key', jLocale::get('password.form.confirm.bad.key')); return $rep; } $passwd = $form->getData('conf_password'); $user->status = JCOMMUNITY_STATUS_VALID; jAuth::updateUser($user); jAuth::changePassword($login, $passwd); jAuth::login($login, $passwd); jForms::destroy('confirmation'); $rep->action = "password:confirmok"; return $rep; }
/** * activate an account. the key should be given as a parameter */ function confirm() { if (jAuth::isConnected()) { return $this->noaccess(); } $rep = $this->getResponse("redirect"); $rep->action = "registration:confirmform"; if ($_SERVER['REQUEST_METHOD'] != 'POST') { return $rep; } $form = jForms::fill('confirmation'); if ($form == null) { return $rep; } if (!$form->check()) { return $rep; } $login = $form->getData('conf_login'); $user = jAuth::getUser($login); if (!$user) { $form->setErrorOn('conf_login', jLocale::get('register.form.confirm.login.doesnt.exist')); return $rep; } if ($user->status != JCOMMUNITY_STATUS_NEW) { jForms::destroy('confirmation'); $rep = $this->getResponse('html'); $tpl = new jTpl(); $tpl->assign('already', true); $rep->body->assign('MAIN', $tpl->fetch('registration_ok')); return $rep; } if ($form->getData('conf_key') != $user->keyactivate) { $form->setErrorOn('conf_key', jLocale::get('register.form.confirm.bad.key')); return $rep; } $user->status = JCOMMUNITY_STATUS_VALID; jEvent::notify('jcommunity_registration_confirm', array('user' => $user)); jAuth::updateUser($user); jAuth::changePassword($login, $form->getData('conf_password')); jAuth::login($login, $form->getData('conf_password')); jForms::destroy('confirmation'); $rep->action = "registration:confirmok"; return $rep; }
function changePassword() { $rep = $this->getResponse('json'); //parametres $login = $this->param('login'); $password = $this->param('password'); //alert $this->success = false; $this->msg = "mot de passe non modifié"; //verification if (!empty($login) && !empty($password)) { try { $this->success = jAuth::changePassword($login, $password); } catch (Exception $e) { $this->success = false; $this->msg = "mot de passe non modifié"; } if ($this->success) { $this->msg = "mot de passe modifié "; } } $rep->data = array('success' => $this->success, 'msg' => $this->msg); return $rep; }
/** * let's change the user password */ function savenewpwd() { $login = $this->param('user'); $rep = $this->getResponse('redirect'); $rep->action = 'jcommunity~account:show'; $rep->params = array('user' => $login); if ($login == '' || !jAuth::isConnected() || jAuth::getUserSession()->login != $login) { return $rep; } $form = jForms::fill('havefnubb~pwd', $login); if (!$form) { return $rep; } // check the form ! $form->check(); //if error go back to the form to retry to change the password if (count($form->getErrors())) { $rep->action = 'havefnubb~members:changepwd'; // check if the new password is different from the actual one } else { if ($form->getData('conf_password') == $form->getData('old_password')) { jMessage::add(jLocale::get('havefnubb~members.pwd.passwd.are.the.same.unchanged'), 'warning'); $rep->action = 'havefnubb~members:changepwd'; return $rep; } //update the password $passwd = $form->getData('conf_password'); $user = jAuth::getUser($login); // update the user info jAuth::updateUser($user); // change the pass jAuth::changePassword($login, $passwd); // login back with new pass jAuth::login($login, $passwd); jForms::destroy('havefnubb~pwd'); } jMessage::add(jLocale::get('havefnubb~member.pwd.passwd.successfully.changed'), 'ok'); return $rep; }
function activePassword() { $rep = $this->getResponse('html'); $rep->title = "Réiniatliser mot de passe étape 2/2 " . $rep->appName; $success = false; $expired = 0; $captchaSuccess = false; $msg = "Echec de l'operation : lien expiré "; $rep->bodyTpl = "activepassmessage"; $token = $this->param('token'); $password = $this->param('password'); // security $recaptcha = $this->param("g-recaptcha-response"); if (empty($recaptcha)) { $success = false; $captchaSuccess = false; $msg = " Vueillez cocher la case je ne suis pas un robot et respecter les instructions"; } else { $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $this->secretkey . "&response=" . $recaptcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']); if ($response . success == false) { $captchaSuccess = false; $msg = "Données invalides : Vueillez cocher la case je ne suis pas un robot et respecter les instructions"; } else { $captchaSuccess = true; } } // end security if (!empty($token) && $captchaSuccess && !empty($password)) { $pass = $password; $tb = jDao::get('user'); $user = $tb->getByKeyactivate($token); // $sub->status=1; if ($user->id) { try { $user->keyactivate = '111'; jAuth::updateUser($user); jAuth::changePassword($user->login, $pass); //mail $mail = new jMailer(); $tpl = $mail->Tpl('user~activepassmail', false); $tpl->assign('user', $user); $tpl->assign('pass', $pass); $mail->Send(); $success = true; $expired = 0; $msg = "Opération effectuée avec succès : mot de passe" . " réinitialisé veuillez consulter votre mail, " . " pour connaitre votre nouveau mot de passe."; } catch (Exception $e) { $success = false; $expired = 1; $msg = "Opération effectuée echouée:" . "formulaire invalide, votre lien d'activation est peut etre périmé;."; } } else { $expired = 1; } } $rep->body->assign('MESSAGE', $msg); $rep->body->assign('captchaSuccess', $captchaSuccess); $rep->body->assign('success', $success); $rep->body->assign('expired', $expired); $rep->body->assign('token', $token); $rep->body->assign('sitekey', $this->sitekey); return $rep; }