Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login using email address #397

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions api/src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ const localAuth = async (name, password) => {
// @access Public
const registerUser = async (req, res) => {
try {
const { name, password, id } = req.body
const { name, password, id, email } = req.body
if (process.env.AUTH_METHOD === 'cognito') {
const data = await db.User.findOne({ where: { userID: id } })
if (!data) {
const user = await db.User.create({ userID: id, isLocalAuth: false, lastLogin: new Date(), numberOfVisit: 0 })
const user = await db.User.create({ email, userID: id, isLocalAuth: false, lastLogin: new Date(), numberOfVisit: 0 })
if (user && await subscribeCommunity(user)) {
res.status(201).send('SUCCESS')
}
Expand All @@ -136,7 +136,7 @@ const registerLocal = async (name, password, res) => {
if (userExists) { return res.json({ message: 'Users already Exists !!!' }).status(400) }
const newUser = await db.sequelize.transaction(async (t) => {
const user = await db.LocalAuth.create({ username: name, password: password }, { transaction: t })
return await db.User.create({ userID: user.id, isLocalAuth: true, lastLogin: new Date(), numberOfVisit: 0 }, { transaction: t })
return await db.User.create({ email: name, userID: user.id, isLocalAuth: true, lastLogin: new Date(), numberOfVisit: 0 }, { transaction: t })
})
if (newUser && await subscribeCommunity(newUser)) {
res.status(201).json({
Expand Down
8 changes: 4 additions & 4 deletions src/actions/userAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ export const register = (name, password) => async (dispatch) => {
username: name,
password,
attributes: {
email: null
email: name
}
})
const response = await Auth.signIn(name, password)
userdata = { token: response?.signInUserSession?.idToken?.jwtToken, id: response?.attributes?.sub || '' }
const { data } = await postApi(dispatch, `${process.env.REACT_APP_API_BASE_URL}/api/users`, { id: userdata.id }, {
const { data } = await postApi(dispatch, `${process.env.REACT_APP_API_BASE_URL}/api/users`, { id: userdata.id, email: name }, {
headers: {
Authorization: 'Bearer ' + userdata.token
}
Expand Down Expand Up @@ -213,7 +213,7 @@ export const checkAndUpdateToken = () => async (dispatch) => {
}
}).catch((data) => {
return tokenFailure(dispatch, 'Unauthorized')
/*const message = data.response && data.response.data.name ? data.response.data.name : data.message
/* const message = data.response && data.response.data.name ? data.response.data.name : data.message
if (message === 'TokenExpired') {
if (process.env.REACT_APP_AUTH_METHOD === 'cognito') {
Auth.currentSession().then((res) => {
Expand Down Expand Up @@ -242,7 +242,7 @@ export const checkAndUpdateToken = () => async (dispatch) => {
}
} else {
return tokenFailure(dispatch, 'Unauthorized')
}*/
} */
})
}

Expand Down
12 changes: 8 additions & 4 deletions src/components/signInSignUp/SignIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,24 @@ const SignIn = () => {
}

return (
<form className='sign' onSubmit={handleSubmit(onSubmit)}>
<form className='sign' onSubmit={handleSubmit(onSubmit)} noValidate>
<h1 className='welcome'>Sign In</h1>
<div className='container'>
{error && <div className='error'>{error}</div>}

<Input
placeholder='Username'
type='text'
placeholder='Email'
type='email'
name='username'
id='username'
ref={regi({
required: {
value: true,
message: 'You must enter username'
message: 'You must enter email'
},
pattern: {
value: /\S+@\S+\.\S+/,
message: 'You must enter valid email'
}
})}
errors={errors}
Expand Down
12 changes: 8 additions & 4 deletions src/components/signInSignUp/SignUp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,24 @@ const SignIn = () => {
}

return (
<form className='sign' onSubmit={handleSubmit(onSubmit)}>
<form className='sign' onSubmit={handleSubmit(onSubmit)} noValidate>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is validation error removed?

<h1 className='welcome'>{welcomeBack}</h1>
<div className='container'>
{error && <div className='error'>{error}</div>}
<Input
placeholder='Username'
type='text'
placeholder='Email'
type='email'
name='username'
id='username'
autoFocus='autoFocus'
ref={regi({
required: {
value: true,
message: 'You must enter username'
message: 'You must enter email'
},
pattern: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

email pattern will not be required as input type should do that

value: /\S+@\S+\.\S+/,
message: 'You must enter valid email'
}
})}
errors={errors}
Expand Down
12 changes: 8 additions & 4 deletions src/screens/forgotPassword/ForgotPassword.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,25 @@ const ForgotPassword = () => {

return (
<SignLayout>
<form className='sign'>
<form className='sign' noValidate>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validation should not be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed noValidate and changed email field type to text.

<h1 className='welcome'>Forgot Password</h1>
<div className='container'>
{confirmErr && <div className='error'>{confirmErr}</div>}
{resendErr && <div className='error'>{resendErr}</div>}
{message && <div className='message'>{message}</div>}
<Input
placeholder='Username'
type='text'
placeholder='Email'
type='email'
name='username'
id='username'
ref={regi({
required: {
value: true,
message: 'You must enter username'
message: 'You must enter email'
},
pattern: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pattern validation will not be required

value: /\S+@\S+\.\S+/,
message: 'You must enter valid email'
}
})}
disabled={false}
Expand Down