-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add validations and change routes
- Loading branch information
Showing
37 changed files
with
499 additions
and
356 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CREATE TABLE IF NOT EXISTS "users" ( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(64) NOT NULL, | ||
username CHAR(16) NOT NULL UNIQUE, | ||
email VARCHAR(256) NOT NULL UNIQUE, | ||
avatar VARCHAR(256), | ||
password TEXT, | ||
account_type INTEGER DEFAULT 2, | ||
address varchar(256), | ||
bio varchar(512), | ||
permissions INT NOT NULL DEFAULT 0, | ||
access_token TEXT | ||
); | ||
|
||
CREATE INDEX user_email ON "users" (email); | ||
CREATE INDEX user_username ON "users" (username); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE SCHEMA IF NOT EXISTS "tower_sessions"; | ||
|
||
CREATE TABLE IF NOT EXISTS "tower_sessions"."sessions" ( | ||
id text PRIMARY KEY NOT NULL, | ||
data bytea NOT NULL, | ||
expiry_date timestamptz NOT NULL | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod web; | ||
pub mod provider; | ||
pub mod backend; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod auth; | ||
pub mod users; | ||
pub mod users; | ||
mod validations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,31 @@ | ||
use serde::Deserialize; | ||
use garde::Validate; | ||
use serde::{Deserialize, Serialize}; | ||
use crate::json::validations::validate_name; | ||
|
||
#[derive(Debug, Clone, Deserialize)] | ||
#[derive(Deserialize, Validate)] | ||
pub struct UpdateUser { | ||
#[garde(skip)] | ||
pub avatar: Option<String>, | ||
#[garde(alphanumeric, length(min=3, max=16))] | ||
pub username: Option<String>, | ||
#[garde(custom(validate_name), length(min = 8))] | ||
pub name: Option<String>, | ||
pub phone: Option<i32>, | ||
//#[garde(phone_number)] | ||
#[garde(skip)] | ||
pub phone: Option<String>, | ||
#[garde(skip)] | ||
pub address: Option<String>, | ||
#[garde(email)] | ||
pub email: Option<String>, | ||
pub password: Option<String>, | ||
} | ||
|
||
#[derive(Serialize)] | ||
pub struct UserMe { | ||
pub id: i32, | ||
pub email: String, | ||
pub name: String, | ||
pub username: String, | ||
pub avatar: Option<String>, | ||
pub account_type: i32, | ||
pub bio: Option<String> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use garde::Error; | ||
|
||
pub fn validate_name(value: &Option<String>, _: &()) -> garde::Result { | ||
match value { | ||
Some(n) => { | ||
if n.chars().all(char::is_alphabetic) { | ||
Ok(()) | ||
} else { | ||
Err(Error::new("Name must contain only letters")) | ||
} | ||
} | ||
None => Ok(()), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.