[−][src]Struct sudoku_backend::ops::Session
Refer to doc/session.md
for more details.
Fields
id: Option<i32>
Unique user ID.
Actually not optional, but this allows us to get an ID from the database.
expiry: NaiveDateTime
Time the cookie expires, defaults to a day from creation time.
is_admin: bool
Whether the user is logged in as admin (always false
if user_id == None
).
user_id: Option<i32>
The logged-in user ID, or None
for unauthed access.
sudoku_board_id: Option<i32>
ID of board currently being solved
board_skeleton: Option<Cow<'static, str>>
The board skeleton sent to the user
solve_start: Option<NaiveDateTime>
Time the solving started
Methods
impl Session
[src]
impl Session
pub fn new() -> Session
[src]
pub fn new() -> Session
Create an empty session expiring a day from the creation datetime.
Put it in the database to get an ID to put back in the cookie.
pub fn get(
db: &SqliteConnection,
cookies: &mut Cookies
) -> Result<Session, &'static str>
[src]
pub fn get(
db: &SqliteConnection,
cookies: &mut Cookies
) -> Result<Session, &'static str>
Get/create a session for the specified cookieset.
pub fn start_game<S: Into<Cow<'static, str>>>(
&mut self,
bid: i32,
skeleton: S,
db: &SqliteConnection
) -> Result<(), &'static str>
[src]
pub fn start_game<S: Into<Cow<'static, str>>>(
&mut self,
bid: i32,
skeleton: S,
db: &SqliteConnection
) -> Result<(), &'static str>
Update the in-memory and in-DB model to start playing the specified game.
Examples
let mut sess = Session { id: Some(32), expiry: NaiveDate::from_ymd(2018, 7, 9).and_hms(12, 40, 26), is_admin: false, user_id: None, sudoku_board_id: None, board_skeleton: None, solve_start: None, }; let skeleton = "3....5....25.81.........6......4..73.3....14..1.7......8...9.12.97........2..8.54"; sess.start_game(24, skeleton, &db).unwrap(); assert_eq!(sess, Session { id: Some(32), expiry: NaiveDate::from_ymd(2018, 7, 9).and_hms(12, 40, 26), is_admin: false, user_id: None, sudoku_board_id: Some(24), board_skeleton: Some(skeleton.into()), solve_start: Some(NaiveDateTime::from_timestamp(Utc::now().timestamp(), 0)), });
pub fn stop_game(&mut self, db: &SqliteConnection) -> Result<(), &'static str>
[src]
pub fn stop_game(&mut self, db: &SqliteConnection) -> Result<(), &'static str>
Update the in-memory and in-DB model to start playing the specified game.
Examples
let mut sess = Session { id: Some(32), expiry: NaiveDate::from_ymd(2018, 7, 9).and_hms(12, 40, 26), is_admin: false, user_id: None, sudoku_board_id: Some(24), board_skeleton: Some("3....5....25.81.........6......4..73.3....14..1.7......8...9.12.97........2..8.54".into()), solve_start: Some(NaiveDate::from_ymd(2018, 7, 9).and_hms(2, 41, 27)), }; sess.stop_game(&db).unwrap(); assert_eq!(sess, Session { id: Some(32), expiry: NaiveDate::from_ymd(2018, 7, 9).and_hms(12, 40, 26), is_admin: false, user_id: None, sudoku_board_id: None, board_skeleton: None, solve_start: None, });
pub fn game_started(&self) -> bool
[src]
pub fn game_started(&self) -> bool
Check if this session has a game going
pub fn log_in(
&mut self,
uid: i32,
is_admin: bool,
db: &SqliteConnection
) -> Result<(), &'static str>
[src]
pub fn log_in(
&mut self,
uid: i32,
is_admin: bool,
db: &SqliteConnection
) -> Result<(), &'static str>
Update the in-memory and in-DB model to be logged in as the specified user with the specified permissions.
Examples
Before:
INSERT INTO "sessions" VALUES(32, '2018-07-09 12:40:26', 0, NULL, NULL, NULL, NULL);
Update:
let mut sess = Session { id: Some(32), expiry: NaiveDate::from_ymd(2018, 7, 9).and_hms(12, 40, 26), is_admin: false, user_id: None, sudoku_board_id: None, board_skeleton: None, solve_start: None, }; sess.log_in(18, true, &db).unwrap(); assert_eq!(sess, Session { id: Some(32), expiry: NaiveDate::from_ymd(2018, 7, 9).and_hms(12, 40, 26), is_admin: true, user_id: Some(18), sudoku_board_id: None, board_skeleton: None, solve_start: None, });
After:
INSERT INTO "sessions" VALUES(32, '2018-07-09 12:40:26', 1, 18, NULL, NULL, NULL);
pub fn log_out(&mut self, db: &SqliteConnection) -> Result<(), &'static str>
[src]
pub fn log_out(&mut self, db: &SqliteConnection) -> Result<(), &'static str>
Update the in-memory and in-DB model to not be logged in nor be admin.
Examples
Before:
INSERT INTO "sessions" VALUES(32, '2018-07-09 12:40:26', 1, 18, NULL, NULL, NULL);
Update:
let mut sess = Session { id: Some(32), expiry: NaiveDate::from_ymd(2018, 7, 9).and_hms(12, 40, 26), is_admin: true, user_id: Some(18), sudoku_board_id: None, board_skeleton: None, solve_start: None, }; sess.log_out(&db).unwrap(); assert_eq!(sess, Session { id: Some(32), expiry: NaiveDate::from_ymd(2018, 7, 9).and_hms(12, 40, 26), is_admin: false, user_id: None, sudoku_board_id: None, board_skeleton: None, solve_start: None, });
After:
INSERT INTO "sessions" VALUES(32, '2018-07-09 12:40:26', 0, NULL, NULL, NULL, NULL);
Trait Implementations
impl PartialEq<Session> for Session
[src]
impl PartialEq<Session> for Session
impl Clone for Session
[src]
impl Clone for Session
fn clone(&self) -> Session
[src]
fn clone(&self) -> Session
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Ord for Session
[src]
impl Ord for Session
fn cmp(&self, other: &Session) -> Ordering
[src]
fn cmp(&self, other: &Session) -> Ordering
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl Eq for Session
[src]
impl Eq for Session
impl PartialOrd<Session> for Session
[src]
impl PartialOrd<Session> for Session
fn partial_cmp(&self, other: &Session) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Session) -> Option<Ordering>
fn lt(&self, other: &Session) -> bool
[src]
fn lt(&self, other: &Session) -> bool
fn le(&self, other: &Session) -> bool
[src]
fn le(&self, other: &Session) -> bool
fn gt(&self, other: &Session) -> bool
[src]
fn gt(&self, other: &Session) -> bool
fn ge(&self, other: &Session) -> bool
[src]
fn ge(&self, other: &Session) -> bool
impl Debug for Session
[src]
impl Debug for Session
impl Hash for Session
[src]
impl Hash for Session
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Serialize for Session
[src]
impl Serialize for Session
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
impl<'de> Deserialize<'de> for Session
[src]
impl<'de> Deserialize<'de> for Session
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
impl<'insert> Insertable<table> for Session
[src]
impl<'insert> Insertable<table> for Session
type Values = <(Option<Eq<id, i32>>, Option<Eq<expiry, NaiveDateTime>>, Option<Eq<is_admin, bool>>, Option<Eq<user_id, i32>>, Option<Eq<sudoku_board_id, i32>>, Option<Eq<board_skeleton, Cow<'static, str>>>, Option<Eq<solve_start, NaiveDateTime>>) as Insertable<table>>::Values
The VALUES
clause to insert these records Read more
fn values(self) -> Self::Values
[src]
fn values(self) -> Self::Values
fn insert_into(
self,
table: T
) -> InsertStatement<T, Self::Values, Insert, NoReturningClause>
[src]
fn insert_into(
self,
table: T
) -> InsertStatement<T, Self::Values, Insert, NoReturningClause>
Insert self
into a given table. Read more
impl<'insert> Insertable<table> for &'insert Session
[src]
impl<'insert> Insertable<table> for &'insert Session
type Values = <(Option<Eq<id, &'insert i32>>, Option<Eq<expiry, &'insert NaiveDateTime>>, Option<Eq<is_admin, &'insert bool>>, Option<Eq<user_id, &'insert i32>>, Option<Eq<sudoku_board_id, &'insert i32>>, Option<Eq<board_skeleton, &'insert Cow<'static, str>>>, Option<Eq<solve_start, &'insert NaiveDateTime>>) as Insertable<table>>::Values
The VALUES
clause to insert these records Read more
fn values(self) -> Self::Values
[src]
fn values(self) -> Self::Values
fn insert_into(
self,
table: T
) -> InsertStatement<T, Self::Values, Insert, NoReturningClause>
[src]
fn insert_into(
self,
table: T
) -> InsertStatement<T, Self::Values, Insert, NoReturningClause>
Insert self
into a given table. Read more
impl<__DB: Backend, __ST> Queryable<__ST, __DB> for Session where
(Option<i32>, NaiveDateTime, bool, Option<i32>, Option<i32>, Option<Cow<'static, str>>, Option<NaiveDateTime>): Queryable<__ST, __DB>,
[src]
impl<__DB: Backend, __ST> Queryable<__ST, __DB> for Session where
(Option<i32>, NaiveDateTime, bool, Option<i32>, Option<i32>, Option<Cow<'static, str>>, Option<NaiveDateTime>): Queryable<__ST, __DB>,
type Row = <(Option<i32>, NaiveDateTime, bool, Option<i32>, Option<i32>, Option<Cow<'static, str>>, Option<NaiveDateTime>) as Queryable<__ST, __DB>>::Row
The Rust type you'd like to map from. Read more
fn build(row: Self::Row) -> Self
[src]
fn build(row: Self::Row) -> Self
impl<'update> AsChangeset for &'update Session
[src]
impl<'update> AsChangeset for &'update Session
type Target = table
The table which Self::Changeset
will be updating
type Changeset = <(Eq<expiry, &'update NaiveDateTime>, Eq<is_admin, &'update bool>, Eq<user_id, &'update Option<i32>>, Eq<sudoku_board_id, &'update Option<i32>>, Eq<board_skeleton, &'update Option<Cow<'static, str>>>, Eq<solve_start, &'update Option<NaiveDateTime>>) as AsChangeset>::Changeset
The update statement this type represents
fn as_changeset(self) -> Self::Changeset
[src]
fn as_changeset(self) -> Self::Changeset
impl<'update> AsChangeset for Session
[src]
impl<'update> AsChangeset for Session
type Target = table
The table which Self::Changeset
will be updating
type Changeset = <(Eq<expiry, NaiveDateTime>, Eq<is_admin, bool>, Eq<user_id, Option<i32>>, Eq<sudoku_board_id, Option<i32>>, Eq<board_skeleton, Option<Cow<'static, str>>>, Eq<solve_start, Option<NaiveDateTime>>) as AsChangeset>::Changeset
The update statement this type represents
fn as_changeset(self) -> Self::Changeset
[src]
fn as_changeset(self) -> Self::Changeset
impl<'insert> UndecoratedInsertRecord<table> for Session
[src]
impl<'insert> UndecoratedInsertRecord<table> for Session
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
impl<T> Typeable for T where
T: Any,
[src]
impl<T> Typeable for T where
T: Any,
impl<T> IntoSql for T
[src]
impl<T> IntoSql for T
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
[src]
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
Convert self
to an expression for Diesel's query builder. Read more
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
[src]
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
Convert &self
to an expression for Diesel's query builder. Read more