mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
fix #2329: Normalize email on login in the backend
This commit is contained in:
parent
145b6727b1
commit
ae360f2201
@ -2,6 +2,7 @@ import encode from '../../jwt/encode'
|
|||||||
import bcrypt from 'bcryptjs'
|
import bcrypt from 'bcryptjs'
|
||||||
import { AuthenticationError } from 'apollo-server'
|
import { AuthenticationError } from 'apollo-server'
|
||||||
import { neode } from '../../bootstrap/neo4j'
|
import { neode } from '../../bootstrap/neo4j'
|
||||||
|
import { normalizeEmail } from 'validator'
|
||||||
|
|
||||||
const instance = neode()
|
const instance = neode()
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ export default {
|
|||||||
// if (user && user.id) {
|
// if (user && user.id) {
|
||||||
// throw new Error('Already logged in.')
|
// throw new Error('Already logged in.')
|
||||||
// }
|
// }
|
||||||
|
email = normalizeEmail(email)
|
||||||
const session = driver.session()
|
const session = driver.session()
|
||||||
const result = await session.run(
|
const result = await session.run(
|
||||||
`
|
`
|
||||||
|
|||||||
@ -5,8 +5,10 @@ import { gql } from '../../helpers/jest'
|
|||||||
import { createTestClient } from 'apollo-server-testing'
|
import { createTestClient } from 'apollo-server-testing'
|
||||||
import createServer, { context } from '../../server'
|
import createServer, { context } from '../../server'
|
||||||
import encode from '../../jwt/encode'
|
import encode from '../../jwt/encode'
|
||||||
|
import { neode as getNeode } from '../../bootstrap/neo4j'
|
||||||
|
|
||||||
const factory = Factory()
|
const factory = Factory()
|
||||||
|
const neode = getNeode()
|
||||||
let query
|
let query
|
||||||
let mutate
|
let mutate
|
||||||
let variables
|
let variables
|
||||||
@ -214,6 +216,28 @@ describe('login', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('normalization', () => {
|
||||||
|
describe('email address is a gmail address ', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
const email = await neode.first('EmailAddress', { email: 'test@example.org' })
|
||||||
|
await email.update({ email: 'someuser@gmail.com' })
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('supplied email contains dots', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
variables = { ...variables, email: 'some.user@gmail.com' }
|
||||||
|
})
|
||||||
|
|
||||||
|
it('normalizes email, issue #2329', async () => {
|
||||||
|
await respondsWith({
|
||||||
|
data: { login: expect.any(String) },
|
||||||
|
errors: undefined,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with a valid email but incorrect password', () => {
|
describe('with a valid email but incorrect password', () => {
|
||||||
|
|||||||
@ -57,17 +57,6 @@ describe('LoginForm', () => {
|
|||||||
undefined,
|
undefined,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('given email is a gmail address', () => {
|
|
||||||
it('removes dots, issue #2329', () => {
|
|
||||||
fillIn(Wrapper(), { email: 'example.user@gmail.com' })
|
|
||||||
expect(storeMocks.actions['auth/login']).toHaveBeenCalledWith(
|
|
||||||
expect.any(Object),
|
|
||||||
{ email: 'exampleuser@gmail.com', password: '1234' },
|
|
||||||
undefined,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -73,7 +73,6 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import LocaleSwitch from '~/components/LocaleSwitch/LocaleSwitch.vue'
|
import LocaleSwitch from '~/components/LocaleSwitch/LocaleSwitch.vue'
|
||||||
import { normalizeEmail } from 'validator'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -94,8 +93,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async onSubmit() {
|
async onSubmit() {
|
||||||
let { email, password } = this.form
|
const { email, password } = this.form
|
||||||
email = normalizeEmail(email)
|
|
||||||
try {
|
try {
|
||||||
await this.$store.dispatch('auth/login', { email, password })
|
await this.$store.dispatch('auth/login', { email, password })
|
||||||
this.$toast.success(this.$t('login.success'))
|
this.$toast.success(this.$t('login.success'))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user