Skip to content
This repository has been archived by the owner on Sep 22, 2021. It is now read-only.

Made email, name optional #235

Merged
merged 2 commits into from Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion auth-server/migrations/20180917160913_users.js
Expand Up @@ -2,7 +2,7 @@
exports.up = (knex) => {
return knex.schema.createTable('users', (table) => {
table.increments('id').primary();
table.string('email').unique().notNullable();
table.string('email').nullable();
table.string('password').notNullable();
table.string('salt').notNullable();
table.string('username').unique().notNullable();
Expand Down
4 changes: 2 additions & 2 deletions auth-server/src/model/User.ts
Expand Up @@ -42,8 +42,8 @@ export default class User extends Model {
properties: {
id: { type: 'integer' },
username: { type: 'string', minLength: 1, maxLength: 255 },
email: { type: 'string', minLength: 1, maxLength: 255 },
name: { type: 'string', minLength: 1, maxLength: 512 },
email: { type: 'string', maxLength: 255 },
name: { type: 'string', maxLength: 512 },
email_verified: { type: 'boolean' }
}
};
Expand Down
4 changes: 2 additions & 2 deletions auth-server/src/resolvers/mutation/signup.ts
Expand Up @@ -15,7 +15,7 @@ interface argsType {

export default async (parent, { email, password, username, name }: argsType, ctx: Context): Promise<SignUpResultType> => {

if (!validateEmail(email)) {
if (email && !validateEmail(email)) {
throw new UserInputError(messages.INVALID_EMAIL);
}

Expand All @@ -31,4 +31,4 @@ export default async (parent, { email, password, username, name }: argsType, ctx
const { user, token, refreshToken } = await authServiceInstance.SignUp(email, password, username, name);
setRefreshTokenCookie(ctx.res, refreshToken);
return { user, token };
};
};
4 changes: 2 additions & 2 deletions auth-server/src/schema/mutation/signup.ts
@@ -1,8 +1,8 @@
export default `
signup(
email: String!
email: String
password: String!
username: String!
name: String
): LoginResponse
`;
`;
34 changes: 19 additions & 15 deletions auth-server/src/services/auth.ts
Expand Up @@ -100,10 +100,12 @@ export default class AuthService {
throw new ForbiddenError(messages.USERNAME_ALREADY_EXISTS);
}

existing = await User
.query()
.where('email', email)
.first();
if (email) {
existing = await User
.query()
.where('email', email)
.first();
}

if (existing) {
throw new ForbiddenError(messages.USER_EMAIL_ALREADY_EXISTS);
Expand All @@ -124,17 +126,19 @@ export default class AuthService {
email_verified: false
});

const verifyToken = await EmailVerificationToken
.query()
.allowInsert('[token, user_id, valid]')
.insert({
token: uuid(),
user_id: user.id,
valid: true
});

// send verification email in background
sendVerificationEmail(user, verifyToken);
if (email) {
const verifyToken = await EmailVerificationToken
.query()
.allowInsert('[token, user_id, valid]')
.insert({
token: uuid(),
user_id: user.id,
valid: true
});

// send verification email in background
sendVerificationEmail(user, verifyToken);
}

return {
user: {
Expand Down
6 changes: 3 additions & 3 deletions front-end/src/generated/auth-graphql.tsx
Expand Up @@ -137,7 +137,7 @@ export type MutationResetPasswordArgs = {


export type MutationSignupArgs = {
email: Scalars['String'],
email?: Maybe<Scalars['String']>,
password: Scalars['String'],
username: Scalars['String'],
name?: Maybe<Scalars['String']>
Expand Down Expand Up @@ -211,7 +211,7 @@ export type UserFragment = (
);

export type SignupMutationVariables = {
email: Scalars['String'],
email?: Maybe<Scalars['String']>,
password: Scalars['String'],
username: Scalars['String'],
name?: Maybe<Scalars['String']>
Expand Down Expand Up @@ -280,7 +280,7 @@ export const UserFragmentDoc = gql`
}
`;
export const SignupDocument = gql`
mutation SIGNUP($email: String!, $password: String!, $username: String!, $name: String) {
mutation SIGNUP($email: String, $password: String!, $username: String!, $name: String) {
signup(email: $email, password: $password, username: $username, name: $name) {
user {
...user
Expand Down
4 changes: 2 additions & 2 deletions front-end/src/generated/graphql.tsx
Expand Up @@ -830,7 +830,7 @@ export type MutationResetPasswordArgs = {


export type MutationSignupArgs = {
email: Scalars['String'],
email?: Maybe<Scalars['String']>,
name?: Maybe<Scalars['String']>,
password: Scalars['String'],
username: Scalars['String']
Expand Down Expand Up @@ -1241,7 +1241,7 @@ export type Mutation_RootResetPasswordArgs = {


export type Mutation_RootSignupArgs = {
email: Scalars['String'],
email?: Maybe<Scalars['String']>,
name?: Maybe<Scalars['String']>,
password: Scalars['String'],
username: Scalars['String']
Expand Down
11 changes: 5 additions & 6 deletions front-end/src/screens/SignupForm/index.tsx
Expand Up @@ -28,7 +28,7 @@ const SignupForm = ({ className }:Props): JSX.Element => {
const handleSubmitForm = (data:Record<string, any>):void => {
const { email, name, password, username } = data;

if (username && email && password){
if (username && password){
signupMutation({
variables: {
email,
Expand All @@ -40,7 +40,9 @@ const SignupForm = ({ className }:Props): JSX.Element => {
.then(({ data }) => {
if (data && data.signup && data.signup.token && data.signup.user) {
handleLoginUser({ token: data.signup.token, user: data.signup.user }, currentUser);
setModal({ content: 'We sent you an email to verify your address. Click on the link in the email.' ,title: 'You\'ve got some mail' });
if (email) {
setModal({ content: 'We sent you an email to verify your address. Click on the link in the email.' ,title: 'You\'ve got some mail' });
}
history.push('/');
}}

Expand Down Expand Up @@ -76,10 +78,8 @@ const SignupForm = ({ className }:Props): JSX.Element => {
className={errors.name ? 'error' : ''}
name='name'
placeholder='Firstname Lastname'
ref={register({ minLength: 3, required: true })}
type='text'
/>
{errors.name && <span className={'errorText'}>{messages.VALIDATION_NAME_ERROR}</span>}
</Form.Field>
</Form.Group>
<Form.Group>
Expand All @@ -90,8 +90,7 @@ const SignupForm = ({ className }:Props): JSX.Element => {
name='email'
placeholder='john@doe.com'
ref={register({
pattern: /^[A-Z0-9_'%=+!`#~$*?^{}&|-]+([.][A-Z0-9_'%=+!`#~$*?^{}&|-]+)*@[A-Z0-9-]+(\.[A-Z0-9-]+)+$/i,
required: true
pattern: /^[A-Z0-9_'%=+!`#~$*?^{}&|-]+([.][A-Z0-9_'%=+!`#~$*?^{}&|-]+)*@[A-Z0-9-]+(\.[A-Z0-9-]+)+$/i
})}
type='text'
/>
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/services/auth-queries.ts
Expand Up @@ -11,7 +11,7 @@ const USER_FRAGMENT = gql`
`;

export const SIGNUP = gql`
mutation SIGNUP($email: String!, $password: String!, $username: String!, $name: String) {
mutation SIGNUP($email: String, $password: String!, $username: String!, $name: String) {
signup(email: $email, password: $password, username:$username, name:$name){
user {
...user
Expand Down
3 changes: 1 addition & 2 deletions front-end/src/util/messages.ts
@@ -1,8 +1,7 @@
export default {
VALIDATION_CONTENT_ERROR: 'Did you forget to add content?',
VALIDATION_EMAIL_ERROR: 'You need to provide a valid email!',
VALIDATION_NAME_ERROR: 'You need to provide a name with at least 3 characters!',
VALIDATION_PASSWORD_ERROR: 'You need to specify a password with at least 6 characters!',
VALIDATION_TITLE_ERROR: 'Did you forget to add a title?',
VALIDATION_USERNAME_ERROR: 'You need to specify a username with at least 3 characters!'
};
};