package My::Mailserver::Controller::Dashboard; use Mojo::Base 'Mojolicious::Controller'; sub index { my $c = shift; $c->stash->{domain} = $c->current_user->domain; $c->stash->{aliases} = $c->schema->resultset('VirtualAlias')->search( { destination => $c->current_user->email }, { order_by => 'source' } ); $c->stash->{recovery_email} = $c->current_user->recovery_email; } sub change_password { my $c = shift; my $v = $c->validation; $v->csrf_protect; $v->required('current_password'); $v->required('new_password'); $v->required('confirm_password'); if ($v->is_valid) { if ($c->current_user->check_password($v->param('current_password'))) { if ($v->param('new_password') eq $v->param('confirm_password')) { $c->current_user->password($v->param('new_password')); $c->current_user->update; $c->flash(success => 'Password changed successfully'); } else { $c->flash(error => 'New and Confirm password must match'); } } else { $c->flash(error => 'Current password incorrect'); } } else { $c->app->log->debug('invalid form'); $c->flash(error => 'All form fields required'); } $c->redirect_to('/dashboard'); } sub change_recovery { my $c = shift; my $v = $c->validation; $v->csrf_protect; $v->required('recovery_email'); if ($v->is_valid) { $c->current_user->recovery_email($v->param('recovery_email')); $c->current_user->update; $c->flash(success => 'Recovery email changed successfully'); } else { $c->flash(error => 'Failed to change recovery email'); } $c->redirect_to('/dashboard'); } 1;