Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding a ``remember this site'' checkbox

  • Loading branch information...
commit 894e5eb7504033941c614a41ed1357aa03a48d84 1 parent a6320d3
@nelhage authored
View
2  etc/config.yml
@@ -12,7 +12,7 @@ framework:
Password: ''
RecordBaseClass: Jifty::DBI::Record::Cachable
User: ''
- Version: 0.0.1
+ Version: 0.0.2
DevelMode: 0
L10N:
PoDir: share/po
View
4 lib/AuthMitEdu.pm
@@ -10,8 +10,8 @@ our $server;
sub start {
$server = Net::OpenID::Server->new(
get_user => \&AuthMitEdu::Model::User::remote_user,
- is_identity => \&AuthMitEdu::Model::User::is_identity,
- is_trusted => \&AuthMitEdu::Model::User::is_trusted,
+ is_identity => sub {0},
+ is_trusted => sub {0},
setup_url => Jifty->web->url( path => '/_/setup' ),
);
View
13 lib/AuthMitEdu/Action/SetupAuth.pm
@@ -20,15 +20,28 @@ use Jifty::Action schema {
param assoc_handle => render as 'hidden';
param trust_root => render as 'hidden';
+ param remember => render as 'checkbox',
+ label is 'Remember this site';
+
param action => type is 'text',
valid are qw(yes no);
};
+sub since {'0.0.2'};
+
sub take_action {
my $self = shift;
my $action = $self->argument_value('action');
+ if($self->argument_value('remember')) {
+ my $trust = $action eq 'yes';
+ my $root = AuthMitEdu::Model::TrustRoot->new;
+ $root->create(identity => Jifty->web->current_user->user_object,
+ trust_root => $self->argument_value('trust_root'),
+ trust => $trust);
+ }
+
if($action eq 'yes') {
my %args;
$args{$_} = $self->argument_value($_)
View
12 lib/AuthMitEdu/Dispatcher.pm
@@ -39,8 +39,18 @@ on qr{^/_/auth/?$} => run {
my %opts = %$data;
set $_ => $opts{$_} for keys %opts;
+ my $trust_root = $opts{trust_root};
+
redirect '/error/no_cert' unless $user;
- redirect '/error/bad_identity/' . $opts{identity} unless $user->is_identity($opts{identity});
+ redirect '/error/bad_identity/' . $opts{identity}
+ unless $user->is_identity($opts{identity});
+
+ if($user->trusts_root($trust_root)) {
+ Jifty->web->_redirect($AuthMitEdu::server->signed_return_url(%opts));
+ } elsif($user->never_trusts_root($trust_root)) {
+ Jifty->web->_redirect(
+ $AuthMitEdu::server->cancel_return_url(return_to => $opts{return_to}));
+ }
show 'setup';
View
20 lib/AuthMitEdu/Model/TrustRoot.pm
@@ -0,0 +1,20 @@
+use strict;
+use warnings;
+
+package AuthMitEdu::Model::TrustRoot;
+use Jifty::DBI::Schema;
+
+use AuthMitEdu::Record schema {
+ column identity => refers_to AuthMitEdu::Model::User;
+
+ column trust_root => type is 'text',
+ render_as 'Trust root';
+
+ column trust => type is 'int';
+};
+
+use Jifty::RightsFrom column => 'identity';
+
+# Your model-specific methods go here.
+
+1;
View
31 lib/AuthMitEdu/Model/User.pm
@@ -4,11 +4,15 @@ use warnings;
package AuthMitEdu::Model::User;
use Jifty::DBI::Schema;
use URI;
-use Email::Address;
+use Data::Dumper;
use AuthMitEdu::Record schema {
- column username =>
- type is 'text';
+ column username => type is 'text';
+ column name => type is 'text';
+
+ column trust_roots =>
+ refers_to AuthMitEdu::Model::TrustRootCollection by 'identity',
+ since '0.0.2';
};
# Your model-specific methods go here.
@@ -26,14 +30,27 @@ sub remote_user {
sub is_identity {
my ($self, $url) = @_;
- return 0 unless $self;
$url = URI->new($url);
return $url->path eq '/' . $self->username;
}
-sub is_trusted {
+sub trusts_root {
+ my ($self, $root) = @_;
+ my $troot = $self->root($root);
+ return $troot->id && $troot->trust;
+}
+
+sub never_trusts_root {
my ($self, $root) = @_;
- return 0;
+ my $troot = $self->root($root);
+ return $troot->id && !$troot->trust;
+}
+
+sub root {
+ my ($self, $root) = (@_);
+ my $troot = AuthMitEdu::Model::TrustRoot->new;
+ $troot->load_by_cols(identity => $self, trust_root => $root);
+ return $troot;
}
sub name {return shift->username;}
@@ -46,7 +63,7 @@ sub current_user_can {
if($right eq 'read') {
return 1;
- } elsif($right eq 'write' && $self->id eq $self->current_user->id) {
+ } elsif($right eq 'update' && $self->id eq $self->current_user->id) {
return 1;
}
return $self->SUPER::current_user_can($right, @_);
View
8 lib/AuthMitEdu/View.pm
@@ -35,7 +35,9 @@ template setup => page {
my $action = Jifty->web->new_action(class => 'SetupAuth');
p {
outs("The site ");
- a {{href is "$root"} $root};
+ div {{class is "trust_root"}
+ a {{href is "$root"} $root};
+ };
outs("would like you verify your identity ($identity). " .
"Do you want to allow them?");
};
@@ -47,6 +49,8 @@ template setup => page {
default_value => get $_);
}
+ render_param($action => 'remember');
+
outs_raw($action->button(
label => "Yes",
arguments => { action => 'yes' },
@@ -63,7 +67,7 @@ template '/error/no_cert' => page {
outs("You do not seem to have an MIT Certificate. See IS&T's ");
a {{ href is "http://web.mit.edu/ist/topics/certificates/index.html"}
"certificate information page"};
- outs("for more information about how to obtain one.");
+ outs("for information about how to obtain one.");
}
};

0 comments on commit 894e5eb

Please sign in to comment.
Something went wrong with that request. Please try again.