Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/pages/register/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ const Register = () => {
setFormData({ ...formData, [name]: value });
};

const validateEmail = (email) => {
const mailFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (email.match(mailFormat)) {
return true; // return true if email is in valid format
}
else {
alert("You have entered an invalid email address"); // generic error message for now, needs refactoring
return false;
}

console.log(onRegister)
}

const validatePassword = (password) => {
const passwordFormat = /^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/;
if (password.match(passwordFormat)) {
return true;
}
else {
alert("Your password is not in the right format"); // generic error message for now, needs refactoring
return false;
}
}

return (
<div className="bg-blue register credentialpage">
<CredentialsCard
Expand All @@ -31,18 +55,25 @@ const Register = () => {
type="email"
name="email"
label={'Email *'}
required
/>
<TextInput
value={formData.password}
onChange={onChange}
name="password"
label={'Password *'}
type={'password'}
required
/>
</form>
<Button
text="Sign up"
onClick={() => onRegister(formData.email, formData.password)}
onClick={() => {
console.log(formData);
if (validateEmail(formData.email) && validatePassword(formData.password)) {
onRegister(formData.email, formData.password);
}
}}
classes="green width-full"
/>
</div>
Expand All @@ -52,3 +83,6 @@ const Register = () => {
};

export default Register;

// email: dave@email.com
// password: @Qwert123456
2 changes: 1 addition & 1 deletion src/service/apiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async function login(email, password) {
}

async function register(email, password) {
await post('users', { email, password }, false);
await post('signup', { email, password }, false); // changed from users to signup
return await login(email, password);
}

Expand Down