From 59e9a24aa63d0209ea301b2c4aa71687e8295be6 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 22 Jan 2023 11:34:53 +0100 Subject: move get_api_token to users model --- lib/Travelynx/Model/Users.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/Travelynx/Model') diff --git a/lib/Travelynx/Model/Users.pm b/lib/Travelynx/Model/Users.pm index c36fa6d..0287ca2 100644 --- a/lib/Travelynx/Model/Users.pm +++ b/lib/Travelynx/Model/Users.pm @@ -19,6 +19,8 @@ my @sb_templates = ( [ 'bahn.expert/regional', 'https://bahn.expert/regional/{name}#{id}' ], ); +my @token_types = (qw(status history travel import)); + sub new { my ( $class, %opt ) = @_; @@ -86,6 +88,22 @@ sub verify_registration_token { return; } +sub get_api_token { + my ( $self, %opt ) = @_; + my $db = $opt{db} // $self->{pg}->db; + my $uid = $opt{uid}; + + my $token = {}; + my $res = $db->select( 'tokens', [ 'type', 'token' ], { user_id => $uid } ); + + for my $entry ( $res->hashes->each ) { + $token->{ $token_types[ $entry->{type} - 1 ] } + = $entry->{token}; + } + + return $token; +} + sub get_uid_by_name_and_mail { my ( $self, %opt ) = @_; my $db = $opt{db} // $self->{pg}->db; -- cgit v1.2.3