Skip to content

Commit

Permalink
User is redirected on register form if no account is found (references
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Nov 28, 2014
1 parent 4c76bab commit 3d24d46
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lib/Act/AuthOAuth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use Act::Config;
use Act::User;
use Act::Util;

use Act::TwoStep;

use JSON::XS;
use LWP::UserAgent;
use MIME::Base64;
Expand Down Expand Up @@ -101,18 +103,30 @@ sub oauth_login_callback ($$)

# Match with ACT user
my $user = Act::User->new( email => lc $email );
$user or do { $r->log_error("Unknown user"); return $self->login_form; };

$r->log_error("User found with email $email");
my $destination;

if ($user) {
$r->log_error("User found with email $email");

# user is authenticated - create a session
my $sid = Act::Util::create_session($user);

# user is authenticated - create a session
my $sid = Act::Util::create_session($user);
$self->send_cookie($sid);

$self->send_cookie($sid);
$self->handle_cache;

$destination = $state || "/";
}

$self->handle_cache;
# No corresponding account, redirect on register page
my $token = Act::TwoStep->_create_token($email);
my $data;
my $sth = $Request{dbh}->prepare_cached('INSERT INTO twostep (token, email, datetime, data) VALUES (?, ?, NOW(), ?)');
$sth->execute($token, $email, $data);
$Request{dbh}->commit;

my $destination = $state || "/";
$destination = "register/$token";

$r->header_out("Location" => $destination);

Expand All @@ -135,7 +149,7 @@ This module allows to log user on an OpenID Connect provider.
User click on a link on the login page and is redirected to OpenID Connect Provider. He must
accept to share his information with Act, and is then redirected back. If a user account with
the corresponding email is found in Act, the user is logged in.
the corresponding email is found in Act, the user is logged in. If not, he gets a register form.
=head2 Add the link
Expand Down

0 comments on commit 3d24d46

Please sign in to comment.