diff options
Diffstat (limited to 'lib/Travelynx/Model/Users.pm')
-rw-r--r-- | lib/Travelynx/Model/Users.pm | 18 |
1 files changed, 18 insertions, 0 deletions
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; |