Skip to content
Snippets Groups Projects
Commit ff257907 authored by Pavel Vyskočil's avatar Pavel Vyskočil Committed by Pavel Vyskočil
Browse files

Added possibility to recover LSHostel password

parent 4cbb9052
Branches
Tags
No related merge requests found
......@@ -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
......
......@@ -13,5 +13,8 @@
},
"email": {
"en": "Email"
},
"forgot_password": {
"en": "Forgot your password? Change it here!"
}
}
{
"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
<?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');
<?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).'" />');
......
<?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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment