Clean up user editing

[?]
Nov 5, 2013, 1:02 PM
4AKMU4ZB2RYJWUDM4H2WW42MVMDWZZ4YD45FJ64DIS77TO56THZAC

Dependencies

  • [2] MQMF2LBW Re-enable adding new users via the web interface
  • [3] WDKFN4B2 Make sign in a modal dialog box rather than a separate page
  • [4] PZL3SZM3 Give every page a consistent title
  • [5] 2G63HKCH Fix some wellformedness issues
  • [6] SZYDW2DG hydra: added some user admin
  • [7] JARRBLZD Bootstrapify the Hydra forms (except the project and jobset edit pages)
  • [8] LZVO64YG Merge in the first bits of the API work
  • [9] SYLVCTT6 Start api cleanup with the User model
  • [10] LSZLZHJY Allow users to edit their own settings
  • [11] AWMM5OGV Use delete instead of delete_all
  • [12] LYVUXIGT Clean up the authorization code a bit
  • [13] XUKHBDR5 Prevent Persona users from setting a password
  • [14] 7KF7YZDR Disable account creation for now
  • [15] LCLCU6FN Don't show a password reset button for Persona accounts
  • [16] D44B24QC Store the account type ("hydra" or "persona") explicitly in the database
  • [17] 36ZTCZ4F Add basic Persona support
  • [18] 3PNG7NIB Remove trailing whitespace
  • [19] XJRJ4J7M Add user registration
  • [*] 2P7VNAAC Move common Javascript code into a separate file
  • [*] TQVKZQUG Use the REST API in the web interface for editing jobsets

