4AKMU4ZB2RYJWUDM4H2WW42MVMDWZZ4YD45FJ64DIS77TO56THZAC
MQMF2LBWWPW2SOZKC3O7P4TBJJ3V6RBVQ52OYA4KCGXS7G6SHWQAC
WDKFN4B2M7BUF4S7X6YA5AKHOJKHLG65LWNQVOSIBTKFEZELBMKAC
XJRJ4J7M6BC433TBLWHHKX7UYYCFX6M7ZQLUEYYTREPCSM6M3RDQC
LZVO64YG43JD7YMZSCTZNOBS5ROZA4FMPKJW2YOMHX2V5PTGBVWQC
LSZLZHJYGXZTCNH4JUXU7W23MW5PBVM4OBMWRRVNEDROMIBUVQNAC
SYLVCTT64DMSUBWROO5USFBSK2OCNB2NB72SSGM4MOEHMUQONEPQC
D44B24QC6NCED6DVUYP2IJJEVBG2JNBKPBRRSLI5UXQTKA23DJQQC
XUKHBDR5HJKYJ7GEWTL4YLQEW2S4ERU2WVQZU3INIJB34B4CTUKAC
TQVKZQUGCFYNH5P56LXMXRXZNTD56MH5T5GX2BMQ5YSRPGHAUYMAC
2P7VNAACFSXMH42JCXQZ7GDAAEIFDGDWJOK6XD6G36AGEYQSRO2AC
SZYDW2DG5Z7BR3ICKWDXVUNSMCDSXMYZUB6FQ4W2B2FVZJD6PULQC
2G63HKCHG7S6DGWDOHSDF7PXFPD6H4TRKDKIIFCXXAKET6FCWN2AC
LCLCU6FNQHHR5KORSS5Y5CT7QJJGVGCGGJTKXFXWIIDU5P72JAHQC
sub deleteUser {
my ($self, $c, $user) = @_;
my ($project) = $c->model('DB::Projects')->search({ owner => $user->username });
error($c, "User " . $user->username . " is still owner of project " . $project->name . ".")
if defined $project;
$c->logout() if $user->username eq $c->user->username;
$user->delete;
}
sub edit :Chained('user') :Args(0) :ActionClass('REST::ForBrowsers') { }
sub edit :Chained('user') :PathPart('') :Args(0) :ActionClass('REST::ForBrowsers') { }
$c->session->{referer} = $c->request->referer if !defined $c->session->{referer};
$c->logout() if $user->username eq $c->user->username;
$user->delete;
$c->flash->{successMsg} = "The user has been deleted.";
$self->status_no_content($c);
}
sub reset_password :Chained('user') :PathPart('reset-password') :Args(0) {
my ($self, $c) = @_;
my $user = $c->stash->{user};
if (($c->stash->{params}->{submit} // "") eq "reset-password") {
error($c, "This user's password cannot be reset.") if $user->type ne "hydra";
$c->stash->{json} = {};
error($c, "No email address is set for this user.")
unless $user->emailaddress;
my $password = Crypt::RandPasswd->word(8,10);
setPassword($user, $password);
sendEmail($c,
$user->emailaddress,
"Hydra password reset",
"Hi,\n\n".
"Your password has been reset. Your new password is '$password'.\n\n".
"You can change your password at " . $c->uri_for($self->action_for('edit'), [$user->username]) . ".\n\n".
"With regards,\n\nHydra.\n"
);
return;
}
error($c, "This user's password cannot be reset.") if $user->type ne "hydra";
error($c, "No email address is set for this user.")
unless $user->emailaddress;
txn_do($c->model('DB')->schema, sub {
updatePreferences($c, $user);
});
my $password = Crypt::RandPasswd->word(8,10);
setPassword($user, $password);
sendEmail($c,
$user->emailaddress,
"Hydra password reset",
"Hi,\n\n".
"Your password has been reset. Your new password is '$password'.\n\n".
"You can change your password at " . $c->uri_for($self->action_for('edit'), [$user->username]) . ".\n\n".
"With regards,\n\nHydra.\n"
);
if ($c->request->looks_like_browser) {
$c->flash->{successMsg} = "Your preferences have been updated.";
backToReferer($c);
} else {
$self->status_no_content($c);
}
$c->flash->{successMsg} = "A new password has been sent to ${\$user->emailaddress}.";
$self->status_no_content($c);
function backToReferrer() {
// FIXME: should only do this if the referrer is another Hydra
// page.
window.location = document.referrer;
}
<input type="checkbox" name="emailonerror" [% IF emailonerror; 'checked="checked"'; END %]/>Receive evaluation error notifications
<input type="checkbox" name="emailonerror" [% IF !create && user.emailonerror; 'checked="checked"'; END %]/>Receive evaluation error notifications
<script type="text/javascript">
$("#reset-password").click(function() {
bootbox.confirm(
'Are you sure you want to reset the password for this user?',
function(c) {
if (!c) return;
$.post("[% c.uri_for(c.controller('User').action_for('edit'), [user.username]) %]", { submit: 'reset-password' })
.done(function(data) {
if (data.error)
bootbox.alert("Unable to reset password: " + data.error);
else
bootbox.alert("An email containing the new password has been sent to the user.");
})
.fail(function() { bootbox.alert("Server request failed!"); });
});
return false;
});
</script>
<script>
$("#submit-user").click(function() {
requestJSON({
[% IF create %]
url: "[% c.uri_for(c.controller('User').action_for('register')) %]",
[% ELSE %]
url: "[% c.uri_for(c.controller('User').action_for('edit'), c.req.captures) %]",
[% END %]
data: $(this).parents("form").serialize(),
type: 'PUT',
success: backToReferrer
});
return false;
});
$("#reset-password").click(function() {
bootbox.confirm(
'Are you sure you want to reset the password for this user?',
function(c) {
if (!c) return;
requestJSON({
url: "[% c.uri_for(c.controller('User').action_for('reset_password'), [user.username]) %]",
type: 'POST',
success: backToReferrer
});
});
return false;
});
$("#delete-user").click(function() {
bootbox.confirm(
'Are you sure you want to delete this user?',
function(c) {
if (!c) return;
requestJSON({
url: "[% c.uri_for(c.controller('User').action_for('edit'), c.req.captures) %]",
type: 'DELETE',
success: backToReferrer
});
});
return false;
});
</script>