summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Model/Users.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2023-01-22 11:34:53 +0100
committerDaniel Friesel <derf@finalrewind.org>2023-01-22 11:34:53 +0100
commit59e9a24aa63d0209ea301b2c4aa71687e8295be6 (patch)
treec8ead7e0f04abd4ca4090c59d9c7897ba75134b9 /lib/Travelynx/Model/Users.pm
parentaf82c46d576ac7d24801d1851ebcce1eb97390d5 (diff)
move get_api_token to users model
Diffstat (limited to 'lib/Travelynx/Model/Users.pm')
-rw-r--r--lib/Travelynx/Model/Users.pm18
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;