Rename url to public_cert_url and use app url for realm
[scpubgit/stemmaweb.git] / lib / stemmaweb / Controller / Users.pm
CommitLineData
19262e3d 1package stemmaweb::Controller::Users;
2use Moose;
3use namespace::autoclean;
4
85990daf 5use Google::JWT;
6
7use JSON::MaybeXS;
8use JSON::WebToken;
9
10use MIME::Base64;
11
19262e3d 12BEGIN {extends 'CatalystX::Controller::Auth'; }
b74843e5 13with 'Catalyst::TraitFor::Controller::reCAPTCHA';
19262e3d 14
15=head1 NAME
16
17stemmaweb::Controller::Users - Catalyst Controller
18
19=head1 DESCRIPTION
20
b74843e5 21The Users controller is based on L<CatalystX::Controller::Auth>, see
22there for most of the functionality. Any localised parts are described
23below.
24
25This controller uses L<Catalyst::TraitFor::Controller::reCAPTCHA> to
26create and check a reCaptcha form shown on the C<register> form to
27help prevent spam signups.
19262e3d 28
29=head1 METHODS
30
31=cut
32
33sub base :Chained('/') :PathPart('') :CaptureArgs(0)
34{
35 my ( $self, $c ) = @_;
1628e97a 36
19262e3d 37 $self->next::method( $c );
38}
39
40=head2 index
41
b74843e5 42The index action is not currently used.
43
19262e3d 44=cut
45
46sub index :Path :Args(0) {
47 my ( $self, $c ) = @_;
48
49 $c->response->body('Matched stemmaweb::Controller::Users in Users.');
50}
51
b74843e5 52=head2 login with openid
53
54Logging in with openid/google requires two passes through the login
55action, on the 2nd pass the C<openid-check> value is passed in when
56the openid providing webserver links the user back to the stemmaweb
eb38afbc 57site. This adaptation to the C<login> action sets the realm we are
b74843e5 58authenticating against to be C<openid> in this case.
59
60=cut
61
b600c671 62before login => sub {
63 my($self, $c) = @_;
64 $c->req->param( realm => 'openid')
65 if $c->req->param('openid-check');
83ed6665 66
67 if ($c->req->params->{email} && $c->req->params->{id_token}) {
68 $c->req->param( realm => 'google');
69 }
b600c671 70};
19262e3d 71
b74843e5 72=head2 register with recaptcha
73
74This adapts the C<register> action to add the recaptcha HTML to the
75page, and verify the recaptcha info entered is correct when the form
76is submitted. If the recaptcha is not correct, we just redisplay the
77form with an error message.
78
79=cut
80
81before register => sub {
82 my ($self, $c) = @_;
83
84 ## Puts HTML into stash in "recaptcha" key.
85 $c->forward('captcha_get');
86
87 ## When submitting, check recaptcha passes, else re-draw form
88 if($c->req->method eq 'POST') {
85990daf 89 if(!$c->forward('captcha_check') || 0 ) {
b74843e5 90 ## Need these two lines to detach, so end can draw the correct template again:
91 my $form = $self->form_handler->new( active => [ $self->login_id_field, 'password', 'confirm_password' ] );
92 $c->stash( template => $self->register_template, form => $form );
93
94 $c->detach();
95 }
96 }
97};
98
eb38afbc 99=head2 success
100
101A stub page returned on login / registration success.
102
103=cut
104
105sub success :Local :Args(0) {
106 my ( $self, $c ) = @_;
107
108 $c->load_status_msgs;
109 $c->stash->{template} = 'auth/success.tt';
110}
111
112=head2 post_logout
113
114Return to the index page, not to the login page.
115
116=cut
117
118sub post_logout {
119 my( $self, $c ) = @_;
120 $c->response->redirect( $c->uri_for_action( '/index' ) );
121 $c->detach;
122}
123
19262e3d 124=head1 AUTHOR
125
126A clever guy
127
128=head1 LICENSE
129
130This library is free software. You can redistribute it and/or modify
131it under the same terms as Perl itself.
132
133=cut
134
135__PACKAGE__->meta->make_immutable;
136
1371;