1 package SGN
::Controller
::AJAX
::Authenticate
;
8 use CXGN
::People
::Login
;
10 BEGIN { extends
'Catalyst::Controller::REST' }
13 default => 'application/json',
15 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
18 sub authenticate_cookie
: Path
('/authenticate/check/token') : ActionClass
('REST') { }
21 sub authenticate_cookie_GET
{
24 my $sgn_session_id = $c->req->param("cookie");
26 my $dbh = $c->dbc->dbh;
27 my $cookie_info = CXGN
::Login
->new($dbh)->query_from_cookie($sgn_session_id);
32 #my $person_id = CXGN::Login->new($dbh)->has_session();
33 #my $p = CXGN::People::Login->new($dbh, $person_id);
34 #my @user_info = ({person_id=>$p->get_sp_person_id(), username=>$p->get_username(), role=>$p->get_roles()});
37 my $q = "SELECT sp_person_id, username, first_name, last_name FROM sgn_people.sp_person WHERE cookie_string=?";
38 my $sth = $dbh->prepare($q);
39 if ($sth->execute($sgn_session_id)) {
40 while (my ($person_id, $username, $first_name, $last_name) = $sth->fetchrow_array ) {
41 push(@user_info_list, ($person_id, $username, $first_name, $last_name));
45 my $q = "SELECT name FROM sgn_people.sp_person_roles JOIN sgn_people.sp_person as p using(sp_person_id) JOIN sgn_people.sp_roles using(sp_role_id) WHERE p.cookie_string=?";
46 my $sth = $dbh->prepare($q);
47 if ($sth->execute($sgn_session_id)) {
48 while (my ($user_type) = $sth->fetchrow_array ) {
49 push(@user_roles_list, ($user_type));
51 @user_info = {person_id
=>$user_info_list[0], username
=>$user_info_list[1], first_name
=>$user_info_list[2], last_name
=>$user_info_list[3], roles
=>\
@user_roles_list};
55 $status = 'Roles Not Found For User';
58 $status = 'Could Not Get User Info';
61 $status = 'No Valid Cookie';
64 my %result = (status
=>$status, result
=>\
@user_info);
66 $c->stash->{rest
} = \
%result;