mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 10:26:29 +03:00
make secure_join flow more readable by using and adding a few macros, tiny api changes
This commit is contained in:
@@ -10,20 +10,17 @@ pub const DC_TOKEN_INVITENUMBER: dc_tokennamespc_t = 100;
|
||||
|
||||
// Functions to read/write token from/to the database. A token is any string associated with a key.
|
||||
|
||||
pub fn dc_token_save(
|
||||
context: &Context,
|
||||
namespc: dc_tokennamespc_t,
|
||||
foreign_id: u32,
|
||||
token: &str,
|
||||
) -> bool {
|
||||
pub fn dc_token_save(context: &Context, namespc: dc_tokennamespc_t, foreign_id: u32) -> String {
|
||||
// foreign_id may be 0
|
||||
let token = dc_create_id();
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO tokens (namespc, foreign_id, token, timestamp) VALUES (?, ?, ?, ?);",
|
||||
params![namespc as i32, foreign_id as i32, token, time()],
|
||||
params![namespc as i32, foreign_id as i32, &token, time()],
|
||||
)
|
||||
.is_ok()
|
||||
.ok();
|
||||
token
|
||||
}
|
||||
|
||||
pub fn dc_token_lookup(
|
||||
@@ -39,6 +36,15 @@ pub fn dc_token_lookup(
|
||||
)
|
||||
}
|
||||
|
||||
pub fn dc_token_lookup_or_new(
|
||||
context: &Context,
|
||||
namespc: dc_tokennamespc_t,
|
||||
foreign_id: u32,
|
||||
) -> String {
|
||||
dc_token_lookup(context, namespc, foreign_id)
|
||||
.unwrap_or_else(|| dc_token_save(context, namespc, foreign_id))
|
||||
}
|
||||
|
||||
pub fn dc_token_exists(context: &Context, namespc: dc_tokennamespc_t, token: &str) -> bool {
|
||||
context
|
||||
.sql
|
||||
|
||||
Reference in New Issue
Block a user