better signup pages
This commit is contained in:
parent
79ecd74500
commit
fee7fff3df
4 changed files with 46 additions and 7 deletions
1
.env
Normal file
1
.env
Normal file
|
@ -0,0 +1 @@
|
|||
DATABASE_URL=sqlite://${HOME}/.witch-watch.db
|
24
src/users.rs
24
src/users.rs
|
@ -1,7 +1,10 @@
|
|||
use std::fmt::Display;
|
||||
|
||||
use argon2::{
|
||||
password_hash::{rand_core::OsRng, PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
|
||||
Argon2,
|
||||
};
|
||||
use askama::Template;
|
||||
use axum::{
|
||||
extract::{Form, State},
|
||||
http::StatusCode,
|
||||
|
@ -24,6 +27,19 @@ pub struct User {
|
|||
email: Option<String>,
|
||||
}
|
||||
|
||||
impl Display for User {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let uname = &self.username;
|
||||
let dname = if let Some(ref n) = self.displayname {
|
||||
n
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let email = if let Some(ref e) = self.email { e } else { "" };
|
||||
write!(f, "Username: {uname}\nDisplayname: {dname}\nEmail: {email}")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, sqlx::FromRow, sqlx::Encode)]
|
||||
pub(crate) struct DbUser {
|
||||
id: Uuid,
|
||||
|
@ -34,6 +50,10 @@ pub(crate) struct DbUser {
|
|||
pwhash: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Template)]
|
||||
#[template(path = "signup_success.html")]
|
||||
pub struct CreateUserSuccess(User);
|
||||
|
||||
impl From<DbUser> for User {
|
||||
fn from(dbu: DbUser) -> Self {
|
||||
User {
|
||||
|
@ -56,7 +76,7 @@ pub async fn get_create_user() -> CreateUser {
|
|||
pub async fn post_create_user(
|
||||
State(pool): State<SqlitePool>,
|
||||
Form(signup): Form<CreateUser>,
|
||||
) -> Result<(), CreateUserError> {
|
||||
) -> Result<CreateUserSuccess, CreateUserError> {
|
||||
let username = &signup.username;
|
||||
let displayname = &signup.displayname;
|
||||
let email = &signup.email;
|
||||
|
@ -102,7 +122,7 @@ pub async fn post_create_user(
|
|||
|
||||
let user = create_user(username, displayname, email, password, &pool).await?;
|
||||
tracing::debug!("created {user:?}");
|
||||
Ok(())
|
||||
Ok(CreateUserSuccess(user))
|
||||
}
|
||||
|
||||
async fn create_user(
|
||||
|
|
|
@ -4,18 +4,20 @@
|
|||
|
||||
{% block content %}
|
||||
|
||||
<p>
|
||||
<form action="/signup" enctype="application/x-www-form-urlencoded" method="post">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" name="username" id="username" minlength="1" maxlength="20" required>
|
||||
<input type="text" name="username" id="username" minlength="1" maxlength="20" required></br>
|
||||
<label for="displayname">Displayname (optional)</label>
|
||||
<input type="text" name="displayname" id="displayname">
|
||||
<input type="text" name="displayname" id="displayname"></br>
|
||||
<label for="email">Email (optional)</label>
|
||||
<input type="text" name="email">
|
||||
<input type="text" name="email"></br>
|
||||
<label for="password">Password</label>
|
||||
<input type="password" name="password" id="password" required>
|
||||
<input type="password" name="password" id="password" required></br>
|
||||
<label for="confirm_password">Confirm Password</label>
|
||||
<input type="password" name="pw_verify" id="pw_verify" required>
|
||||
<input type="password" name="pw_verify" id="pw_verify" required></br>
|
||||
<input type="submit" value="Signup">
|
||||
</form>
|
||||
</p>
|
||||
|
||||
{% endblock %}
|
||||
|
|
16
templates/signup_success.html
Normal file
16
templates/signup_success.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Thanks for Signing Up for Witch Watch, Bish{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>You did it!</h1>
|
||||
|
||||
<div id="signup_success"><p>
|
||||
{{ self.0 }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p>Now, head on over to <a href="/login">the login page</a> and get watchin'!</p>
|
||||
|
||||
{% endblock %}
|
Loading…
Reference in a new issue