Add basic Persona support

[?]
Jul 8, 2013, 9:54 PM
36ZTCZ4FDV6ILURQEIGFHCP57ALZH6OWYNN3MBXG2QXZSBULBPMAC

Dependencies

  • [2] 7KF7YZDR Disable account creation for now
  • [3] RFGPN7U7 Machine status: Don't show removed machines anymore
  • [4] S5GCSCNS Update bootstrap to 2.3.1
  • [5] DV43UILU Don't float the search bar to the right in collapsed mode
  • [6] LZVO64YG Merge in the first bits of the API work
  • [7] QL55ECJ6 - adapted ui for hydra, more in line with nixos.org website
  • [8] UICHT2PS Add a search feature
  • [9] OEPUOUNB Using twitter bootstrap for more consistent looks for Hydra
  • [10] JARRBLZD Bootstrapify the Hydra forms (except the project and jobset edit pages)
  • [11] XJRJ4J7M Add user registration
  • [12] HTL6HIBM machine-status: Read /etc/nix.machines instead of using the BuildMachines table
  • [13] BZUB3ZSH Use get_column for 'as' column (max_stoptime).
  • [*] J5UVLXOK * Start of a basic Catalyst web interface.
  • [*] PZL3SZM3 Give every page a consistent title
  • [*] HRAFVVOE make logo configurable via HYDRA_LOGO env var
  • [*] RU7AQO7U * Role-based access control. Only admins can create projects. Only

Change contents

  • replacement in src/lib/Hydra/Controller/Root.pm at line 138
    [7.352][3.397:402]()
    [7.352]
    [7.352]
  • edit in src/lib/Hydra/Controller/User.pm at line 11
    [7.435]
    [7.435]
    use LWP::UserAgent;
    use JSON;
  • edit in src/lib/Hydra/Controller/User.pm at line 73
    [6.24932]
    [7.1420]
    sub persona_login :Path('/persona-login') Args(0) {
    my ($self, $c) = @_;
    $c->stash->{json} = {};
    die if $c->request->method ne "POST";
    my $assertion = $c->req->params->{assertion} or die;
    my $ua = new LWP::UserAgent;
    my $response = $ua->post(
    'https://verifier.login.persona.org/verify',
    { assertion => $assertion,
    audience => "http://localhost:3000/"
    });
    Catalyst::Exception->throw("Did not get a response from Persona.") unless $response->is_success;
  • edit in src/lib/Hydra/Controller/User.pm at line 90
    [7.1421]
    [6.24933]
    my $d = decode_json($response->decoded_content) or die;
    Catalyst::Exception->throw("Persona says: $d->{reason}") if $d->{status} ne "okay";
  • edit in src/lib/Hydra/Controller/User.pm at line 93
    [6.24934]
    [7.1421]
    my $email = $d->{email} or die;
    my $user = $c->find_user({ username => $email });
    if (!$user) {
    $c->model('DB::Users')->create(
    { username => $email
    , password => "!"
    , emailaddress => $email,
    });
    $user = $c->find_user({ username => $email }) or die;
    }
    $c->set_authenticated($user);
    $c->stash->{json}->{result} = "ok";
    }
  • edit in src/root/layout.tt at line 13
    [16.2897]
    [17.618]
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
  • replacement in src/root/layout.tt at line 100
    [7.9312][7.9312:9375]()
    You are logged in as <tt>[% c.user.username %]</tt>.
    [7.9312]
    [7.9375]
    You are logged in as <tt>[% HTML.escape(c.user.username) %]</tt>.
  • edit in src/root/layout.tt at line 106
    [15.11729]
    [7.7485]
    <script src="https://login.persona.org/include.js"></script>
    <script>
    navigator.id.watch({
    loggedInUser: [% c.user_exists ? '"' _ HTML.escape(c.user.username) _ '"' : "null" %],
    onlogin: function(assertion) {
    $.post("[% c.uri_for('/persona-login') %]", { assertion: assertion })
    .done(function(data) {
    if (data.error)
    bootbox.alert("Login failed: " + data.error);
    else
    window.location.reload();
    })
    .fail(function() { bootbox.alert("Server request failed!"); });
    },
    onlogout: function() {
    $.ajax({
    type: 'POST',
    url: '/logout',
    success: function(res, status, xhr) { window.location.reload(); },
    error: function(xhr, status, err) { alert("Logout failure: " + err); }
    });
    }
    });
  • edit in src/root/layout.tt at line 132
    [7.7486]
    [15.11729]
    $("#persona-signin").click(function() {
    navigator.id.request();
    });
    $("#persona-signout").click(function() {
    navigator.id.logout();
    });
    </script>
  • edit in src/root/login.tt at line 15
    [2.42][7.4401:4408](),[7.4401][7.4401:4408]()
    <br/>
  • edit in src/root/login.tt at line 16
    [7.4409]
    [7.9805]
    <!--
  • edit in src/root/login.tt at line 40
    [18.5199]
    [18.5199]
    -->
  • replacement in src/root/topbar.tt at line 3
    [4.448][7.6753:6793](),[7.10536][7.6753:6793](),[7.6753][7.6753:6793]()
    <a href="[% uri %]">[% title %]</a>
    [4.448]
    [7.6811]
    <a [% HTML.attributes(href => uri) %]>[% title %]</a>
  • replacement in src/root/topbar.tt at line 201
    [5.193][5.193:298]()
    [% INCLUDE menuItem uri = c.uri_for(c.controller('Root').action_for('logout')) title = "Sign out" %]
    [5.193]
    [5.298]
    <li>
    <a href="#" id="persona-signout">Sign out</a>
    </li>
  • replacement in src/root/topbar.tt at line 205
    [5.311][5.311:414]()
    [% INCLUDE menuItem uri = c.uri_for(c.controller('Root').action_for('login')) title = "Sign in" %]
    [5.311]
    [5.414]
    <li>
    <a href="#" id="persona-signin">Sign in</a>
    </li>