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

Last change on this file since 422 was 415, checked in by nanardon, 13 years ago
  • use numeric needupdate flag, then detect if another has been request
File size: 2.0 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                $c->res->redirect($c->uri_for('/'));
39            }
40        } else {
41            if ($c->req->xmlrpc->is_xmlrpc_request) {
42                $c->error('invalid login / password');
43            }
44        }
45    }
46}
47
48sub invit_login : Local {
49    my ($self, $c) = @_;
50
51}
52
53sub logout :Local {
54    my ($self, $c) = @_;
55
56    $c->logout;
57}
58
59sub create :Local {
60    my ($self, $c) = @_;
61
62    warn $c->req->param('valid');
63    warn $c->session->{valid_create_user};
64    if ((my $valid = $c->req->param('valid')) && $c->req->param('username')) {
65       if ($valid == $c->session->{valid_create_user}) {
66           my $res = $c->forward('/admin/create_user',
67               [
68                   $c->req->param('username'),
69                   $c->req->param('password'),
70               ]
71            );
72            if ($res) {
73               $c->res->redirect($c->uri_for('/login',
74                   { username => $c->req->param('username') }
75               ));
76           }
77       }
78    }
79    my $aa = (0 .. 9)[rand(9)];
80    my $bb = (0 .. 9)[rand(9)];
81    $c->stash->{valid} = "$aa + $bb";
82    $c->session->{valid_create_user} = $aa + $bb;
83
84}
85
86=head1 AUTHOR
87
88Olivier Thauvin
89
90=head1 LICENSE
91
92This library is free software. You can redistribute it and/or modify
93it under the same terms as Perl itself.
94
95=cut
96
97__PACKAGE__->meta->make_immutable;
98
991;
Note: See TracBrowser for help on using the repository browser.