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>.'
137 my ( $self, $c ) = @_;
138 $c->response->content_type("text/html");
143 This library is free software, you can redistribute it and modify
144 it under the same terms as Perl itself.