Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
pilinux committed Sep 1, 2023
1 parent 1519f09 commit 1e2fd4f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
18 changes: 4 additions & 14 deletions app/routes/login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@ import { Form, Link } from "@remix-run/react";
import { useState } from "react";

import { remoteApi } from "~/api.server";
import { sha512, sha3_512 } from "~/crypto";
import { jwtExpiry } from "~/jwt";
import { cookieHandler } from "~/cookies.server";

function validateEmail(email) {
const regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
return regex.test(email);
}

function validatePassword(password) {
// ,;.:-_#'+*@<>!"§$|%&/()[]=?{}\
const regex =
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[,;.:\-\_#\'+*@<>!"§$|%&/\(\)\[\]=?\{\}\\]).{6,}$/;
return regex.test(password);
}
import { sha512, sha3_512 } from "~/crypto";
import { jwtExpiry } from "~/jwt";
import { validateEmail, validatePassword } from "~/validator";

// https://remix.run/docs/en/main/guides/resource-routes
// on server-side
Expand Down Expand Up @@ -174,7 +164,7 @@ export default function Login() {

if (res.status === 200) {
// authentication successful, perform client-side redirect
window.location.href = "/logout";
window.location.href = "/protected";
}
if (res.status !== 200 && res.status < 500) {
setAuthError("Invalid email or password");
Expand Down
11 changes: 11 additions & 0 deletions app/validator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function validateEmail(email) {
const regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
return regex.test(email);
}

export function validatePassword(password) {
// ,;.:-_#'+*@<>!"§$|%&/()[]=?{}\
const regex =
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[,;.:\-\_#\'+*@<>!"§$|%&/\(\)\[\]=?\{\}\\]).{6,}$/;
return regex.test(password);
}

0 comments on commit 1e2fd4f

Please sign in to comment.