Change contents

  • replacement in src/lib/Hydra/Controller/User.pm at line 19
    [4.478][4.23631:23695]()
    sub login :Local :Args(0) :ActionClass('REST::ForBrowsers') { }
    [4.478]
    [4.23921]
    sub login :Local :Args(0) :ActionClass('REST') { }
  • replacement in src/lib/Hydra/Controller/User.pm at line 33
    [3.380][3.380:421]()
    $self->status_ok($c, entity => { });
    [3.380]
    [4.24558]
    $self->status_no_content($c);
  • replacement in src/lib/Hydra/Controller/User.pm at line 37
    [4.1285][4.24561:24626]()
    sub logout :Local :Args(0) :ActionClass('REST::ForBrowsers') { }
    [4.1285]
    [4.1285]
    sub logout :Local :Args(0) :ActionClass('REST') { }
  • replacement in src/lib/Hydra/Controller/User.pm at line 109
    [4.1561][4.1561:1674]()
    $c->stash->{template} = 'user.tt';
    $c->stash->{create} = 1;
    return if $c->request->method ne "POST";
    [4.1561]
    [4.1674]
    if ($c->request->method eq "GET") {
    $c->stash->{template} = 'user.tt';
    $c->stash->{create} = 1;
    return;
    }
    die unless $c->request->method eq "PUT";
  • replacement in src/lib/Hydra/Controller/User.pm at line 145
    [4.3246][4.1101:1124]()
    backToReferer($c);
    [4.3246]
    [4.1124]
    $self->status_no_content($c);
  • edit in src/lib/Hydra/Controller/User.pm at line 151
    [2.593]
    [4.1127]
    my $fullName = trim($c->req->params->{fullname} // "");
    error($c, "Your must specify your full name.") if $fullName eq "";
  • edit in src/lib/Hydra/Controller/User.pm at line 165
    [2.1031][2.1031:1163]()
    my $fullName = trim($c->req->params->{fullname} // "");
    error($c, "Your must specify your full name.") if $fullName eq "";
  • replacement in src/lib/Hydra/Controller/User.pm at line 192
    [4.25091][4.25091:25125]()
    $self->status_ok(
    $c,
    [4.25091]
    [4.1770]
    $self->status_ok($c,
  • replacement in src/lib/Hydra/Controller/User.pm at line 211
    [4.3320][4.1514:1855](),[4.1855][4.25386:25459]()
    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') { }
    [4.3320]
    [4.25459]
    sub edit :Chained('user') :PathPart('') :Args(0) :ActionClass('REST::ForBrowsers') { }
  • edit in src/lib/Hydra/Controller/User.pm at line 215
    [4.3378]
    [4.1892]
    $c->stash->{template} = 'user.tt';
    }
  • edit in src/lib/Hydra/Controller/User.pm at line 218
    [4.1893]
    [4.1893]
    sub edit_PUT {
    my ($self, $c) = @_;
  • replacement in src/lib/Hydra/Controller/User.pm at line 222
    [4.1928][4.1928:2054]()
    $c->stash->{template} = 'user.tt';
    $c->session->{referer} = $c->request->referer if !defined $c->session->{referer};
    [4.1928]
    [4.2054]
    if (($c->stash->{params}->{submit} // "") eq "reset-password") {
    return;
    }
  • replacement in src/lib/Hydra/Controller/User.pm at line 226
    [4.2055][4.25476:25521]()
    $c->stash->{fullname} = $user->fullname;
    [4.2055]
    [4.2224]
    txn_do($c->model('DB')->schema, sub {
    updatePreferences($c, $user);
    });
  • replacement in src/lib/Hydra/Controller/User.pm at line 230
    [4.2225][4.25522:25575]()
    $c->stash->{emailonerror} = $user->emailonerror;
    [4.2225]
    [4.25575]
    $c->flash->{successMsg} = "Your preferences have been updated.";
    $self->status_no_content($c);
  • replacement in src/lib/Hydra/Controller/User.pm at line 234
    [4.25578][4.25578:25594]()
    sub edit_POST {
    [4.25578]
    [4.25594]
    sub edit_DELETE {
  • edit in src/lib/Hydra/Controller/User.pm at line 236
    [4.25619][4.25619:25620]()
  • replacement in src/lib/Hydra/Controller/User.pm at line 238
    [4.25655][4.25655:25694]()
    $c->stash->{template} = 'user.tt';
    [4.25655]
    [4.25694]
    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;
  • replacement in src/lib/Hydra/Controller/User.pm at line 242
    [4.25695][4.25695:25781]()
    $c->session->{referer} = $c->request->referer if !defined $c->session->{referer};
    [4.25695]
    [4.25781]
    $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};
  • replacement in src/lib/Hydra/Controller/User.pm at line 255
    [4.25782][4.25782:25843](),[4.25843][4.2286:2357](),[4.2286][4.2286:2357]()
    if (($c->stash->{params}->{submit} // "") eq "delete") {
    deleteUser($self, $c, $user);
    backToReferer($c);
    }
    [4.25782]
    [4.2357]
    requirePost($c);
  • replacement in src/lib/Hydra/Controller/User.pm at line 257
    [4.2358][4.25844:25913](),[4.25913][4.64:150](),[4.150][4.2427:3040](),[4.207][4.2427:3040](),[4.25913][4.2427:3040](),[4.2427][4.2427:3040]()
    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;
    }
    [4.2358]
    [4.3040]
    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;
  • replacement in src/lib/Hydra/Controller/User.pm at line 261
    [4.3095][4.3095:3137](),[4.3137][2.1666:1704](),[2.1704][4.3956:3964](),[4.3956][4.3956:3964]()
    txn_do($c->model('DB')->schema, sub {
    updatePreferences($c, $user);
    });
    [4.3041]
    [4.3964]
    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"
    );
  • replacement in src/lib/Hydra/Controller/User.pm at line 272
    [4.3965][4.26184:26227](),[4.26227][4.266:339](),[4.339][4.26227:26311](),[4.26227][4.26227:26311]()
    if ($c->request->looks_like_browser) {
    $c->flash->{successMsg} = "Your preferences have been updated.";
    backToReferer($c);
    } else {
    $self->status_no_content($c);
    }
    [4.3965]
    [4.3413]
    $c->flash->{successMsg} = "A new password has been sent to ${\$user->emailaddress}.";
    $self->status_no_content($c);
  • edit in src/root/static/js/common.js at line 148
    [22.3901]
    function backToReferrer() {
    // FIXME: should only do this if the referrer is another Hydra
    // page.
    window.location = document.referrer;
    }
  • replacement in src/root/user.tt at line 1
    [4.4561][4.5348:5441]()
    [% WRAPPER layout.tt title=(create ? "Register new user" : "Editing user $user.username") %]
    [4.4561]
    [4.4648]
    [% WRAPPER layout.tt title=(create ? "Add new user" : "Editing user $user.username") %]
  • replacement in src/root/user.tt at line 17
    [4.5207][4.4861:4906]()
    <form class="form-horizontal" method="post">
    [4.5207]
    [4.4906]
    <form class="form-horizontal">
  • replacement in src/root/user.tt at line 33
    [4.5305][4.4568:4668]()
    <input type="text" class="span3" name="fullname" [% HTML.attributes(value => fullname) %]/>
    [4.5305]
    [4.5412]
    <input type="text" class="span3" name="fullname" [% HTML.attributes(value => create ? '' : user.fullname) %]/>
  • replacement in src/root/user.tt at line 63
    [2.2030][2.2030:2171]()
    <input type="checkbox" name="emailonerror" [% IF emailonerror; 'checked="checked"'; END %]/>Receive evaluation error notifications
    [2.2030]
    [2.2171]
    <input type="checkbox" name="emailonerror" [% IF !create && user.emailonerror; 'checked="checked"'; END %]/>Receive evaluation error notifications
  • replacement in src/root/user.tt at line 96
    [4.7280][4.7280:7333]()
    <button type="submit" class="btn btn-primary">
    [4.7280]
    [4.7333]
    <button id="submit-user" class="btn btn-primary">
  • replacement in src/root/user.tt at line 101
    [4.211][4.5647:5759](),[4.898][4.5647:5759](),[4.5647][4.5647:5759]()
    <button id="reset-password" type="submit" class="btn btn-warning" name="submit" value="reset-password">
    [4.898]
    [4.5759]
    <button id="reset-password" class="btn btn-warning">
  • edit in src/root/user.tt at line 105
    [4.5850][4.5850:6700]()
    <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>
  • replacement in src/root/user.tt at line 107
    [4.7476][4.7476:7576]()
    <button id="delete-user" type="submit" class="btn btn-danger" name="submit" value="delete">
    [4.7476]
    [4.7576]
    <button id="delete-user" class="btn btn-danger">
  • edit in src/root/user.tt at line 111
    [4.7669][4.7669:7862]()
    <script type="text/javascript">
    $("#delete-user").click(function() {
    return confirm("Are you sure you want to delete this user?");
    });
    </script>
  • edit in src/root/user.tt at line 118
    [4.6706]
    [4.6706]
    <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>