Skip to content

Commit

Permalink
implement validate in ponies app b00tc4mp#68
Browse files Browse the repository at this point in the history
  • Loading branch information
NerinaHctz committed Jul 14, 2024
1 parent e275c2a commit f292593
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 39 deletions.
2 changes: 1 addition & 1 deletion staff/nerina-castillo/ponies/app/logic/createPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import validate from "../validate.js";
import generateId from "../util/generateId";

const createPost = (image, caption) => {
validate.string(image, 'image')
validate.image(image, 'image')
validate.string(caption, 'caption')
if (!image.startsWith("http")) throw new Error("invalid image");

Expand Down
2 changes: 1 addition & 1 deletion staff/nerina-castillo/ponies/app/logic/getAllPosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const getAllPosts = () => {
(user) => user.username === sessionStorage.username
);

if (user === null) throw new Error("User not found");
if (user === null) throw new Error("user not found");

const posts = data.findPosts(() => true);

Expand Down
16 changes: 8 additions & 8 deletions staff/nerina-castillo/ponies/app/logic/registerUser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import data from "../data/index";
import validate from "../validate";

const email_regex = /^[a-z0-9._]+@[a-z0-9.-]{3,63}\.[a-z]{2,10}$/;
const name_regex = /^(?!.*\s{2})[a-zA-Z ]{3,16}$/;
const user_regex = /^(?!.*\s{2})[a-zA-Z0-9._-]{4,16}$/;
const EMAIL_REGEX = /^[a-z0-9._]+@[a-z0-9.-]{3,63}\.[a-z]{2,10}$/;
const NAME_REGEX = /^(?!.*\s{2})[a-zA-Z ]{3,16}$/;
const USER_REGEX = /^(?!.*\s{2})[a-zA-Z0-9._-]{4,16}$/;

const registerUser = (
name,
Expand All @@ -18,15 +18,15 @@ const registerUser = (
validate.email(email)
validate.username(username)
validate.password(password)
validate.passwordRepeat(passwordRepeat)
validate.password(passwordRepeat)

if (!name_regex.test(name.trim())) throw new Error("invalid name");
if (!NAME_REGEX.test(name.trim())) throw new Error("invalid name");

if (!name_regex.test(surname.trim())) throw new Error("ivalid surname");
if (!NAME_REGEX.test(surname.trim())) throw new Error("ivalid surname");

if (!email_regex.test(email)) throw new Error("invalid email");
if (!EMAIL_REGEX.test(email)) throw new Error("invalid email");

if (!user_regex.test(username)) throw new Error("invalid username");
if (!USER_REGEX.test(username)) throw new Error("invalid username");

if (password.trim().length < 8) throw new Error("invalid password");

Expand Down
29 changes: 0 additions & 29 deletions staff/nerina-castillo/ponies/app/view/Register.css

This file was deleted.

0 comments on commit f292593

Please sign in to comment.