New method to retrieve admin_status; add is_admin to session

This commit is contained in:
swag 2023-01-09 19:24:08 -05:00
parent 1607a0a7d5
commit c34b07c129
2 changed files with 19 additions and 7 deletions

View File

@ -37,8 +37,6 @@ sub login($self) {
$v = $self->validation if $self->req->method eq 'POST'; $v = $self->validation if $self->req->method eq 'POST';
if ($v && $v->has_data) { if ($v && $v->has_data) {
my ($email, $password, $mod_id, $mod_name);
$v->required('email' ); $v->required('email' );
$v->required('password'); $v->required('password');
@ -46,16 +44,22 @@ sub login($self) {
$self->stash(status => 400) $self->stash(status => 400)
} }
else { else {
my ($email, $password);
$email = $self->param('email' ); $email = $self->param('email' );
$password = $self->param('password'); $password = $self->param('password');
if ($self->moderator->check($email, $password)) { if ($self->moderator->check($email, $password)) {
my ($mod_id, $mod_name, $admin_status);
$mod_id = $self->moderator->get_id($email); $mod_id = $self->moderator->get_id($email);
$mod_name = $self->moderator->get_name($mod_id); $mod_name = $self->moderator->get_name($mod_id);
$admin_status = $self->moderator->admin_status($mod_id);
$self->session( $self->session(
mod_id => $mod_id, mod_id => $mod_id,
author => $mod_name author => $mod_name,
is_admin => $admin_status
); );
$self->flash(info => "Hello, $mod_name 😎"); $self->flash(info => "Hello, $mod_name 😎");
$self->moderator->login_timestamp($mod_id); $self->moderator->login_timestamp($mod_id);
@ -66,7 +70,7 @@ sub login($self) {
$self->stash( $self->stash(
status => 403, status => 403,
error => 'Invalid login! 🧐' error => 'Invalid login! 🧐'
); )
} }
} }
} }

View File

@ -53,6 +53,14 @@ sub unlock($self, $mod_id) {
END_SQL END_SQL
} }
sub admin_status($self, $mod_id) {
$self->pg->db->query(<<~'END_SQL', $mod_id)->hash->{'admin_status'}
SELECT admin_status
FROM moderators
WHERE moderator_id = ?;
END_SQL
}
sub get_id($self, $email) { sub get_id($self, $email) {
$self->pg->db->query(<<~'END_SQL', $email)->hash->{'moderator_id'} $self->pg->db->query(<<~'END_SQL', $email)->hash->{'moderator_id'}
SELECT moderator_id SELECT moderator_id