summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Controller/Account.pm
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-07-24 20:50:12 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-07-24 20:50:12 +0200
commit2759d7258c37c7498905cfe19f6b4c4f6d16bd21 (patch)
treeed91dcab1818f66aefa664da0224d32bb61f7508 /lib/Travelynx/Controller/Account.pm
parent7811520a30657e2bc98873f296ae1f8fcff51dc0 (diff)
support non-DB HAFAS backends (WiP)
Diffstat (limited to 'lib/Travelynx/Controller/Account.pm')
-rw-r--r--lib/Travelynx/Controller/Account.pm46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/Travelynx/Controller/Account.pm b/lib/Travelynx/Controller/Account.pm
index 5c101b1..b7b2b78 100644
--- a/lib/Travelynx/Controller/Account.pm
+++ b/lib/Travelynx/Controller/Account.pm
@@ -999,6 +999,52 @@ sub password_form {
$self->render('change_password');
}
+sub backend_form {
+ my ($self) = @_;
+ my $user = $self->current_user;
+
+ my @backends = $self->stations->get_backends;
+
+ for my $backend (@backends) {
+ my $type = 'UNKNOWN';
+ if ( $backend->{iris} ) {
+ $type = 'IRIS-TTS';
+ $backend->{name} = 'DB';
+ }
+ elsif ( $backend->{hafas} ) {
+ $type = 'HAFAS';
+ $backend->{longname}
+ = $self->hafas->get_service( $backend->{name} )->{name};
+ }
+ $backend->{type} = $type;
+ }
+
+ $self->render(
+ 'select_backend',
+ backends => \@backends,
+ user => $user,
+ redirect_to => $self->req->param('redirect_to') // '/',
+ );
+}
+
+sub change_backend {
+ my ($self) = @_;
+
+ my $backend_id = $self->req->param('backend');
+ my $redir = $self->req->param('redirect_to') // '/';
+
+ if ( $backend_id !~ m{ ^ \d+ $ }x ) {
+ $self->redirect_to($redir);
+ }
+
+ $self->users->set_backend(
+ uid => $self->current_user->{id},
+ backend_id => $backend_id,
+ );
+
+ $self->redirect_to($redir);
+}
+
sub change_password {
my ($self) = @_;
my $old_password = $self->req->param('oldpw');