feat: simplified the signup

This commit is contained in:
silver 2023-07-30 02:50:13 +01:00
parent 970e566dea
commit 63b59432a3
7 changed files with 136 additions and 313 deletions

View file

@ -1,14 +1,17 @@
pub mod methods;
use chrono::{Datelike, SecondsFormat, Utc};
use dotenvy::dotenv;
use ldap3::{LdapConn, Scope, SearchEntry};
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use sqlx::{Error, Pool, Sqlite};
use std::env;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
use chrono::{Datelike, SecondsFormat, Utc};
use rand::distributions::Alphanumeric;
use rand::{Rng, thread_rng};
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use sqlx::{
sqlite::{SqliteConnectOptions, SqlitePoolOptions},
Error, Pool, Sqlite,
};
use std::{
env,
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};
use tide::prelude::*;
#[derive(Debug, Clone, Deserialize, Serialize, sqlx::FromRow)]
@ -19,20 +22,7 @@ pub struct AccountsNew {
pub date_expiry: String,
pub name_first: String,
pub name_surname: String,
}
#[derive(Debug, Deserialize, Serialize, sqlx::FromRow)]
pub struct AccountsPending {
user: String,
mail: String,
cn: String,
sn: String,
auth_code: String,
// action will be what to do with it
action: String,
// will only last for a few hours
expiry: i64,
pub id_student: String,
}
#[derive(Debug, Deserialize, Serialize, sqlx::FromRow)]
@ -53,20 +43,6 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
.connect_with(SqliteConnectOptions::from_str(&format!("sqlite://{}", database))?.create_if_missing(true))
.await?;
sqlx::query(
"CREATE TABLE IF NOT EXISTS accounts_pending (
user text primary key,
mail text not null,
cn text not null,
sn text not null,
action text not null,
auth_code text not null,
expiry integer not null
)",
)
.execute(&pool)
.await?;
sqlx::query(
"CREATE TABLE IF NOT EXISTS accounts_new (
mail text primary key,
@ -74,7 +50,8 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
date_iso text not null,
date_expiry text not null,
name_first text not null,
name_surname integer not null
name_surname integer not null,
id_student text not null
)",
)
.execute(&pool)
@ -100,6 +77,10 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
.await?;
sqlx::query("CREATE INDEX IF NOT EXISTS index_uid_number ON accounts (uid)").execute(&pool).await?;
sqlx::query("CREATE INDEX IF NOT EXISTS index_mail ON accounts (mail)").execute(&pool).await?;
sqlx::query("CREATE INDEX IF NOT EXISTS index_student_id ON accounts (student_id)")
.execute(&pool)
.await?;
update_accounts(&pool, config).await;