Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
a7dff12e
Commit
a7dff12e
authored
Feb 08, 2019
by
Robert Czechowski
Browse files
Implement timeout in all session request
parent
c6e67f89
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/db_conn_sqlite.rs
View file @
a7dff12e
...
...
@@ -7,7 +7,9 @@ use db_objects::*;
use
rand
::{
thread_rng
,
Rng
,
distributions
::
Alphanumeric
};
use
time
;
use
self
::
time
::{
Timespec
,
Duration
};
use
std
::
path
::{
Path
};
...
...
@@ -82,8 +84,20 @@ impl MedalConnection for Connection {
}
});
match
res
{
Ok
(
session
)
=>
Some
(
session
),
_
=>
None
Ok
(
session
)
=>
{
let
duration
=
if
session
.permanent_login
{
Duration
::
days
(
90
)
}
else
{
Duration
::
minutes
(
90
)
};
let
now
=
time
::
get_time
();
if
now
-
session
.last_activity
?
<
duration
{
self
.execute
(
"UPDATE session_user SET last_activity = ?1 WHERE id = ?2"
,
&
[
&
now
,
&
session
.id
])
.unwrap
();
Some
(
session
)
}
else
{
// Session timed out
// Should remove session token from session_user
None
}
},
_
=>
None
// no session found, should create new session in get_session_or_new()
}
}
fn
save_session
(
&
self
,
session
:
SessionUser
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment