Session verification-related changes
This commit is contained in:
parent
cf91c02ba0
commit
6cf65a8edd
|
@ -106,36 +106,41 @@ sub startup {
|
||||||
$self->helper(session_verify => sub {
|
$self->helper(session_verify => sub {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
# get info from user's session cookie and store it in vars
|
|
||||||
my $_user_id = $self->session('user_id');
|
|
||||||
my $_session_key = $self->session('session_key');
|
|
||||||
|
|
||||||
my $_validity = 1;
|
my $_validity = 1;
|
||||||
my $_catch_error;
|
my $_catch_error;
|
||||||
|
|
||||||
try {
|
# get info from user's session cookie and store it in vars
|
||||||
# check to see if session with this id is present in db
|
my $_user_id = $self->session('user_id');
|
||||||
($self->schema->resultset('Session')->search
|
my $_session_key = $self->session('session_key');
|
||||||
({ 'session_key' => $_session_key })
|
my $_is_auth = $self->session('is_auth');
|
||||||
->get_column('session_key')->first)
|
|
||||||
or die;
|
|
||||||
|
|
||||||
# check to see if the current session key's user id matches
|
if ($_is_auth) {
|
||||||
# that of the user id in the database
|
try {
|
||||||
$_user_id == ($self->schema->resultset('Session')->
|
# check to see if session with this id is present in db
|
||||||
session_uid($_session_key))
|
($self->schema->resultset('Session')->search
|
||||||
or die;
|
({ 'session_key' => $_session_key })
|
||||||
|
->get_column('session_key')->first)
|
||||||
# check if session is still within valid time as recorded in
|
or die;
|
||||||
# the db
|
|
||||||
time < ($self->schema->resultset('Session')->
|
# check to see if the current session key's user id matches
|
||||||
session_expiry($_session_key))
|
# that of the user id in the database
|
||||||
|
$_user_id == ($self->schema->resultset('Session')->
|
||||||
|
session_uid($_session_key))
|
||||||
or die;
|
or die;
|
||||||
} catch ($_catch_error) {
|
|
||||||
$_validity = undef;
|
# check if session is still within valid time as recorded in
|
||||||
$self->session_destroy;
|
# the db
|
||||||
|
time < ($self->schema->resultset('Session')->
|
||||||
|
session_expiry($_session_key))
|
||||||
|
or die;
|
||||||
|
} catch ($_catch_error) {
|
||||||
|
$_validity = undef;
|
||||||
|
$self->session_destroy;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$_validity = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $_validity;
|
return $_validity;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,10 @@ use Tree::Simple;
|
||||||
sub index {
|
sub index {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
|
if ($self->session_verify eq undef) {
|
||||||
|
$self->redirect_to('/')
|
||||||
|
}
|
||||||
|
|
||||||
$self->render(
|
$self->render(
|
||||||
template => 'index',
|
template => 'index',
|
||||||
category_tree => $self->model('forums')->list_full
|
category_tree => $self->model('forums')->list_full
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
my $userControls;
|
my $userControls;
|
||||||
|
|
||||||
# TODO: once implemented, put username + profile link first
|
# TODO: once implemented, put username + profile link first
|
||||||
if ($self->session('is_auth') == 1) {
|
if ($self->session('is_auth')) {
|
||||||
my $username =
|
my $username = '';
|
||||||
$userControls = "<a href=\"/logout\">logout</a>"}
|
$userControls = "<a href=\"/logout\">logout</a>"}
|
||||||
else {
|
else {
|
||||||
$userControls =
|
$userControls =
|
||||||
|
|
Loading…
Reference in New Issue