JNOEM73WZ5Q6UWAMVB6J3ZFPYWTONYEHSMV2THTTBV4D5SYX5X7QC
CMY6YHG36OX27OCWAENW2FQ3AKBR52XY3OBLKG5RY3D62UZ4BGUQC
Z63HIZPS4WOEDXVLOLVIHNZI2IMXCFCFBIHHM65EQ7SGJRX6BVCAC
TWIZ7QV4GCTQK743IKZSOJCIAEX62GZHFIYGOIFCFGIBOGPSY2WAC
DSWQKJRHGLKXUDXKMRXCIQZKEGXYV3H5LPUMGSV4HQ4HYPTI47GQC
FS2NWBVN2SZB2FFPB3JSYT5URTVZEAZWMQ7QW4JUYPNJVDVAJTTQC
WSHUT37CPBBR5JHWAHR27BKOADUWPUHYBWBJPNI6TEQ47TDWTL7QC
RJ75MX6YMJSXYKW2YK6ZJNG2SQMPCPKICMESMC4ZD4EB2SCVJ2KAC
5UNA2DEALCSRBINR27KSA6OMD6GQAXHYZ35ICQ7NB62G2XP4FT5QC
W3M3C7CCWHJWRWHULDWO45D3OFD4NL3V4OTJVIJCYRQG57Z2JTWQC
pub async fn find(db: &State<Database>, id: i32) -> Result<Self, sqlx::Error> {
query_as!(User, "SELECT * FROM users WHERE id = $1", id)
.fetch_one(&**db)
.await
}
pub async fn create(&self, db: &State<Database>) -> Result<i32, sqlx::Error> {
let result = query!(
"INSERT INTO users (name, email, password) VALUES ($1, $2, crypt($3, gen_salt('bf'))) RETURNING id",
&self.name,
&self.email.to_lowercase(),
&self.password
pub async fn create(
db: &State<Database>,
name: String,
password: String,
email: String,
) -> Result<Self, sqlx::Error> {
let result = query_as!( User,
"INSERT INTO users (name, email, password) VALUES ($1, $2, crypt($3, gen_salt('bf'))) RETURNING *",
&name,
&email.to_lowercase(),
&password
// TODO When the form parsing fails, the users gets no feedback
let mut new_user = User {
id: -1,
name: user.user_name.clone(),
email: user.email.clone(),
password: user.password.clone(),
};
match new_user.create(db).await {
Ok(id) => {
new_user.id = id;
match User::create(
db,
user.user_name.clone(),
user.password.clone(),
user.email.clone(),
)
.await
{
Ok(new_user) => {