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.
15 $c->authenticate({ username
=> $c->request->params->{'username'},
16 password
=> $c->request->params->{'password'}
19 if ( $c->user_exists ) {
20 if ( $c->req->params->{detach
} ) {
21 $c->detach( $c->req->params->{detach
} );
23 $c->res->body( $c->user->get('username') . ' logged in' );
26 $c->res->body( 'not logged in' );
30 sub notdisabled_login
: Global
{
31 my ( $self, $c ) = @_;
33 $c->authenticate({ username
=> $c->request->params->{'username'},
34 password
=> $c->request->params->{'password'},
35 status
=> [ 'active', 'registered' ]
38 if ( $c->user_exists ) {
39 if ( $c->req->params->{detach
} ) {
40 $c->detach( $c->req->params->{detach
} );
42 $c->res->body( $c->user->get('username') . ' logged in' );
45 $c->res->body( 'not logged in' );
49 sub searchargs_login
: Global
{
50 my ( $self, $c ) = @_;
52 my $username = $c->request->params->{'username'} || '';
53 my $email = $c->request->params->{'email'} || '';
56 password
=> $c->request->params->{'password'},
58 searchargs
=> [ { "-or" => [ username
=> $username,
60 { prefetch
=> qw
/ map_user_role /}
65 if ( $c->user_exists ) {
66 if ( $c->req->params->{detach
} ) {
67 $c->detach( $c->req->params->{detach
} );
69 $c->res->body( $c->user->get('username') . ' logged in' );
72 $c->res->body( 'not logged in' );
76 sub resultset_login
: Global
{
77 my ( $self, $c ) = @_;
79 my $username = $c->request->params->{'username'} || '';
80 my $email = $c->request->params->{'email'} || '';
83 my $object = $c->model( 'User' )->search(
86 username
=> $username,
94 password
=> $c->request->params->{'password'},
95 rdbo
=> { object
=> $object }
98 if ( $c->user_exists ) {
99 if ( $c->req->params->{detach
} ) {
100 $c->detach( $c->req->params->{detach
} );
102 $c->res->body( $c->user->get('username') . ' logged in' );
105 $c->res->body( 'not logged in' );
109 ## need to add a resultset login test and a search args login test
111 sub user_logout
: Global
{
112 my ( $self, $c ) = @_;
117 $c->res->body( 'logged out' );
120 $c->res->body( 'not logged ok' );
124 sub get_session_user
: Global
{
125 my ( $self, $c ) = @_;
127 if ( $c->user_exists ) {
128 $c->res->body($c->user->get('username')); # . " " . Dumper($c->user->get_columns()) );
132 sub is_admin
: Global
{
133 my ( $self, $c ) = @_;
136 if ( $c->assert_user_roles( qw
/admin/ ) ) {
137 $c->res->body( 'ok' );
141 $c->res->body( 'failed' );
145 sub is_admin_user
: Global
{
146 my ( $self, $c ) = @_;
149 if ( $c->assert_user_roles( qw
/admin user/ ) ) {
150 $c->res->body( 'ok' );
154 $c->res->body( 'failed' );
158 sub set_usersession
: Global
{
159 my ( $self, $c, $value ) = @_;
160 $c->user_session->{foo
} = $value;
161 $c->res->body( 'ok' );
164 sub get_usersession
: Global
{
165 my ( $self, $c ) = @_;
166 $c->res->body( $c->user_session->{foo
} || '' );