Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ajax/changePassword.json.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@

$retval = array();

// check if a random password is whished
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wished -> requested

if (isset($request['randomPassword']) && $request['randomPassword'] === true) {
$request['newPassword'] = User::generateRandomPassword();
$retval["password"] = $request['newPassword'];
}

// check which field should be changed
if (!empty($request['newPassword'])) {
$newPass = $request['newPassword'];
Expand Down
149 changes: 148 additions & 1 deletion changePassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@
</table>

<!-- Modal-Dialog zum Passwort ändern -->
<div id="pwChangeModal" class="modal fade" role="dialog">
<div id="pwChangeModal"
class="modal fade"
role="dialog"
ng-controller="ChangePasswordController as changePassword">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" role="form">
Expand All @@ -71,6 +74,11 @@
<h4 class="modal-title">Passwort ändern</h4>
</div>
<div class="modal-body">

<!-- Step 0: set password -->
<div class="ngStepAnimated" id="step0"
ng-if="changePassword.step === 0"
ng-class="{'moveToRight' : changePassword.moveToRight}">
<div class="form-group">
<label class="control-label col-sm-4">
User:
Expand Down Expand Up @@ -109,18 +117,141 @@
</span>
</div>
</div>
</div>

<!-- Step 1: choose template -->
<div class="ngStepAnimated" id="step1"
ng-if="changePassword.step === 1"
ng-class="{'moveToRight' : changePassword.moveToRight}">
<form class="form-horizontal"
role="form">
<div class="form-group">
<label class="control-label col-sm-2">E-Mail-Vorlage:</label>
<div class="col-sm-10">
<div ng-repeat="(index, template) in changePassword.mailSettings.templates"
class="radio">
<label>
<input type="radio"
value="{{index}}"
ng-model="changePassword.mailtemplate"
name="mailtemplate">
{{template.name}}
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-primary"
ng-click="changePassword.stepBack()">
Abbrechen
</button>
<button class="btn btn-primary"
ng-click="changePassword.completeStep1()">
Weiter
</button>
</div>
</div>
</form>
</div>

<!-- Step 2: send mail -->
<div class="ngStepAnimated" id="step2"
ng-if="changePassword.step === 2"
ng-class="{'moveToRight' : changePassword.moveToRight}">
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="control-label col-sm-2" for="sender">Absender:</label>
<div class="col-sm-10">
<input type="email"
class="form-control"
id="sender"
ng-model="changePassword.mailform.sender" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="recipient">Empfänger:</label>
<div class="col-sm-10">
<input type="email"
class="form-control"
id="recipient"
ng-model="changePassword.mailform.recipient" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="subject">Betreff:</label>
<div class="col-sm-10">
<input type="text"
class="form-control"
id="subject"
ng-model="changePassword.mailform.subject" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="mailbody">Text:</label>
<div class="col-sm-10">
<textarea class="form-control" id="mailbody" rows="20"
ng-model="changePassword.mailform.mailbody"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-primary"
ng-click="changePassword.stepBack()">
Zurück
</button>
<button class="btn btn-primary"
ng-click="changePassword.sendMail()"
ng-disabled="changePassword.mailsending || changePassword.mailsuccess">
Mail absenden
</button>
<span class="fa fa-refresh"
ng-show="changePassword.mailsending"
ng-class="{'fa-spin' : changePassword.mailsending}">
</span>
<span class="fa fa-check"
ng-show="changePassword.mailsuccess"></span>
<span class="fa fa-times"
ng-show="changePassword.mailfailure"></span>
</div>
</div>
</form>
</div>

<!-- Step 3: ready -->
<div class="ngStepAnimated" id="step3"
ng-if="changePassword.step === 3"
ng-class="{'moveToRight' : changePassword.moveToRight}">
<div class="alert alert-success">Mail erfolgreich versandt</div>
</div>

</div> <!-- modal-body -->
<div class="modal-footer">
<button type="button"
class="btn btn-info pull-left btn-sm"
ng-show="changePassword.step === 0"
ng-click="changePassword.setRandomPassword(list.pwChangeUser)">
Zufällig Generieren &amp; Mailen
</button>
<input type="submit"
class="btn btn-primary pull-right btn-sm rbtnMargin"
ng-show="changePassword.step === 0"
ng-click="list.changePassword()"
ng-disabled="!list.pwd1 || !list.isSamePw()"
value="Ändern" />
<button type="button"
class="btn pull-right btn-sm"
ng-show="changePassword.step === 0"
data-dismiss="modal">
Abbrechen
</button>
<button type="button"
class="btn pull-right btn-sm"
ng-show="changePassword.step !== 0"
ng-click="changePassword.reset()"
data-dismiss="modal">
Fertig
</button>
</div> <!-- modal-footer -->
</form>
</div> <!-- modal-content -->
Expand All @@ -133,5 +264,21 @@ class="btn pull-right btn-sm"
<script type="application/json" json-data id="jsonUsers">
<?php echo json_encode($users, JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_QUOT); ?>
</script>
<script type="application/json" json-data id="mailSettings">
<?php
$mail_templates = array();
foreach (MAIL_TEMPLATES['changePassword'] as $template) {
$mail_templates[] = array(
'name' => (isset($template['name'])?$template['name']:basename($template['file'])),
'subject' => $template['subject'],
'template' => file_get_contents(BASE_PATH . $template['file']));
}
$mailSettings = array(
'sender' => MAIL_SENDER,
'sendername' => $_SESSION['givenName'],
'templates' => $mail_templates);
echo json_encode($mailSettings, JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_QUOT);
?>
</script>

<?php include('html_bottom.inc.php'); ?>
7 changes: 7 additions & 0 deletions config.inc.php.template
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const MAIL_TEMPLATES = array(
'subject' => 'Your account for example.com',
'file' => 'mail-templates/special-newuser.tpl'
)
),
'changePassword' => array(
array(
'name' => 'Default',
'subject' => 'Your new password for example.com',
'file' => 'mail-templates/mail-password.tpl'
)
)
);

