Skip to content

Commit

Permalink
Adds email validation and domain whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbrain-za committed Nov 5, 2023
1 parent 554ca97 commit 4ad5f82
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "challenge_frontend"
version = "0.5.7"
version = "0.5.8"
edition = "2021"
rust-version = "1.71"
authors = ["Philip Barlow"]
Expand Down Expand Up @@ -28,9 +28,10 @@ serde_json = "1.0"
egui_commonmark = "0.9.0"
serde = { version = "1", features = ["derive"] }
web-sys = { version = "0.3.64" }
js-sys = "0.3.65"
js-sys = "0.3.64"
egui-notify = "0.10"
rfd = "0.12.1"
email_address = "0.2.4"

# native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
18 changes: 17 additions & 1 deletion src/apps/login_app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::helpers::refresh;
use egui_notify::Toasts;
use email_address::*;
use gloo_net::http;
use poll_promise::Promise;
use std::time::Duration;
Expand Down Expand Up @@ -349,7 +350,22 @@ impl LoginApp {
if ui.button("Register").clicked() {
if self.register.password != self.register.confirm_password {
self.toasts
.error("Passwords do not match!")
.error("Passwords do not match")
.set_duration(Some(Duration::from_secs(5)));
} else if !EmailAddress::is_valid(&self.register.email) {
self.toasts
.error("Invalid email address")
.set_duration(Some(Duration::from_secs(5)));
} else if !self
.register
.email
.contains(option_env!("ALLOWED_DOMAIN").unwrap_or("dummy.com"))
{
self.toasts
.error(format!(
"Email must be from {}",
option_env!("ALLOWED_DOMAIN").unwrap_or("dummy.com")
))
.set_duration(Some(Duration::from_secs(5)));
} else {
self.submit = Some(AuthRequest::Register);
Expand Down

0 comments on commit 4ad5f82

Please sign in to comment.