seedlot upload with accession synonyms. seedlot upload works to update existing seedlots
[sgn.git] / lib / SGN / Controller / AJAX / Authenticate.pm
blobc75a301a549ab5f97b25280d66b57e06744632f6
1 package SGN::Controller::AJAX::Authenticate;
3 use strict;
4 use Moose;
5 use JSON;
6 use Data::Dumper;
7 use CXGN::Login;
8 use CXGN::People::Login;
10 BEGIN { extends 'Catalyst::Controller::REST' }
12 __PACKAGE__->config(
13 default => 'application/json',
14 stash_key => 'rest',
15 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
18 sub authenticate_cookie : Path('/authenticate/check/token') : ActionClass('REST') { }
21 sub authenticate_cookie_GET {
22 my $self = shift;
23 my $c = shift;
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);
28 my $status;
29 my @user_info = ();
30 my @user_info_list;
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()});
36 if ($cookie_info) {
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));
44 my @user_roles_list;
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};
52 $status = 'OK';
54 } else {
55 $status = 'Roles Not Found For User';
57 } else {
58 $status = 'Could Not Get User Info';
60 } else {
61 $status = 'No Valid Cookie';
64 my %result = (status=>$status, result=>\@user_info);
66 $c->stash->{rest} = \%result;