Expand Down
109 changes: 109 additions & 0 deletions js/angular-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,115 @@



useradminApp.controller('ChangePasswordController',
function($http, alertsService) {
this.alerts = alertsService;

var mailSettingsEl = document.getElementById('mailSettings');
if (mailSettingsEl) {
this.mailSettings = JSON.parse(mailSettingsEl.textContent);
}

this.reset = function() {
this.step = 0;
this.moveToRight = false;

this.user = null;
this.userpassword = null;

this.mailtemplate = "0";

this.mailform = {
"sender": this.mailSettings.sender,
"recipient": "",
"subject": "",
"mailbody": ""
};

this.mailsending = false;
this.mailsuccess = false;
this.mailfailure = false;
}
this.reset();

this.setRandomPassword = function(user) {
this.user = user;
var that = this;
$http.post('ajax/changePassword.json.php',{
'dn': this.user.dn,
'randomPassword': true})
.then(function(response) {
// success
that.userpassword = response.data.password;
that.gotoStep(1);
}, function(response) {
// error
var responsemsg;
if (typeof response.data == 'object') {
responsemsg = response.data.detail;
} else {
responsemsg = response.data;
}
that.alerts.push(
{type: 'danger',
msg: 'Passwort konnte nicht geändert werden: '
+ responsemsg});
});
};

this.completeStep1 = function() {
var f = this.mailform;
f.recipient = this.user.mail;
f.subject = this.mailSettings.templates[this.mailtemplate].subject;
var context = {
user: this.user,
sendername: this.mailSettings.sendername,
userpassword: this.userpassword
};
var template = this.mailSettings.templates[this.mailtemplate].template;
f.mailbody = Mark.up(template, context);
this.gotoStep(2);
};

this.sendMail = function() {
this.mailsending = true;
this.mailsuccess = false;
this.mailfailure = false;
var that = this;
$http.post('ajax/sendMail.json.php',
{'mailform': this.mailform
})
.then(function(response) {
that.mailsuccess = true;
that.mailsending = false;
that.gotoStep(3);
}, function(response) {
that.mailfailure = true;
that.mailsending = false;
});
};

this.stepBack = function() {
this.gotoStep(this.step - 1);
};

this.gotoStep = function(newstep) {
// Need to set class moveToRight manually to the currently visible step,
// which is then hidden
var el = document.getElementById('step' + this.step);
if (newstep > this.step) {
el.classList.remove('moveToRight');
this.moveToRight = false;
} else {
el.classList.add('moveToRight');
this.moveToRight = true;
}
this.step = newstep;
}
});



useradminApp.controller('SelfServiceController',
function($http) {

Expand Down