Skip to content

Commit

Permalink
Merge pull request #4 from slava-lu/fix/final_fixes
Browse files Browse the repository at this point in the history
Email to lowercase
  • Loading branch information
slava-lu authored Dec 16, 2023
2 parents 447b793 + 9c1a1a2 commit 488ec09
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/api/v1/auth/account/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ const cookiesOptionRemember = () => ({
*/
router.post('/', async (req, res, next) => {
try {
const { email = '', mobilePhone, password, firstName = '', lastName = '', isRemember } = req.body
const { email: emailRaw = '', mobilePhone, password, firstName = '', lastName = '', isRemember } = req.body
const email = emailRaw.toLowerCase()

const validationResult = validatePassword(password)
if (validationResult) {
Expand Down
3 changes: 2 additions & 1 deletion src/api/v1/auth/login/localAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const { validatePassword } = require('@utils/helpers')
const localAuth = async (req, res, next) => {
const ct = new Date()
try {
const { email, mobilePhone, password } = req.body
const { email: emailRaw, mobilePhone, password } = req.body
const email = emailRaw.toLowerCase()

const validationResult = validatePassword(password)
if (validationResult) {
Expand Down
3 changes: 2 additions & 1 deletion src/api/v1/auth/login/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ router.post('/local', localAuth, checkUser(), postLogin(), async (req, res, next
*/
router.post('/loginAs', checkUser(), checkRoles('impersonation'), passwordCheck(), async (req, res, next) => {
const { accountId, hashCheck } = req.user
const { email } = req.body
const { email: emailRaw } = req.body
const email = emailRaw.toLowerCase()
try {
const { userId } = getOne(await getUserData(email))
if (!userId) {
Expand Down
5 changes: 3 additions & 2 deletions src/api/v1/auth/oauth/oauthMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const oauthMiddleware = () => {

const decodedIdToken = jwt.decode(idToken)

const { sub, email, given_name, family_name, name, picture } = decodedIdToken
const { sub, email: emailRaw, given_name, family_name, name, picture } = decodedIdToken
const email = emailRaw.toLowerCase()

// some roles are not allowed to log in using social networks
const userInfo = getOne(await getUserInfoByEmail(email))
Expand All @@ -57,7 +58,7 @@ const oauthMiddleware = () => {
name,
picture,
refresh_token,
access_token
access_token,
)

req.user = result
Expand Down
10 changes: 7 additions & 3 deletions src/api/v1/auth/password/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ router.post('/change', checkUser(), async (req, res, next) => {
*/
router.get('/checkResetCode', async (req, res, next) => {
try {
const { passwordResetCode, email } = req?.query
const { passwordResetCode, email: emailRaw } = req?.query
const email = emailRaw.toLowerCase()
if (!passwordResetCode || !email) {
return res.status(403).send({
resultCode: resultCodes.ERROR,
Expand Down Expand Up @@ -227,7 +228,9 @@ router.get('/checkResetCode', async (req, res, next) => {
router.post('/resetByCode', async (req, res, next) => {
const passwordChangedAt = new Date()
try {
const { passwordResetCode, email, password } = req.body
const { passwordResetCode, email: emailRaw, password } = req.body
const email = emailRaw.toLowerCase()

if (!passwordResetCode || !email || !password) {
return res.status(403).send({
resultCode: resultCodes.ERROR,
Expand Down Expand Up @@ -314,7 +317,8 @@ router.post('/resetByCode', async (req, res, next) => {
router.get('/requestResetCode', async (req, res, next) => {
const passwordResetAt = new Date()
try {
const { email } = req?.query
const { email: emailRaw } = req?.query
const email = emailRaw.toLowerCase()
if (!email) {
return res.status(400).send({
resultCode: resultCodes.ERROR,
Expand Down

0 comments on commit 488ec09

Please sign in to comment.