2019-08-31 04:07:25 +05:00
|
|
|
const Errors = {
|
2020-04-03 00:35:25 +05:00
|
|
|
EMAIL_ALREADY_IN_USE: {
|
|
|
|
emailAlreadyInUse: 'Email already in use',
|
|
|
|
},
|
|
|
|
USERNAME_ALREADY_IN_USE: {
|
|
|
|
usernameAlreadyInUse: 'Username already in use',
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
email: {
|
|
|
|
type: 'string',
|
|
|
|
isEmail: true,
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
password: {
|
|
|
|
type: 'string',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
|
|
|
},
|
2020-04-03 00:35:25 +05:00
|
|
|
username: {
|
|
|
|
type: 'string',
|
|
|
|
isNotEmptyString: true,
|
|
|
|
minLength: 3,
|
|
|
|
maxLength: 16,
|
|
|
|
regex: /^[a-zA-Z0-9]+(_?[a-zA-Z0-9])*$/,
|
|
|
|
allowNull: true,
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
|
|
|
exits: {
|
2020-04-03 00:35:25 +05:00
|
|
|
emailAlreadyInUse: {
|
|
|
|
responseType: 'conflict',
|
|
|
|
},
|
|
|
|
usernameAlreadyInUse: {
|
2019-11-05 18:01:42 +05:00
|
|
|
responseType: 'conflict',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2019-11-05 18:01:42 +05:00
|
|
|
async fn(inputs, exits) {
|
2020-04-03 00:35:25 +05:00
|
|
|
const values = _.pick(inputs, ['email', 'password', 'name', 'username']);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
const user = await sails.helpers
|
|
|
|
.createUser(values, this.req)
|
2020-04-03 00:35:25 +05:00
|
|
|
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE)
|
|
|
|
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
return exits.success({
|
2019-11-05 18:01:42 +05:00
|
|
|
item: user,
|
2019-08-31 04:07:25 +05:00
|
|
|
});
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|