00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00033 class ilPasswordAssistanceGUI
00034 {
00038 function ilPasswordAssistanceGUI()
00039 {
00040 global $ilCtrl;
00041
00042 $this->ctrl =& $ilCtrl;
00043 }
00044
00048 function &executeCommand()
00049 {
00050 global $ilias, $lng, $ilSetting, $ilErr, $ilAuth;
00051
00052
00053 if (!$ilSetting->get("password_assistance"))
00054 {
00055 if (empty($_SESSION["AccountId"]) and $_SESSION["AccountId"] !== false)
00056 {
00057 $ilErr->raiseError($lng->txt("permission_denied"),$ilias->error_obj->WARNING);
00058 }
00059 }
00060
00061
00062 if (!$ilSetting->get("setup_ok"))
00063 {
00064 die("Setup is not completed. Please run setup routine again. (pwassist.php)");
00065 }
00066
00067
00068
00069 $lang = $_GET['lang'];
00070 if ($lang != null && $lang != "" && $lng->getLangKey() != $lang)
00071 {
00072 $lng = new ilLanguage($lang);
00073 }
00074 $lng->loadLanguageModule('pwassist');
00075
00076 $cmd = $this->ctrl->getCmd();
00077 $next_class = $this->ctrl->getNextClass($this);
00078
00079 switch($next_class)
00080 {
00081 default:
00082 if ($cmd != "")
00083 {
00084 return $this->$cmd();
00085 }
00086 else
00087 {
00088 if (!empty($_GET["key"])) {
00089 $this->showAssignPasswordForm();
00090 } else {
00091 $this->showAssistanceForm();
00092 }
00093 }
00094 break;
00095 }
00096
00097
00098
00099
00100
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 function showAssistanceForm($message="", $username="", $email="")
00119 {
00120 global $tpl, $ilias, $lng;
00121
00122
00123 $tpl->addBlockFile("CONTENT", "content", "tpl.pwassist_assistance.html");
00124
00125 if ($message != "")
00126 {
00127 $tpl->setCurrentBlock("pw_message");
00128 $tpl->setVariable("TXT_MESSAGE", str_replace("\\n","<br>",$message));
00129 $tpl->parseCurrentBlock();
00130 }
00131
00132 $tpl->setVariable("FORMACTION",
00133 $this->ctrl->getFormAction($this));
00134 $tpl->setVariable("TARGET","target=\"_parent\"");
00135 $tpl->setVariable("IMG_AUTH",
00136 ilUtil::getImagePath("icon_auth_b.gif"));
00137 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("password_assistance"));
00138
00139 $contact_address = $ilias->getSetting("admin_email");
00140 $tpl->setVariable
00141 (
00142 "TXT_ENTER_USERNAME_AND_EMAIL",
00143 str_replace
00144 (
00145 "\\n","<br>",
00146 sprintf
00147 (
00148 $lng->txt("pwassist_enter_username_and_email"),
00149 "<a href=\"mailto:".$contact_address."\">".$contact_address."</a>"
00150 )
00151 )
00152 );
00153 $tpl->setVariable("TXT_USERNAME", $lng->txt("username"));
00154 $tpl->setVariable("TXT_EMAIL", $lng->txt("email"));
00155 $tpl->setVariable("USERNAME", $username);
00156 $tpl->setVariable("EMAIL", $email);
00157 $tpl->setVariable("TXT_SUBMIT", $lng->txt("submit"));
00158 $tpl->setVariable("BACK", $lng->txt("back"));
00159 $tpl->setVariable("LINK_BACK",
00160 $this->ctrl->getLinkTargetByClass("ilstartupgui", "showLogin"));
00161 $tpl->setVariable("LANG", $lng->getLangKey());
00162
00163 $tpl->show();
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 function showUsernameAssistanceForm($message="", $username="", $email="")
00182 {
00183 global $tpl, $ilias, $lng;
00184
00185
00186 $tpl->addBlockFile("CONTENT", "content", "tpl.pwassist_username_assistance.html");
00187
00188 if ($message != "")
00189 {
00190 $tpl->setCurrentBlock("pw_message");
00191 $tpl->setVariable("TXT_MESSAGE", str_replace("\\n","<br>",$message));
00192 $tpl->parseCurrentBlock();
00193 }
00194
00195 $tpl->setVariable("FORMACTION",
00196 $this->ctrl->getFormAction($this));
00197 $tpl->setVariable("IMG_AUTH",
00198 ilUtil::getImagePath("icon_auth_b.gif"));
00199 $tpl->setVariable("TARGET","target=\"_parent\"");
00200 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("password_assistance"));
00201
00202 $contact_address = $ilias->getSetting("admin_email");
00203 $tpl->setVariable
00204 (
00205 "TXT_ENTER_USERNAME_AND_EMAIL",
00206 str_replace
00207 (
00208 "\\n","<br>",
00209 sprintf
00210 (
00211 $lng->txt("pwassist_enter_email"),
00212 "<a href=\"mailto:".$contact_address."\">".$contact_address."</a>"
00213 )
00214 )
00215 );
00216 $tpl->setVariable("TXT_USERNAME", $lng->txt("username"));
00217 $tpl->setVariable("TXT_EMAIL", $lng->txt("email"));
00218 $tpl->setVariable("USERNAME", $username);
00219 $tpl->setVariable("EMAIL", $email);
00220 $tpl->setVariable("TXT_SUBMIT", $lng->txt("submit"));
00221 $tpl->setVariable("BACK", $lng->txt("back"));
00222 $tpl->setVariable("LINK_BACK",
00223 $this->ctrl->getLinkTargetByClass("ilstartupgui", "showLogin"));
00224 $tpl->setVariable("LANG", $lng->getLangKey());
00225
00226 $tpl->show();
00227 }
00228
00241 function submitAssistanceForm()
00242 {
00243 global $tpl, $ilias, $lng, $rbacadmin, $rbacreview;
00244
00245 require_once "classes/class.ilObjUser.php";
00246 require_once "classes/class.ilUtil.php";
00247
00248
00249 $username = ilUtil::stripSlashes($_POST["username"]);
00250 $email = ilUtil::stripSlashes($_POST["email"]);
00251
00252
00253 $userObj = null;
00254 $userid = ilObjUser::getUserIdByLogin($username);
00255 $txt_key = "pwassist_invalid_username_or_email";
00256 if ($userid != 0)
00257 {
00258 $userObj = new ilObjUser($userid);
00259 if (strcasecmp($userObj->getEmail(), $email) != 0)
00260 {
00261 $userObj = null;
00262 } else if ($userObj->getAuthMode(true) != AUTH_LOCAL ||
00263 ($userObj->getAuthMode(true) == AUTH_DEFAULT && AUTH_DEFAULT != AUTH_LOCAL))
00264 {
00265 $userObj = null;
00266 $txt_key = "pwassist_invalid_auth_mode";
00267 }
00268 }
00269
00270
00271
00272 if ($userObj == null)
00273 {
00274 $this->showAssistanceForm
00275 (
00276 $lng->txt($txt_key),
00277 $username,
00278 $email
00279 );
00280 }
00281
00282
00283
00284
00285 else
00286 {
00287
00288
00289
00290
00291 if ($rbacreview->isAssigned($userObj->getID, ANONYMOUS_ROLE_ID)
00292 || $rbacreview->isAssigned($userObj->getID, SYSTEM_ROLE_ID)
00293 )
00294 {
00295 $this->showAssistanceForm
00296 (
00297 $lng->txt("pwassist_not_permitted"),
00298 $username,
00299 $email
00300 );
00301 }
00302 else
00303 {
00304 $this->sendPasswordAssistanceMail($userObj);
00305 $this->showMessageForm
00306 (
00307 null,
00308 sprintf
00309 (
00310 $lng->txt("pwassist_mail_sent"),
00311 $email
00312 )
00313 );
00314 }
00315 }
00316 }
00317
00330 function submitUsernameAssistanceForm()
00331 {
00332 global $tpl, $ilias, $lng, $rbacadmin, $rbacreview;
00333
00334 require_once "classes/class.ilObjUser.php";
00335 require_once "classes/class.ilUtil.php";
00336
00337
00338 $email = ilUtil::stripSlashes($_POST["email"]);
00339
00340
00341 $logins = ilObjUser::_getUserIdsByEmail($email);
00342
00343
00344
00345 if (count($logins)< 1)
00346 {
00347 $this->showUsernameAssistanceForm
00348 (
00349 $lng->txt("pwassist_invalid_email"),
00350 "",
00351 $email
00352 );
00353 }
00354
00355
00356
00357
00358 else
00359 {
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376 {
00377 $this->sendUsernameAssistanceMail($email, $logins);
00378 $this->showMessageForm
00379 (
00380 null,
00381 sprintf
00382 (
00383 $lng->txt("pwassist_mail_sent"),
00384 $email
00385 )
00386 );
00387 }
00388 }
00389 }
00390
00404 function sendPasswordAssistanceMail($userObj)
00405 {
00406 global $lng, $ilias;
00407
00408 include_once "classes/class.ilMailbox.php";
00409 include_once "classes/class.ilMimeMail.php";
00410 require_once "include/inc.pwassist_session_handler.php";
00411
00412
00413
00414 $pwassist_session = db_pwassist_session_find($userObj->getId());
00415 if (count($pwassist_session) == 0 || $pwassist_session["expires"] < time())
00416 {
00417
00418 db_set_save_handler();
00419 session_start();
00420 $pwassist_session["pwassist_id"] = db_pwassist_create_id();
00421 session_destroy();
00422 db_pwassist_session_write(
00423 $pwassist_session["pwassist_id"],
00424 3600,
00425 $userObj->getId()
00426 );
00427 }
00428 $protocol = isset($_SERVER['HTTPS'])?"https://":"http://";
00429
00430 $server_url=$protocol.$_SERVER['HTTP_HOST'].
00431 substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],'/')).
00432 '/';
00433 $pwassist_url=$protocol.$_SERVER['HTTP_HOST']
00434 .str_replace("ilias.php", "pwassist.php", $_SERVER['PHP_SELF'])
00435 ."?client_id=".$ilias->getClientId()
00436 ."&lang=".$lng->getLangKey()
00437 ."&key=".$pwassist_session["pwassist_id"];
00438 $contact_address=$ilias->getSetting("admin_email");
00439
00440 $mm = new ilMimeMail();
00441 $mm->Subject($lng->txt("pwassist_mail_subject"));
00442 $mm->From($contact_address);
00443 $mm->To($userObj->getEmail());
00444
00445 $mm->Body
00446 (
00447 str_replace
00448 (
00449 array("\\n","\\t"),
00450 array("\n","\t"),
00451 sprintf
00452 (
00453 $lng->txt("pwassist_mail_body"),
00454 $pwassist_url,
00455 $server_url,
00456 $_SERVER['REMOTE_ADDR'],
00457 $userObj->getLogin(),
00458 'mailto:'.$contact_address
00459 )
00460 )
00461 );
00462
00463 $mm->Send();
00464 }
00465
00466
00480 function sendUsernameAssistanceMail($email, $logins)
00481 {
00482 global $lng, $ilias;
00483
00484 include_once "classes/class.ilMailbox.php";
00485 include_once "classes/class.ilMimeMail.php";
00486 require_once "include/inc.pwassist_session_handler.php";
00487 $protocol = isset($_SERVER['HTTPS'])?"https://":"http://";
00488
00489
00490
00491 $server_url=$protocol.$_SERVER['HTTP_HOST'].
00492 substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],'/')).
00493 '/';
00494 $login_url=$server_url."pwassist.php"
00495 ."?client_id=".$ilias->getClientId()
00496 ."&lang=".$lng->getLangKey();
00497
00498 $contact_address=$ilias->getSetting("admin_email");
00499
00500 $mm = new ilMimeMail();
00501 $mm->Subject($lng->txt("pwassist_mail_subject"));
00502 $mm->From($contact_address);
00503 $mm->To($email);
00504
00505 $mm->Body
00506 (
00507 str_replace
00508 (
00509 array("\\n","\\t"),
00510 array("\n","\t"),
00511 sprintf
00512 (
00513 $lng->txt("pwassist_username_mail_body"),
00514 join ($logins,",\n"),
00515 $server_url,
00516 $_SERVER['REMOTE_ADDR'],
00517 $email,
00518 'mailto:'.$contact_address,
00519 $login_url
00520 )
00521 )
00522 );
00523
00524 $mm->Send();
00525 }
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546 function showAssignPasswordForm($message="", $username="", $password1="", $password2="", $pwassist_id="")
00547 {
00548 global $tpl, $ilias, $lng, $rbacadmin, $rbacreview;
00549
00550 require_once "include/inc.pwassist_session_handler.php";
00551 require_once "classes/class.ilLanguage.php";
00552
00553
00554 if ($pwassist_id == "")
00555 {
00556 $pwassist_id = $_GET["key"];
00557 }
00558
00559
00560 $pwassist_session = db_pwassist_session_read($pwassist_id);
00561 if (count($pwassist_session) == 0 || $pwassist_session["expires"] < time())
00562 {
00563 $this->showAssistanceForm($lng->txt("pwassist_session_expired"));
00564 }
00565 else
00566 {
00567 $tpl->addBlockFile("CONTENT", "content", "tpl.pwassist_assignpassword.html");
00568 if ($message != "")
00569 {
00570 $tpl->setCurrentBlock("pw_message");
00571 $tpl->setVariable("TXT_MESSAGE", str_replace("\\n","<br>",$message));
00572 $tpl->parseCurrentBlock();
00573 }
00574
00575 $tpl->setVariable("FORMACTION",
00576 $this->ctrl->getFormAction($this));
00577 $tpl->setVariable("TARGET","target=\"_parent\"");
00578 $tpl->setVariable("IMG_AUTH",
00579 ilUtil::getImagePath("icon_auth_b.gif"));
00580 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("password_assistance"));
00581 $tpl->setVariable("TXT_ENTER_USERNAME_AND_NEW_PASSWORD", $lng->txt("pwassist_enter_username_and_new_password"));
00582 $tpl->setVariable("TXT_USERNAME", $lng->txt("username"));
00583 $tpl->setVariable("TXT_PASSWORD1", $lng->txt("password"));
00584 $tpl->setVariable("TXT_PASSWORD2", $lng->txt("retype_password"));
00585 $tpl->setVariable("USERNAME", $username);
00586 $tpl->setVariable("PASSWORD1", $password1);
00587 $tpl->setVariable("PASSWORD2", $password2);
00588 $tpl->setVariable("TXT_SUBMIT", $lng->txt("submit"));
00589 $tpl->setVariable("KEY", $pwassist_id);
00590 $tpl->setVariable("BACK", $lng->txt("back"));
00591 $tpl->setVariable("CMD_BACK",
00592 $this->ctrl->getLinkTargetByClass("ilstartupgui", "showLogin"));
00593 $tpl->setVariable("LANG", $lng->getLangKey());
00594
00595 $tpl->show();
00596 }
00597 }
00598
00618 function submitAssignPasswordForm() {
00619 global $tpl, $ilias, $lng, $rbacadmin, $rbacreview;
00620
00621 require_once "include/inc.pwassist_session_handler.php";
00622
00623
00624 $pwassist_id = ilUtil::stripSlashes($_POST["key"]);
00625 $username = ilUtil::stripSlashes($_POST["username"]);
00626 $password1 = ilUtil::stripSlashes($_POST["password1"]);
00627 $password2 = ilUtil::stripSlashes($_POST["password2"]);
00628
00629
00630 $pwassist_session = db_pwassist_session_read($pwassist_id);
00631
00632 if (count($pwassist_session) == 0 || $pwassist_session["expires"] < time())
00633 {
00634 $this->showAssistanceForm($lng->txt("pwassist_session_expired"));
00635 }
00636 else
00637 {
00638 $is_successful = true;
00639 $message = "";
00640
00641 $userObj = new ilObjUser($pwassist_session["user_id"]);
00642
00643
00644
00645
00646 if ($userObj == null)
00647 {
00648 $message = $lng->txt("user_does_not_exist");
00649 $is_successful = false;
00650 }
00651
00652
00653
00654 if ($is_successful && strcasecmp($userObj->getLogin(), $username) != 0)
00655 {
00656 $message = $lng->txt("pwassist_login_not_match");
00657 $is_successful = false;
00658 }
00659
00660
00661
00662 if ($is_successful && $password1 != $password2)
00663 {
00664 $message = $lng->txt("passwd_not_match");
00665 $is_successful = false;
00666 }
00667
00668
00669 if ($is_successful && !ilUtil::isPassword($password1))
00670 {
00671 $message = $lng->txt("passwd_invalid");
00672 $is_successful = false;
00673 }
00674
00675
00676
00677
00678
00679 if ($is_successful)
00680 {
00681 $is_successful = $userObj->resetPassword($password1,$password2);
00682 if (! $is_successful)
00683 {
00684 $message = $lng->txt("passwd_invalid");
00685 }
00686 }
00687
00688
00689
00690 if ($is_successful)
00691 {
00692 $is_successfull = $userObj->update();
00693 if (! $is_successful)
00694 {
00695 $message = $lng->txt("update_error");
00696 }
00697 }
00698
00699
00700
00701
00702
00703 if ($is_successful)
00704 {
00705 db_pwassist_session_destroy($pwassist_id);
00706 $this->showMessageForm
00707 (
00708 null,
00709 sprintf
00710 (
00711 $lng->txt("pwassist_password_assigned"),
00712 $username
00713 )
00714 );
00715 }
00716 else
00717 {
00718 $this->showAssignPasswordForm
00719 (
00720 $message,
00721 $username,
00722 $password1,
00723 $password2,
00724 $pwassist_id
00725 );
00726 }
00727 }
00728 }
00729
00730
00731
00732
00733 function showMessageForm($message="", $text="")
00734 {
00735 global $tpl, $ilias, $lng;
00736
00737 if ($message != "")
00738 {
00739 $tpl->setCurrentBlock("pw_message");
00740 $tpl->setVariable("TXT_MESSAGE", str_replace("\\n","<br>",$message));
00741 $tpl->parseCurrentBlock();
00742 }
00743
00744 $tpl->addBlockFile("CONTENT", "content", "tpl.pwassist_message.html");
00745 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("password_assistance"));
00746 $tpl->setVariable("IMG_AUTH",
00747 ilUtil::getImagePath("icon_auth_b.gif"));
00748 $tpl->setVariable("TXT_TEXT",str_replace("\\n","<br>",$text));
00749 $tpl->setVariable("BACK", $lng->txt("back"));
00750 $tpl->setVariable("LINK_BACK",
00751 $this->ctrl->getLinkTargetByClass("ilstartupgui", "showLogin"));
00752 $tpl->setVariable("LANG", $lng->getLangKey());
00753
00754 $tpl->show();
00755 }
00756 }
00757
00758 ?>