|
Revision 7674, 1.6 kB
(checked in by vkgtaro, 5 years ago)
|
|
lang/perl/Chaostr: remove CP::FormValidator::Simple
|
| Line | |
|---|
| 1 | package Chaostr::Web::Controller::Login; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use base 'Catalyst::Controller'; |
|---|
| 6 | |
|---|
| 7 | =head1 NAME |
|---|
| 8 | |
|---|
| 9 | Chaostr::Web::Controller::Login - Catalyst Controller |
|---|
| 10 | |
|---|
| 11 | =head1 DESCRIPTION |
|---|
| 12 | |
|---|
| 13 | Catalyst Controller. |
|---|
| 14 | |
|---|
| 15 | =head1 METHODS |
|---|
| 16 | |
|---|
| 17 | =cut |
|---|
| 18 | |
|---|
| 19 | =head2 index |
|---|
| 20 | |
|---|
| 21 | =cut |
|---|
| 22 | |
|---|
| 23 | sub index : Local { |
|---|
| 24 | my ( $self, $c ) = @_; |
|---|
| 25 | |
|---|
| 26 | if ( $c->user_exists ) { |
|---|
| 27 | $c->res->redirect( $c->uri_for(q{/}) ); |
|---|
| 28 | return; |
|---|
| 29 | } |
|---|
| 30 | return if $c->req->method eq 'GET'; |
|---|
| 31 | |
|---|
| 32 | $c->authenticate( |
|---|
| 33 | { name => $c->req->param('username'), |
|---|
| 34 | password => $c->req->param('password') |
|---|
| 35 | } |
|---|
| 36 | ); |
|---|
| 37 | |
|---|
| 38 | if ( !$c->user_exists ) { |
|---|
| 39 | # ログインできてなかった場合 |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | if ( $c->req->param('auto') ) { |
|---|
| 43 | $c->session->{auto_login} = 1; |
|---|
| 44 | |
|---|
| 45 | # 2 週間 |
|---|
| 46 | $c->session_expire_key( __user => 1_209_600 ); |
|---|
| 47 | } |
|---|
| 48 | else { |
|---|
| 49 | $c->session->{auto_login} = 0; |
|---|
| 50 | |
|---|
| 51 | # 2 時間 |
|---|
| 52 | $c->session_expire_key( __user => 7_200 ); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | $c->log->info( $c->user->name . '(' . $c->req->address . ') logined' ); |
|---|
| 56 | $c->model('DBIC::User')->find( $c->user->id ) |
|---|
| 57 | ->update( { lastlogin_at => $c->datetime() } ); |
|---|
| 58 | |
|---|
| 59 | return $c->res->redirect( $c->uri_for(q{/}) ); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | =head2 logout |
|---|
| 63 | |
|---|
| 64 | =cut |
|---|
| 65 | |
|---|
| 66 | sub logout : Global { |
|---|
| 67 | my ( $self, $c ) = @_; |
|---|
| 68 | |
|---|
| 69 | if ( $c->user ) { |
|---|
| 70 | $c->log->info( $c->user->name . '(' . $c->req->address . ') logout' ); |
|---|
| 71 | $c->logout; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | return $c->res->redirect( $c->uri_for(q{/}) ); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | =head1 AUTHOR |
|---|
| 78 | |
|---|
| 79 | Daisuke Komatsu C<< <taro __at__ cpan.org> >> |
|---|
| 80 | |
|---|
| 81 | =head1 LICENSE |
|---|
| 82 | |
|---|
| 83 | This library is free software, you can redistribute it and/or modify |
|---|
| 84 | it under the same terms as Perl itself. |
|---|
| 85 | |
|---|
| 86 | =cut |
|---|
| 87 | |
|---|
| 88 | 1; |
|---|
| 89 | |
|---|