diff --git a/server/api/auth.js b/server/api/auth.js index a677411a..8ae10466 100644 --- a/server/api/auth.js +++ b/server/api/auth.js @@ -1,5 +1,5 @@ +// @flow import Router from 'koa-router'; -import Sequelize from 'sequelize'; import apiError, { httpErrors } from '../errors'; import fetch from 'isomorphic-fetch'; import querystring from 'querystring'; @@ -9,80 +9,80 @@ import { User, Team } from '../models'; const router = new Router(); -router.post('auth.signup', async ctx => { - const { username, name, email, password } = ctx.request.body; +// router.post('auth.signup', async ctx => { +// const { username, name, email, password } = ctx.request.body; - ctx.assertPresent(username, 'name is required'); - ctx.assertPresent(name, 'name is required'); - ctx.assertPresent(email, 'email is required'); - ctx.assertEmail(email, 'email is invalid'); - ctx.assertPresent(password, 'password is required'); +// ctx.assertPresent(username, 'name is required'); +// ctx.assertPresent(name, 'name is required'); +// ctx.assertPresent(email, 'email is required'); +// ctx.assertEmail(email, 'email is invalid'); +// ctx.assertPresent(password, 'password is required'); - if (await User.findOne({ where: { email } })) { - throw apiError( - 400, - 'user_exists_with_email', - 'User already exists with this email' - ); - } +// if (await User.findOne({ where: { email } })) { +// throw apiError( +// 400, +// 'user_exists_with_email', +// 'User already exists with this email' +// ); +// } - if (await User.findOne({ where: { username } })) { - throw apiError( - 400, - 'user_exists_with_username', - 'User already exists with this username' - ); - } +// if (await User.findOne({ where: { username } })) { +// throw apiError( +// 400, +// 'user_exists_with_username', +// 'User already exists with this username' +// ); +// } - const user = await User.create({ - username, - name, - email, - password, - }); +// const user = await User.create({ +// username, +// name, +// email, +// password, +// }); - ctx.body = { - data: { - user: await presentUser(ctx, user), - accessToken: user.getJwtToken(), - }, - }; -}); +// ctx.body = { +// data: { +// user: await presentUser(ctx, user), +// accessToken: user.getJwtToken(), +// }, +// }; +// }); -router.post('auth.login', async ctx => { - const { username, password } = ctx.request.body; +// router.post('auth.login', async ctx => { +// const { username, password } = ctx.request.body; - ctx.assertPresent(username, 'username/email is required'); - ctx.assertPresent(password, 'password is required'); +// ctx.assertPresent(username, 'username/email is required'); +// ctx.assertPresent(password, 'password is required'); - let user; - if (username) { - user = await User.findOne({ - where: Sequelize.or({ email: username }, { username }), - }); - } else { - throw apiError(400, 'invalid_credentials', 'username or email is invalid'); - } +// let user; +// if (username) { +// user = await User.findOne({ +// where: Sequelize.or({ email: username }, { username }), +// }); +// } else { +// throw apiError(400, 'invalid_credentials', 'username or email is invalid'); +// } - if (!user) { - throw apiError(400, 'username or email is invalid'); - } +// if (!user) { +// throw apiError(400, 'username or email is invalid'); +// } - if (!user.passwordDigest) { - throw apiError(400, 'no_password', 'No password set'); - } +// if (!user.passwordDigest) { +// throw apiError(400, 'no_password', 'No password set'); +// } - if (!await user.verifyPassword(password)) { - throw apiError(400, 'invalid_password', 'Invalid password'); - } +// if (!await user.verifyPassword(password)) { +// throw apiError(400, 'invalid_password', 'Invalid password'); +// } - ctx.body = { - data: { - user: await presentUser(ctx, user), - accessToken: user.getJwtToken(), - }, - }; -}); +// ctx.body = { +// data: { +// user: await presentUser(ctx, user), +// accessToken: user.getJwtToken(), +// }, +// }; +// }); router.post('auth.slack', async ctx => { const { code } = ctx.body; diff --git a/server/api/auth.test.js b/server/api/auth.test.js index 4ba12543..114e0bf1 100644 --- a/server/api/auth.test.js +++ b/server/api/auth.test.js @@ -1,3 +1,4 @@ +/* eslint-disable flowtype/require-valid-file-annotation */ import TestServer from 'fetch-test-server'; import app from '..'; import { flushdb, seed } from '../test/support'; @@ -7,7 +8,7 @@ const server = new TestServer(app.callback()); beforeEach(flushdb); afterAll(() => server.close()); -describe('#auth.signup', async () => { +describe.skip('#auth.signup', async () => { it('should signup a new user', async () => { const res = await server.post('/api/auth.signup', { body: { @@ -84,7 +85,7 @@ describe('#auth.signup', async () => { }); }); -describe('#auth.login', () => { +describe.skip('#auth.login', () => { test('should login with email', async () => { await seed(); const res = await server.post('/api/auth.login', {