1 package TestApp::Controller::Root;
5 no warnings "uninitialized";
6 use base 'Catalyst::Controller';
7 use Net::OpenID::Server;
9 __PACKAGE__->config->{namespace} = '';
13 TestApp::Controller::Root - Root Controller for TestApp.
17 D'er... testing. Has an OpenID provider to test the OpenID credential against.
21 sub provider : Local {
22 my ( $self, $c, $username ) = @_;
24 my $nos = Net::OpenID::Server
26 get_args => $c->req->query_params,
27 post_args => $c->req->body_params,
28 get_user => sub { $c->user },
30 my ( $user, $identity_url ) = @_;
32 my ( $check ) = $identity_url =~ /(\w+)\z/;
33 return $check eq $user->id; # simple auth here
36 my ( $user, $trust_root, $is_identity ) = @_;
37 return $is_identity; # enough that they passed is_identity
39 setup_url => $c->uri_for($c->req->path, {moo => "setup"}),
40 server_secret => $c->config->{startup_time},
43 # From your OpenID server endpoint:
45 my ( $type, $data ) = $nos->handle_page;
47 if ($type eq "redirect")
49 $c->res->redirect($data);
51 elsif ($type eq "setup")
53 my %setup_opts = %{$data};
55 You're not signed in so you can't be verified.
56 <a href="/login">Sign in</a> | <a href="/signin_openid">OpenId</a>.
58 # it's then your job to redirect them at the end to "return_to"
59 # (or whatever you've named it in setup_map)
63 $c->res->content_type($type);
66 my $server_uri = $c->uri_for($c->req->path);
67 $data =~ s,(?=</head>),<link rel="openid.server" href="$server_uri" />,;
75 $c->logout if $c->user_exists;
77 $c->res->redirect($c->uri_for("/"));
83 if ( $c->req->method eq 'POST'
85 $c->authenticate({ username => $c->req->body_params->{username},
86 password => $c->req->body_params->{password} }) )
88 # $c->res->body("You are signed in!");
89 $c->res->redirect($c->uri_for("/"));
93 my $action = $c->req->uri->path;
95 <html><head/><body><form name="login" action="$action" method="POST">
96 <input type="text" name="username" />
97 <input type="password" name="password" />
98 <input type="submit" value="Sign in" />
105 sub signin_openid : Local {
108 if ( $c->authenticate({}, "openid") )
110 $c->res->body("You did it with OpenID!");
114 my $action = $c->req->uri->path;
116 <form action="$action" method="GET" name="openid">
117 <input type="text" name="openid_identifier" class="openid" size="50" />
118 <input type="submit" value="Sign in with OpenID" />
124 sub default : Private {
125 my ( $self, $c ) = @_;
129 $c->user ? "" : "not",
131 $c->user ? ( $c->user->id || %{$c->user} ) : '<a href="/login">Sign in</a> | <a href="/signin_openid">OpenId</a>.'
136 sub not_a_valid_openid_uri : Global {
137 my ( $self, $c ) = @_;
138 $c->response->body("OPENID. UR DOIN IT RONG.");
141 sub i_can_has_tarpit : Global {
142 my ( $self, $c ) = @_;
144 $c->response->content_type("text/html");
145 # Expect an arbitrary, biggish amount of content; it's a lie.
146 $c->response->headers->header("Content-length" => 1_024 * 100);
147 # Do this for 30 seconds; tests will timeout at 10 or 15.
148 sleep 1 && $c->response->write("sucker\n") for 1 .. 30;
152 my ( $self, $c ) = @_;
153 $c->response->content_type("text/html") unless $c->response->content_type;
158 This library is free software, you can redistribute it and modify
159 it under the same terms as Perl itself.
164 package TestApp::Controller::Root;
168 no warnings "uninitialized";
169 use base 'Catalyst::Controller';
170 use Net::OpenID::Server;
172 __PACKAGE__->config->{namespace} = '';
176 TestApp::Controller::Root - Root Controller for TestApp.
180 D'er... testing. Has an OpenID provider to test the OpenID credential against.
184 sub provider : Local {
185 my ( $self, $c, $username ) = @_;
187 my $nos = Net::OpenID::Server
189 get_args => $c->req->query_params,
190 post_args => $c->req->body_params,
191 get_user => sub { $c->user },
193 my ( $user, $identity_url ) = @_;
195 my ( $check ) = $identity_url =~ /(\w+)\z/;
196 return $check eq $user->id; # simple auth here
199 my ( $user, $trust_root, $is_identity ) = @_;
200 return $is_identity; # enough that they passed is_identity
202 setup_url => $c->uri_for($c->req->path, {moo => "setup"}),
203 server_secret => $c->config->{startup_time},
206 # From your OpenID server endpoint:
208 my ( $type, $data ) = $nos->handle_page;
210 if ($type eq "redirect")
212 $c->res->redirect($data);
214 elsif ($type eq "setup")
216 my %setup_opts = %{$data};
218 You're not signed in so you can't be verified.
219 <a href="/login">Sign in</a> | <a href="/signin_openid">OpenId</a>.
221 # it's then your job to redirect them at the end to "return_to"
222 # (or whatever you've named it in setup_map)
226 $c->res->content_type($type);
229 my $server_uri = $c->uri_for($c->req->path);
230 $data =~ s,(?=</head>),<link rel="openid.server" href="$server_uri" />,;
232 $c->res->body($data);
238 $c->logout if $c->user_exists;
239 $c->delete_session();
240 $c->res->redirect($c->uri_for("/"));
246 if ( $c->req->method eq 'POST'
248 $c->authenticate({ username => $c->req->body_params->{username},
249 password => $c->req->body_params->{password} }) )
251 # $c->res->body("You are signed in!");
252 $c->res->redirect($c->uri_for("/"));
256 my $action = $c->req->uri->path;
258 <html><head/><body><form name="login" action="$action" method="POST">
259 <input type="text" name="username" />
260 <input type="password" name="password" />
261 <input type="submit" value="Sign in" />
268 sub signin_openid : Local {
271 if ( $c->authenticate({}, "openid") )
273 $c->res->body("You did it with OpenID!");
277 my $action = $c->req->uri->path;
279 <form action="$action" method="GET" name="openid">
280 <input type="text" name="openid_identifier" class="openid" size="50" />
281 <input type="submit" value="Sign in with OpenID" />
287 sub default : Private {
288 my ( $self, $c ) = @_;
292 $c->user ? "" : "not",
294 $c->user ? ( $c->user->id || %{$c->user} ) : '<a href="/login">Sign in</a> | <a href="/signin_openid">OpenId</a>.'
300 my ( $self, $c ) = @_;
301 $c->response->content_type("text/html");
306 This library is free software, you can redistribute it and modify
307 it under the same terms as Perl itself.