rsstootalizer/RSSTootalizer/User.pm

48 lines
991 B
Perl
Raw Normal View History

2017-04-21 14:56:24 +00:00
# vim: set foldmarker={,}:
use strict;
2017-04-23 18:51:48 +00:00
use RSSTootalizer::Base;
2017-04-21 14:56:24 +00:00
2017-04-23 18:51:48 +00:00
package RSSTootalizer::User;
@RSSTootalizer::User::ISA = qw(RSSTootalizer::Base);
2017-04-21 14:56:24 +00:00
use JSON;
2017-04-23 18:51:48 +00:00
use RSSTootalizer::Token;
2017-04-21 14:56:24 +00:00
use Data::Dumper;
2017-04-22 20:22:55 +00:00
sub dbTable :lvalue { "users"; }
sub orderBy :lvalue { "username"; }
2017-04-21 14:56:24 +00:00
# Class functions
sub authenticate {
my $class = shift;
2017-04-22 20:22:55 +00:00
my $session_id = $main::FORM{session_id};
return 0 unless defined($session_id);
my $user = $class->get_by("session_id", $session_id);
return 0 unless $user;
my $instance = $user->{data}->{instance};
my $token = $user->{data}->{access_token};
2017-04-21 14:56:24 +00:00
if ($token){
2017-04-21 19:45:58 +00:00
open(DATA, "./verify_credentials.bash '$token' '$instance'|");
2017-04-21 14:56:24 +00:00
my $reply;
{
2017-04-23 19:24:03 +00:00
local $/ = undef;
2017-04-21 14:56:24 +00:00
$reply = <DATA>
}
close DATA;
$reply = decode_json($reply);
#{"error":"The access token is invalid"}
2017-04-22 20:22:55 +00:00
if (!defined($$reply{username})){
2017-04-21 14:56:24 +00:00
return 0;
}
2017-04-22 20:22:55 +00:00
$reply->{token} = $token;
$reply->{instance} = $instance;
2017-04-21 14:56:24 +00:00
return $class->new($reply);
}
return 0;
}
# Object methods
1;