This commit is contained in:
Yash Karandikar 2022-02-08 11:58:06 -06:00
parent 49c7586ab7
commit 64244836e5
4 changed files with 34 additions and 12 deletions

View file

@ -1,10 +1,10 @@
use fancy_regex::Regex;
use serde::{Deserialize, Serialize};
use sycamore::prelude::*;
use sycamore_router::{
HistoryIntegration, Route, Router, RouterProps, StaticRouter, StaticRouterProps,
};
use wasm_bindgen::prelude::*;
use fancy_regex::Regex;
#[wasm_bindgen]
extern "C" {
@ -212,12 +212,15 @@ pub fn register() -> View<G> {
let error_blank = Signal::new(false);
let error_passmatch = Signal::new(false);
let error_username_format = Signal::new(false);
let error_format = Signal::new(false);
let whitespace_re = Regex::new(r"\s").unwrap();
let password_re = Regex::new(r"^.*(?=.{8})(?=.+[a-z])(?=.*[A-Z])(?=.+\d)(?=.*[`~!@#$%^&*()_+\-=\[\]{}\\|:;/?<>,.]).*$").unwrap();
let password_re = Regex::new(
r"^.*(?=.{8})(?=.+[a-z])(?=.*[A-Z])(?=.+\d)(?=.*[`~!@#$%^&*()_+\-=\[\]{}\\|:;/?<>,.]).*$",
)
.unwrap();
let on_click = cloned!((error_blank, error_passmatch, username, password_raw, password_confirm, error_format, error_username_format) => move |_| {
let username = (*username.get()).trim().to_string();
@ -232,7 +235,7 @@ pub fn register() -> View<G> {
view! {
div(class="card") {
label { "Username:"
label { "Username:"
input(bind:value=username)
}
label { "Password"
@ -246,7 +249,7 @@ pub fn register() -> View<G> {
(if *error_username_format.get() {
view! {
p(style="color: red") { "Username cannot contain any spaces." }
}
}
} else {
view! {}
})

View file

@ -50,4 +50,4 @@ pub async fn register(user_input: Json<PartialUser>) -> io::Result<()> {
.await;
Ok(())
}
}

View file

@ -14,7 +14,6 @@ enum Task {
// channel
AllIssues(oneshot::Sender<Vec<Issue>>),
// channel(id), username, hashed password
CreateUser(oneshot::Sender<Option<i64>>, String, String),
}
@ -82,8 +81,14 @@ impl ExecutorConnection {
);
executor_wrapper!(get_issue, Task::GetIssue, Option<Issue>, id: i64);
executor_wrapper!(all_issues, Task::AllIssues, Vec<Issue>);
executor_wrapper!(create_user, Task::CreateUser, Option<i64>, username: String, password_hash: String);
executor_wrapper!(
create_user,
Task::CreateUser,
Option<i64>,
username: String,
password_hash: String
);
}
impl DbExecutor {
@ -138,11 +143,19 @@ impl DbExecutor {
}
tx.send(issues).unwrap();
},
}
Task::CreateUser(tx, username, password_hash) => {
// hashing will be done in the frontend so as not to leak passwords over the web
let id = self.db.query_row("insert into users(username, password_hash) values(?, ?) returning id", params![username, password_hash], |r| r.get(0)).optional().unwrap();
let id = self
.db
.query_row(
"insert into users(username, password_hash) values(?, ?) returning id",
params![username, password_hash],
|r| r.get(0),
)
.optional()
.unwrap();
tx.send(id).unwrap();
}
}

View file

@ -57,7 +57,13 @@ async fn main() {
rocket::build()
.mount(
"/",
routes![index, api::all_issues, api::get_issue, api::add_issue, api::register],
routes![
index,
api::all_issues,
api::get_issue,
api::add_issue,
api::register
],
)
.mount("/", FileServer::from("app/dist").rank(1))
.launch()