« lib/Rapi/Blog/DB/Result/PreauthActionEvent.pm
↑ Summary
lib/Rapi/Blog/Controller/Remote/PreauthAction.pm »
| 1 | package Rapi::Blog::PreAuth::Actor::Login; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | use Moo; | ||
| 6 | extends 'Rapi::Blog::PreAuth::Actor'; | ||
| 7 | |||
| 8 | use Types::Standard qw(:all); | ||
| 9 | |||
| 10 | use RapidApp::Util ':all'; | ||
| 11 | use Rapi::Blog::Util; | ||
| 12 | |||
| 13 | |||
| 14 | |||
| 15 | sub execute { | ||
| 16 | my $self = shift; | ||
| 17 | my $c = RapidApp->active_request_context or die "Unable to get Catlyst context - you're only calling this during a request, right?"; | ||
| 18 | |||
| 19 | #$c->delete_expired_sessions; | ||
| 20 | try{$c->logout}; | ||
| 21 | |||
| 22 | my $BlogUser = $self->PreauthAction->user or die "Failed to get user row."; | ||
| 23 | my $user = $BlogUser->username; | ||
| 24 | |||
| 25 | my $uObj = $c->find_user({ username => $user }) or die "Failed to get Catalyst Auth user object"; | ||
| 26 | |||
| 27 | $c->set_authenticated( $uObj ); | ||
| 28 | |||
| 29 | $c->user or die "->set_authenticated(): unknown error occured"; | ||
| 30 | |||
| 31 | # ----- | ||
| 32 | # This comes directly from Auth::do_login | ||
| 33 | $c->session->{RapidApp_username} = $user; | ||
| 34 | |||
| 35 | # New: set the X-RapidApp-Authenticated header now so the response | ||
| 36 | # itself will reflect the successful login (since in either case, the | ||
| 37 | # immediate response is a simple redirect). This is for client info/debug only | ||
| 38 | $c->res->header('X-RapidApp-Authenticated' => $c->user->username); | ||
| 39 | |||
| 40 | $c->log->info("Successfully authenticated user '$user'") if ($c->debug); | ||
| 41 | $c->user->update({ | ||
| 42 | last_login_ts => DateTime->now( time_zone => 'local' ) | ||
| 43 | }); | ||
| 44 | |||
| 45 | # Something is broken! | ||
| 46 | $c->_save_session_expires; | ||
| 47 | # ----- | ||
| 48 | |||
| 49 | } | ||
| 50 | |||
| 51 | |||
| 52 | |||
| 53 | 1; | ||
| 54 | |||
| 55 | |||
| 56 | __END__ |