Subject: | Patches: Auth store, OpenId support |
Patches to support OpenId logins and use the Auth store instead of models
(and dbic assumptions)
Subject: | 0001-Replace-use-of-c-model-with-c-get_auth_realm-.-store.patch |
From 95b73caaf70ce49354ef0808c8093380b319955d Mon Sep 17 00:00:00 2001
From: Jess Robinson <j.robinson@shadowcat.co.uk>
Date: Fri, 11 May 2012 16:46:19 +0000
Subject: [PATCH 1/4] Replace use of $c->model with $c->get_auth_realm(..)->store
---
lib/CatalystX/Controller/Auth.pm | 38 +++++++++++++++++++++++++++-----------
1 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/lib/CatalystX/Controller/Auth.pm b/lib/CatalystX/Controller/Auth.pm
index 6116e19..18a2cb0 100644
--- a/lib/CatalystX/Controller/Auth.pm
+++ b/lib/CatalystX/Controller/Auth.pm
@@ -26,13 +26,17 @@ use HTML::FormHandlerX::Form::Login;
has form_handler => ( is => 'ro', isa => 'Str', default => 'HTML::FormHandlerX::Form::Login' );
has view => ( is => 'ro', isa => 'Str', default => 'TT' );
-has model => ( is => 'ro', isa => 'Str', default => 'DB::User' );
+# has model => ( is => 'ro', isa => 'Str', default => 'DB::User' );
+
+has realm => ( is => 'ro', isa => 'Str', default => 'default');
has login_id_field => ( is => 'ro', isa => 'Str', default => 'username' );
has login_id_db_field => ( is => 'ro', isa => 'Str', default => 'username' );
has enable_register => ( is => 'ro', isa => 'Bool', default => 1 );
+has send_register_email => ( is => 'ro', isa => 'Bool', default => 1);
+
has register_template => ( is => 'ro', isa => 'Str', default => 'auth/register.tt' );
has login_template => ( is => 'ro', isa => 'Str', default => 'auth/login.tt' );
has change_password_template => ( is => 'ro', isa => 'Str', default => 'auth/change-password.tt' );
@@ -245,21 +249,33 @@ sub register :Chained('base') :PathPart :Args(0)
if ( $form->validated )
{
- if ( $c->model( $self->model )->search( { $self->login_id_db_field => $form->field( $self->login_id_field )->value } )->all )
+ my $auth_store = $c->get_auth_realm($self->realm)->store;
+ if ( $auth_store->find_user( { $self->login_id_db_field => $form->field( $self->login_id_field )->value }, $c ))
{
$c->stash( error_msg => $self->register_exists_failed_message );
}
else
{
- my $user = $c->model( $self->model )->create( { $self->login_id_db_field => $form->field( $self->login_id_field )->value,
- password => $form->field('password')->value,
- } );
-
- $self->_send_register_email( $c, user => $user );
+ my $user;
+ if($auth_store->can('auto_create_user'))
+ {
+ $user = $auth_store->auto_create_user(
+ { $self->login_id_db_field => $form->field( $self->login_id_field )->value,
+
+ password => $form->field('password')->value,
+ }, $c
+ );
+ } else {
+ die "Store " . ref($auth_store) . " does not support auto_create_user!";
+ }
+
+ if($user && $self->send_register_email) {
+ $self->_send_register_email( $c, user => $user );
+ }
if ( $self->auto_login_after_register )
{
- $c->authenticate( { $self->login_id_db_field => $form->field( $self->login_id_field )->value, password => $form->field('password')->value } );
+ $c->authenticate( { $self->login_id_db_field => $form->field( $self->login_id_field )->value, password => $form->field('password')->value }, $self->realm );
}
$self->post_register( $c );
@@ -457,7 +473,7 @@ sub forgot_password :Chained('base') :PathPart('forgot-password') :Args(0)
if ( $form->validated )
{
- my $user = $c->model( $self->model )->find( { $self->login_id_db_field => $c->request->params->{ $self->login_id_field } } );
+ my $user = $c->get_auth_realm($self->realm)->store->find_user( { $self->login_id_db_field => $c->request->params->{ $self->login_id_field } }, $c );
if ( $user )
{
@@ -579,7 +595,7 @@ sub reset_password :Chained('base') :PathPart('reset-password') :Args(0)
if ( $form->validated )
{
- my $user = $c->model( $self->model )->find( { $self->login_id_db_field => $form->field( $self->login_id_field )->value } );
+ my $user = $c->get_auth_realm($self->realm)->store->find_user( { $self->login_id_db_field => $form->field( $self->login_id_field )->value }, $c );
$user->password( $form->field('password')->value );
@@ -658,7 +674,7 @@ sub change_password :Chained('get') :PathPart('change-password') :Args(0)
{
my $user = $c->stash->{ user };
- if ( ! $c->authenticate( { $self->login_id_db_field => $user->email, password => $form->field('old_password')->value } ) )
+ if ( ! $c->authenticate( { $self->login_id_db_field => $user->email, password => $form->field('old_password')->value }, $self->realm ) )
{
$c->stash( error_msg => 'Old password incorrect' );
}
--
1.7.3.5
Subject: | 0003-Allow-frontend-to-specify-which-realm-to-validate-th.patch |
From 2ed85e4e43f67869aa1f74e71a3b7da45b741534 Mon Sep 17 00:00:00 2001
From: Jess Robinson <j.robinson@shadowcat.co.uk>
Date: Tue, 15 May 2012 08:43:54 +0000
Subject: [PATCH 3/4] Allow frontend to specify which realm to validate the login against
---
lib/CatalystX/Controller/Auth.pm | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/CatalystX/Controller/Auth.pm b/lib/CatalystX/Controller/Auth.pm
index 7d4c963..14e0a81 100644
--- a/lib/CatalystX/Controller/Auth.pm
+++ b/lib/CatalystX/Controller/Auth.pm
@@ -26,7 +26,6 @@ use HTML::FormHandlerX::Form::Login;
has form_handler => ( is => 'ro', isa => 'Str', default => 'HTML::FormHandlerX::Form::Login' );
has view => ( is => 'ro', isa => 'Str', default => 'TT' );
-# has model => ( is => 'ro', isa => 'Str', default => 'DB::User' );
has realm => ( is => 'ro', isa => 'Str', default => 'default');
@@ -372,7 +371,8 @@ sub login :Chained('base') :PathPart :Args(0)
return;
}
- my $fields = $self->login_fields->{$self->realm};
+ my $realm = $c->req->param('realm') || $self->realm;
+ my $fields = $self->login_fields->{$realm};
my $form = $self->form_handler->new( active => $fields );
## openid returns with GET params!
@@ -384,7 +384,7 @@ sub login :Chained('base') :PathPart :Args(0)
if ( $form->validated )
{
my $authinfo = { map { $_ => $form->field($_) } @$fields };
- if ( $c->authenticate( $authinfo, $self->realm)
+ if ( $c->authenticate( $authinfo, $realm)
)
{
if ( $c->req->params->{ remember } )
--
1.7.3.5
Subject: | 0004-Support-openid-better-special-case-the-return-visit-.patch |
From 492670738a114e7dc03c423d863cd52a7d165796 Mon Sep 17 00:00:00 2001
From: Jess Robinson <j.robinson@shadowcat.co.uk>
Date: Tue, 15 May 2012 09:57:16 +0000
Subject: [PATCH 4/4] Support openid better (special-case the return visit to login)
Fix bug with passing values to authenticate
---
lib/CatalystX/Controller/Auth.pm | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/lib/CatalystX/Controller/Auth.pm b/lib/CatalystX/Controller/Auth.pm
index 14e0a81..62c90cd 100644
--- a/lib/CatalystX/Controller/Auth.pm
+++ b/lib/CatalystX/Controller/Auth.pm
@@ -373,6 +373,10 @@ sub login :Chained('base') :PathPart :Args(0)
my $realm = $c->req->param('realm') || $self->realm;
my $fields = $self->login_fields->{$realm};
+ if($c->req->param('openid-check')) {
+ ## Returning from openid login, no fields in form for this yet
+ $fields = [];
+ }
my $form = $self->form_handler->new( active => $fields );
## openid returns with GET params!
@@ -383,7 +387,7 @@ sub login :Chained('base') :PathPart :Args(0)
if ( $form->validated )
{
- my $authinfo = { map { $_ => $form->field($_) } @$fields };
+ my $authinfo = { map { $_ => $form->field($_)->value } @$fields };
if ( $c->authenticate( $authinfo, $realm)
)
{
--
1.7.3.5
Subject: | 0002-Attempt-to-support-openid-as-well-as-local-login-reg.patch |
From 87f10447d87abcb7b707c3869704c35ee563577e Mon Sep 17 00:00:00 2001
From: Jess Robinson <j.robinson@shadowcat.co.uk>
Date: Tue, 15 May 2012 08:27:10 +0000
Subject: [PATCH 2/4] Attempt to support openid as well as local login/register
- Support multiple realms, specify sets of login fields to activate
(display?)
---
lib/CatalystX/Controller/Auth.pm | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/lib/CatalystX/Controller/Auth.pm b/lib/CatalystX/Controller/Auth.pm
index 18a2cb0..7d4c963 100644
--- a/lib/CatalystX/Controller/Auth.pm
+++ b/lib/CatalystX/Controller/Auth.pm
@@ -30,6 +30,9 @@ has view => ( is => 'ro', isa => 'Str', default
has realm => ( is => 'ro', isa => 'Str', default => 'default');
+has login_fields => ( is => 'ro', isa => 'HashRef', default => sub { { default => [ qw/username password/ ] } });
+
+
has login_id_field => ( is => 'ro', isa => 'Str', default => 'username' );
has login_id_db_field => ( is => 'ro', isa => 'Str', default => 'username' );
@@ -369,15 +372,20 @@ sub login :Chained('base') :PathPart :Args(0)
return;
}
- my $form = $self->form_handler->new( active => [ $self->login_id_field, 'password' ] );
-
- if ( $c->req->method eq 'POST' )
+ my $fields = $self->login_fields->{$self->realm};
+ my $form = $self->form_handler->new( active => $fields );
+
+## openid returns with GET params!
+# if ( $c->req->method) # eq 'POST' )
+ if( $c->req->param && $c->req->param > 1 ) # at least 2 as we have the "mid" param..
{
$form->process( params => $c->request->params );
if ( $form->validated )
{
- if ( $c->authenticate( { $self->login_id_db_field => $form->field( $self->login_id_field )->value, password => $form->field('password')->value } ) )
+ my $authinfo = { map { $_ => $form->field($_) } @$fields };
+ if ( $c->authenticate( $authinfo, $self->realm)
+ )
{
if ( $c->req->params->{ remember } )
{
--
1.7.3.5