7 TestApp->config( $ENV{TESTAPP_CONFIG} );
9 TestApp->setup( @{$ENV{TESTAPP_PLUGINS}} );
11 sub user_login : Global {
12 my ( $self, $c ) = @_;
14 ## this allows anyone to login regardless of status.
16 $c->authenticate({ username => $c->request->params->{'username'},
17 password => $c->request->params->{'password'}
21 return $c->res->body($@);
24 if ( $c->user_exists ) {
25 if ( $c->req->params->{detach} ) {
26 $c->detach( $c->req->params->{detach} );
28 $c->res->body( $c->user->get('username') . ' logged in' );
31 $c->res->body( 'not logged in' );
36 sub notdisabled_login : Global {
37 my ( $self, $c ) = @_;
39 $c->authenticate({ username => $c->request->params->{'username'},
40 password => $c->request->params->{'password'},
41 status => [ 'active', 'registered' ]
44 if ( $c->user_exists ) {
45 if ( $c->req->params->{detach} ) {
46 $c->detach( $c->req->params->{detach} );
48 $c->res->body( $c->user->get('username') . ' logged in' );
51 $c->res->body( 'not logged in' );
55 sub searchargs_login : Global {
56 my ( $self, $c ) = @_;
58 my $username = $c->request->params->{'username'} || '';
59 my $email = $c->request->params->{'email'} || '';
62 password => $c->request->params->{'password'},
64 searchargs => [ { "-or" => [ username => $username,
66 { prefetch => qw/ map_user_role /}
71 if ( $c->user_exists ) {
72 if ( $c->req->params->{detach} ) {
73 $c->detach( $c->req->params->{detach} );
75 $c->res->body( $c->user->get('username') . ' logged in' );
78 $c->res->body( 'not logged in' );
82 sub resultset_login : Global {
83 my ( $self, $c ) = @_;
85 my $username = $c->request->params->{'username'} || '';
86 my $email = $c->request->params->{'email'} || '';
89 my $rs = $c->model('TestApp::User')->search({ "-or" => [ username => $username,
93 password => $c->request->params->{'password'},
94 dbix_class => { resultset => $rs }
97 if ( $c->user_exists ) {
98 if ( $c->req->params->{detach} ) {
99 $c->detach( $c->req->params->{detach} );
101 $c->res->body( $c->user->get('username') . ' logged in' );
104 $c->res->body( 'not logged in' );
108 sub bad_login : Global {
109 my ( $self, $c ) = @_;
111 ## this allows anyone to login regardless of status.
113 $c->authenticate({ william => $c->request->params->{'username'},
114 the_bum => $c->request->params->{'password'}
118 return $c->res->body($@);
121 if ( $c->user_exists ) {
122 if ( $c->req->params->{detach} ) {
123 $c->detach( $c->req->params->{detach} );
125 $c->res->body( $c->user->get('username') . ' logged in' );
128 $c->res->body( 'not logged in' );
132 ## need to add a resultset login test and a search args login test
134 sub user_logout : Global {
135 my ( $self, $c ) = @_;
140 $c->res->body( 'logged out' );
143 $c->res->body( 'not logged ok' );
147 sub get_session_user : Global {
148 my ( $self, $c ) = @_;
150 if ( $c->user_exists ) {
151 $c->res->body($c->user->get('username')); # . " " . Dumper($c->user->get_columns()) );
155 sub is_admin : Global {
156 my ( $self, $c ) = @_;
159 if ( $c->assert_user_roles( qw/admin/ ) ) {
160 $c->res->body( 'ok' );
164 $c->res->body( 'failed' );
168 sub is_admin_user : Global {
169 my ( $self, $c ) = @_;
172 if ( $c->assert_user_roles( qw/admin user/ ) ) {
173 $c->res->body( 'ok' );
177 $c->res->body( 'failed' );
181 sub set_usersession : Global {
182 my ( $self, $c, $value ) = @_;
183 $c->user_session->{foo} = $value;
184 $c->res->body( 'ok' );
187 sub get_usersession : Global {
188 my ( $self, $c ) = @_;
189 $c->res->body( $c->user_session->{foo} || '' );