mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
server: Add an SQL table to store password reset tokens
This commit is contained in:
parent
35d0cc0fb0
commit
88732556c1
@ -21,6 +21,15 @@ pub enum JwtStorage {
|
|||||||
Blacklisted,
|
Blacklisted,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Contains the temporary tokens to reset the password, sent by email.
|
||||||
|
#[derive(Iden)]
|
||||||
|
pub enum PasswordResetTokens {
|
||||||
|
Table,
|
||||||
|
Token,
|
||||||
|
UserId,
|
||||||
|
ExpiryDate,
|
||||||
|
}
|
||||||
|
|
||||||
/// This needs to be initialized after the domain tables are.
|
/// This needs to be initialized after the domain tables are.
|
||||||
pub async fn init_table(pool: &Pool) -> sqlx::Result<()> {
|
pub async fn init_table(pool: &Pool) -> sqlx::Result<()> {
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
@ -95,5 +104,38 @@ pub async fn init_table(pool: &Pool) -> sqlx::Result<()> {
|
|||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
sqlx::query(
|
||||||
|
&Table::create()
|
||||||
|
.table(PasswordResetTokens::Table)
|
||||||
|
.if_not_exists()
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(PasswordResetTokens::Token)
|
||||||
|
.string_len(255)
|
||||||
|
.not_null()
|
||||||
|
.primary_key(),
|
||||||
|
)
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(PasswordResetTokens::UserId)
|
||||||
|
.string_len(255)
|
||||||
|
.not_null(),
|
||||||
|
)
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(PasswordResetTokens::ExpiryDate)
|
||||||
|
.date_time()
|
||||||
|
.not_null(),
|
||||||
|
)
|
||||||
|
.foreign_key(
|
||||||
|
ForeignKey::create()
|
||||||
|
.name("PasswordResetTokensUserForeignKey")
|
||||||
|
.table(PasswordResetTokens::Table, Users::Table)
|
||||||
|
.col(PasswordResetTokens::UserId, Users::UserId)
|
||||||
|
.on_delete(ForeignKeyAction::Cascade)
|
||||||
|
.on_update(ForeignKeyAction::Cascade),
|
||||||
|
)
|
||||||
|
.to_string(DbQueryBuilder {}),
|
||||||
|
)
|
||||||
|
.execute(pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user