[][src]Struct sudoku_backend::ops::Session

pub struct Session {
    pub id: Option<i32>,
    pub expiry: NaiveDateTime,
    pub is_admin: bool,
    pub user_id: Option<i32>,
    pub sudoku_board_id: Option<i32>,
    pub board_skeleton: Option<Cow<'static, str>>,
    pub solve_start: Option<NaiveDateTime>,
}

Refer to doc/session.md for more details.

Fields

Unique user ID.

Actually not optional, but this allows us to get an ID from the database.

Time the cookie expires, defaults to a day from creation time.

Whether the user is logged in as admin (always false if user_id == None).

The logged-in user ID, or None for unauthed access.

ID of board currently being solved

The board skeleton sent to the user

Time the solving started

Methods

impl Session
[src]

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.

Get/create a session for the specified cookieset.

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)),
});

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,
});

Check if this session has a game going

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);

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 Clone for Session
[src]

Performs copy-assignment from source. Read more

impl Ord for Session
[src]

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl Eq for Session
[src]

impl PartialOrd<Session> for Session
[src]

impl Debug for Session
[src]

impl Hash for Session
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Serialize for Session
[src]

impl<'de> Deserialize<'de> for Session
[src]

impl<'insert> Insertable<table> for Session
[src]

The VALUES clause to insert these records Read more

Insert self into a given table. Read more

impl<'insert> Insertable<table> for &'insert Session
[src]

The VALUES clause to insert these records Read more

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]

The Rust type you'd like to map from. Read more

impl<'update> AsChangeset for &'update Session
[src]

The table which Self::Changeset will be updating

The update statement this type represents

impl<'update> AsChangeset for Session
[src]

The table which Self::Changeset will be updating

The update statement this type represents

impl<'insert> UndecoratedInsertRecord<table> for Session
[src]

Auto Trait Implementations

impl Send for Session

impl Sync for Session

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> Typeable for T where
    T: Any
[src]

Get the TypeId of this object.

impl<T> IntoSql for T
[src]

Convert self to an expression for Diesel's query builder. Read more

Convert &self to an expression for Diesel's query builder. Read more