diff --git a/CHANGELOG.md b/CHANGELOG.md index d9559fd5277ac7a045095493d20d8967dab35a3a..d87cba6705c46e6ca67bd4cdcb4d74b7d7bd29f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +#### Added +- Added possibility to recover LS Hostel password #### Changed - Use email as identifier instead of username diff --git a/dictionaries/lshostel.definition.json b/dictionaries/lshostel.definition.json index c343652f67b7c00a1d614923512a699f31ab0c07..9301050ef98d2ad560e1e6eedfa230f8a01f2200 100644 --- a/dictionaries/lshostel.definition.json +++ b/dictionaries/lshostel.definition.json @@ -13,5 +13,8 @@ }, "email": { "en": "Email" + }, + "forgot_password": { + "en": "Forgot your password? Change it here!" } } diff --git a/dictionaries/pwd_reset.definition.json b/dictionaries/pwd_reset.definition.json new file mode 100644 index 0000000000000000000000000000000000000000..f3ffe6ace3bbd20226731d444e44013a3bfed865 --- /dev/null +++ b/dictionaries/pwd_reset.definition.json @@ -0,0 +1,32 @@ +{ + "header": { + "en": "Forgot your password?" + }, + "email": { + "en": "Email" + }, + "text": { + "en": "Enter your email. We'll send you an email with instructions on how to reset your password." + }, + "ok_header": { + "en": "Link to reset password has been sent" + }, + "ok_text": { + "em": "We have sent you an email with instructions on how to reset your password." + }, + "err_header": { + "en": "Something went wrong" + }, + "err_text_part1": { + "en": "Please check the filled email is correct." + }, + "err_text_part2": { + "en": "If you have problem with recovering your password, please contact " + }, + "support": { + "en": "support" + }, + "submit": { + "en": "Submit" + } +} \ No newline at end of file diff --git a/templates/pwd_reset-tpl.php b/templates/pwd_reset-tpl.php new file mode 100644 index 0000000000000000000000000000000000000000..534b31eebc48d1c3baeb362296369f985211d750 --- /dev/null +++ b/templates/pwd_reset-tpl.php @@ -0,0 +1,78 @@ +<?php +/** + * @author Pavel Vyskocil <vyskocilpavel@muni.cz> + */ + + +namespace SimpleSAML\Module\lshostel; + +$this->data['header'] = $this->t('{lshostel:pwd_reset:header}'); + +$this->includeAtTemplateBase('includes/header.php'); + +if (isset($_POST['username'])) { + $userName = $_POST['username']; + try { + sendPasswordResetEmail($userName); + ?> + <div class="alert alert-success" > + <span class="glyphicon glyphicon-exclamation-sign" style="float:left; font-size: 38px; margin-right: 10px;"></span> + + <strong><?php echo $this->t('{lshostel:pwd_reset:ok_header}');?></strong> + + <p><?php echo $this->t('{lshostel:pwd_reset:ok_text}');?></p> + </div> + + <?php + } catch (\Exception $exception) { + ?> + <div class="alert alert-danger" > + <span class="glyphicon glyphicon-exclamation-sign" style="float:left; font-size: 38px; margin-right: 10px;"></span> + + <strong><?php echo $this->t('{lshostel:pwd_reset:err_header}');?></strong> + + <p><?php echo $this->t('{lshostel:pwd_reset:err_text_part1}');?></p> + <p><?php echo $this->t('{lshostel:pwd_reset:err_text_part2}');?> + <a href="mailto:idm@ics.muni.cz"><?php echo $this->t('{lshostel:pwd_reset:support}');?> + </a>. + </p> + </div> + + + <?php + } +} + +?> + + <p><?php echo $this->t('{lshostel:pwd_reset:text}'); ?></p> + + <br> + + <form action="?" method="post" name="passwd_reset" class="form-horizontal"> + + <div class="form-group"> + <label for="username" class="col-sm-2 control-label"><?php echo $this->t('{lshostel:pwd_reset:email}'); ?></label> + <div class="col-sm-10"> + <input id="username" type="text" name="username" class="form-control"/> + </div> + </div> + + <div class="form-group"> + <div class="col-sm-offset-8 col-sm-4"> + <button class="btn btn-success btn-block" + onclick="this.value='<?php echo $this->t('{login:processing}'); ?>'; + this.disabled=true; this.form.submit(); return true;" tabindex="6"> + <?php echo $this->t('{lshostel:pwd_reset:submit}'); ?> + </button> + </div> + + </div> + + </form> + + +<?php + +$this->includeAtTemplateBase('includes/footer.php'); + diff --git a/themes/lshostel/core/loginuserpass.php b/themes/lshostel/core/loginuserpass.php index a8a6044cb9c8bed09af85fbebe2d0649a22b2d5b..077cc79554648c37bdefed0d8a2728b46ce12ff6 100644 --- a/themes/lshostel/core/loginuserpass.php +++ b/themes/lshostel/core/loginuserpass.php @@ -1,6 +1,6 @@ <?php -//$this->data['header'] = $this->t('{lshostel:lshostel:user_pass_header}'); -$this->data['header'] = "Life Science Hostel Login"; +$this->data['header'] = $this->t('{lshostel:lshostel:user_pass_header}'); +//$this->data['header'] = "Life Science Hostel Login"; if (strlen($this->data['username']) > 0) { $this->data['autofocus'] = 'password'; @@ -139,22 +139,29 @@ if ($this->data['errorcode'] !== null) { ?> <div class="form-group"> - <div class="col-sm-offset-2 col-sm-10"> - <div class="col-sm-offset-2 col-sm-4"> - <button class="btn btn-success" - onclick="this.value='<?php echo $this->t('{login:processing}'); ?>'; - this.disabled=true; this.form.submit(); return true;" tabindex="6"> - <?php echo $this->t('{login:login_button}'); ?> - </button> - </div> - <div class="col-sm-4"> - <a href="https://perun.bbmri-eric.eu/non/registrar/?vo=lifescience_hostel" class="btn btn-link btn-block"> - <?php echo $this->t('{lshostel:lshostel:register_acc_hostel}') ?> - </a> - </div> - </div> + <div class="col-sm-offset-8 col-sm-4"> + <button class="btn btn-success btn-block" + onclick="this.value='<?php echo $this->t('{login:processing}'); ?>'; + this.disabled=true; this.form.submit(); return true;" tabindex="6"> + <?php echo $this->t('{login:login_button}'); ?> + </button> + </div> + </div> + <div id="login_form_links" class="row"> + <div class="col-sm-6"> + <a href="<?php echo SimpleSAML\Module::getModuleURL("lshostel/pwd_reset.php");?>" class="btn btn-link btn-block"> + <?php echo $this->t('{lshostel:lshostel:forgot_password}') ?> + </a> + </div> + <div class="col-sm-6"> + <a href="https://perun.bbmri-eric.eu/non/registrar/?vo=lifescience_hostel" class="btn btn-link btn-block"> + <?php echo $this->t('{lshostel:lshostel:register_acc_hostel}') ?> + </a> + </div> + </div> + <?php foreach ($this->data['stateparams'] as $name => $value) { echo('<input type="hidden" name="'.htmlspecialchars($name).'" value="'.htmlspecialchars($value).'" />'); diff --git a/www/pwd_reset.php b/www/pwd_reset.php new file mode 100644 index 0000000000000000000000000000000000000000..0af8b6e4380e236f803e1a406f57e79aaa5fc3f5 --- /dev/null +++ b/www/pwd_reset.php @@ -0,0 +1,59 @@ +<?php +/** + * @author Pavel Vyskocil <vyskocilpavel@muni.cz> + */ + + +use SimpleSAML\Configuration; +use SimpleSAML\Error\Exception; +use SimpleSAML\Logger; +use SimpleSAML\XHTML\Template; + + +const LSHOSTEL_ENTITY_ID = "https://login.bbmri-eric.eu/lshostel/"; +const LSHOSTEL_SCOPE = "@lifescience-hostel.org"; +const VO_SHORT_NAME = "lifescience_hostel"; +const PERUN_NAMESPACE = "lifescience-hostel"; +const PERUN_URL = "https://perun.bbmri-eric.eu/"; +const EMAIL_ATTR_URN = "urn:perun:user:attribute-def:def:preferredMail"; +const LANG_EN = "en"; + +$config = Configuration::getInstance(); + + +$t = new Template($config, 'lshostel:pwd_reset-tpl.php'); +$t->show(); + + +function sendPasswordResetEmail($userName) { + $rpcAdapter = new sspmod_perun_AdapterRpc(); + $userName = str_replace('@', '_', $userName); + $uid = [$userName . LSHOSTEL_SCOPE]; + $user = null; + try { + $user = $rpcAdapter->getPerunUser(LSHOSTEL_ENTITY_ID, $uid); + } catch (Exception $ex) { + throw new Exception("There are no LifeScience Hostel user with username: " . $userName, $ex); + } + if (is_null($user )){ + throw new Exception("There are no LifeScience Hostel user with username: " . $userName); + } + + $vo = $rpcAdapter->getVoByShortName(VO_SHORT_NAME); + $member = $rpcAdapter->getMemberByUser($user, $vo); + + $connector = $rpcAdapter->getConnector(); + + $response = $connector->post('membersManager', + 'sendPasswordResetLinkEmail', + [ + 'member' => $member->getId(), + 'namespace' => PERUN_NAMESPACE, + 'url' => PERUN_URL, + 'emailAttributeURN' => EMAIL_ATTR_URN, + 'language' => LANG_EN + ]); + + Logger::debug(print_r($response, true)); + +} \ No newline at end of file diff --git a/www/res/css/lshostel.css b/www/res/css/lshostel.css index dfd19e2fc7947182cb080b092350a8e9950f0832..ecb02c3a533f880912dee4e266e2be3203e7d826 100644 --- a/www/res/css/lshostel.css +++ b/www/res/css/lshostel.css @@ -68,3 +68,9 @@ hr { #footer img { margin: 0px 16px; } + + +#login_form_links { + margin-top: 50px; + margin-bottom: -32px; +} \ No newline at end of file