1 | package Sophie::Controller::Login; |
---|
2 | use Moose; |
---|
3 | use namespace::autoclean; |
---|
4 | |
---|
5 | BEGIN {extends 'Catalyst::Controller'; } |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | Sophie::Controller::Login - Catalyst Controller |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Catalyst Controller. |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | |
---|
20 | =head2 index |
---|
21 | |
---|
22 | =cut |
---|
23 | |
---|
24 | sub 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 | |
---|
48 | sub invit_login : Local { |
---|
49 | my ($self, $c) = @_; |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | sub logout :Local { |
---|
54 | my ($self, $c) = @_; |
---|
55 | |
---|
56 | $c->logout; |
---|
57 | } |
---|
58 | |
---|
59 | sub 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 | |
---|
88 | Olivier Thauvin |
---|
89 | |
---|
90 | =head1 LICENSE |
---|
91 | |
---|
92 | This library is free software. You can redistribute it and/or modify |
---|
93 | it under the same terms as Perl itself. |
---|
94 | |
---|
95 | =cut |
---|
96 | |
---|
97 | __PACKAGE__->meta->make_immutable; |
---|
98 | |
---|
99 | 1; |
---|