source: server/trunk/web/lib/Sophie/Controller/Login.pm @ 306

Last change on this file since 306 was 213, checked in by nanardon, 13 years ago
  • add login/logout to header
File size: 2.1 KB
Line 
1package Sophie::Controller::Login;
2use Moose;
3use namespace::autoclean;
4
5BEGIN {extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9Sophie::Controller::Login - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub index :Path :Args(0) :XMLRPCPath('/login') {
25    my ( $self, $c, $login, $password ) = @_;
26    $login ||= $c->req->param('username');
27    $password ||= $c->req->param('password');
28
29    if ($login) {
30        if ($c->authenticate({
31                mail => $login,
32                password => $password,
33            }
34        )) {
35            if ($c->req->xmlrpc->is_xmlrpc_request) {
36                $c->stash->{xmlrpc} = 'sophie_session=' . $c->sessionid;
37            } else {
38                warn 'redirect';
39                $c->res->redirect($c->uri_for('/'));
40            }
41        } else {
42            if ($c->req->xmlrpc->is_xmlrpc_request) {
43                $c->error('invalid login / password');
44            }
45        }
46    }
47}
48
49sub invit_login : Local {
50    my ($self, $c) = @_;
51
52}
53
54sub logout :Local {
55    my ($self, $c) = @_;
56
57    $c->logout;
58}
59
60sub create :Local {
61    my ($self, $c) = @_;
62
63    warn $c->req->param('valid');
64    warn $c->session->{valid_create_user};
65    if ((my $valid = $c->req->param('valid')) && $c->req->param('username')) {
66       if ($valid == $c->session->{valid_create_user}) {
67           my $res = $c->forward('/admin/create_user',
68               [
69                   $c->req->param('username'),
70                   $c->req->param('password'),
71               ]
72            );
73            if ($res) {
74               $c->res->redirect($c->uri_for('/login',
75                   { username => $c->req->param('username') }
76               ));
77           }
78       }
79    }
80    my $aa = (0 .. 9)[rand(9)];
81    my $bb = (0 .. 9)[rand(9)];
82    $c->stash->{valid} = "$aa + $bb";
83    $c->session->{valid_create_user} = $aa + $bb;
84
85}
86
87=head1 AUTHOR
88
89Olivier Thauvin
90
91=head1 LICENSE
92
93This library is free software. You can redistribute it and/or modify
94it under the same terms as Perl itself.
95
96=cut
97
98__PACKAGE__->meta->make_immutable;
99
1001;
Note: See TracBrowser for help on using the repository browser.