mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Merge pull request #2330 from Human-Connection/2329-normalize_emails_in_login_form
2329 normalize emails in login form
This commit is contained in:
commit
0a96f3ed6f
@ -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', () => {
|
||||||
|
|||||||
62
webapp/components/LoginForm/LoginForm.spec.js
Normal file
62
webapp/components/LoginForm/LoginForm.spec.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import LoginForm from './LoginForm.vue'
|
||||||
|
import Styleguide from '@human-connection/styleguide'
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
import { config, mount, createLocalVue } from '@vue/test-utils'
|
||||||
|
|
||||||
|
const localVue = createLocalVue()
|
||||||
|
localVue.use(Vuex)
|
||||||
|
localVue.use(Styleguide)
|
||||||
|
|
||||||
|
config.stubs['nuxt-link'] = '<span><slot /></span>'
|
||||||
|
config.stubs['locale-switch'] = '<span><slot /></span>'
|
||||||
|
config.stubs['client-only'] = '<span><slot /></span>'
|
||||||
|
|
||||||
|
describe('LoginForm', () => {
|
||||||
|
let mocks
|
||||||
|
let propsData
|
||||||
|
let storeMocks
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
propsData = {}
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mount', () => {
|
||||||
|
const Wrapper = () => {
|
||||||
|
storeMocks = {
|
||||||
|
getters: {
|
||||||
|
'auth/pending': () => false,
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
'auth/login': jest.fn(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const store = new Vuex.Store(storeMocks)
|
||||||
|
mocks = {
|
||||||
|
$t: () => {},
|
||||||
|
$toast: {
|
||||||
|
success: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return mount(LoginForm, { mocks, localVue, propsData, store })
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('fill in email and password and submit', () => {
|
||||||
|
const fillIn = (wrapper, opts = {}) => {
|
||||||
|
const { email = 'email@example.org', password = '1234' } = opts
|
||||||
|
wrapper.find('input[name="email"]').setValue(email)
|
||||||
|
wrapper.find('input[name="password"]').setValue(password)
|
||||||
|
wrapper.find('form').trigger('submit')
|
||||||
|
}
|
||||||
|
|
||||||
|
it('dispatches login with form data', () => {
|
||||||
|
fillIn(Wrapper())
|
||||||
|
expect(storeMocks.actions['auth/login']).toHaveBeenCalledWith(
|
||||||
|
expect.any(Object),
|
||||||
|
{ email: 'email@example.org', password: '1234' },
|
||||||
|
undefined,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -93,8 +93,9 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async onSubmit() {
|
async onSubmit() {
|
||||||
|
const { email, password } = this.form
|
||||||
try {
|
try {
|
||||||
await this.$store.dispatch('auth/login', { ...this.form })
|
await this.$store.dispatch('auth/login', { email, password })
|
||||||
this.$toast.success(this.$t('login.success'))
|
this.$toast.success(this.$t('login.success'))
|
||||||
this.$emit('success')
|
this.$emit('success')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user