Explorar o código

Elem.addClass not accepts an arbitrary number of arguments.

Lee Morgan hai 11 meses
pai
achega
30b0f1f9d4
Modificáronse 3 ficheiros con 21 adicións e 5 borrados
  1. 2 2
      src/views/js/Elem.js
  2. 1 2
      src/views/js/Notifier.js
  3. 18 1
      src/views/js/pages/Register.js

+ 2 - 2
src/views/js/Elem.js

@@ -8,8 +8,8 @@ export default class Elem {
         return this;
     }
 
-    addClass(v){
-        this.elem.classList.add(v);
+    addClass(...v){
+        this.elem.classList.add(...v);
         return this;
     }
 

+ 1 - 2
src/views/js/Notifier.js

@@ -3,8 +3,7 @@ import Elem from "./Elem.js";
 export default class Notifier{
     constructor(type, message){
         this.elem = new Elem("p")
-            .addClass("notifier")
-            .addClass(type)
+            .addClass("notifier", type)
             .text(message)
             .appendTo(document.body)
             .get();

+ 18 - 1
src/views/js/pages/Register.js

@@ -1,6 +1,7 @@
 import Page from "./Page.js";
 import Elem from "../Elem.js";
 import User from "../data/User.js";
+import Notifier from "../Notifier.js";
 
 export default class Register extends Page{
     constructor(){
@@ -17,18 +18,34 @@ export default class Register extends Page{
         const password = this.container.querySelector(".password").value;
         const confirmPassword = this.container.querySelector(".confirmPassword").value;
 
+        if(!isValidEmail(email)){
+            new Notifier("error", "Invalid email address");
+            return;
+        }
+
+        if(password.length < 10){
+            new Notifier("error", "Password must contain at least 10 characters");
+            return;
+        }
+
+        if(password !== confirmPassword){
+            new Notifier("error", "Passwords do not match");
+            return;
+        }
+
         fetch("/api/user", {
             method: "POST",
             headers: {
                 "Content-Type": "application/json"
             },
-            body: JSON.stringify(User.create(name, email, password))
+            body: JSON.stringify(await User.create(name, email, password))
         })
             .then(r=>r.json())
             .then((response)=>{
                 if(response.error){
                     console.log(response.error);
                 }else{
+                    let user = new User(...response);
                     console.log(response);
                 }
             })