I’m trying to do a register, but i want it to check if the username is in the database or not.
because when i enter an existing username it will be accepted.
> createUser : function (credentials) {
> check(credential, Object)
> // First we check if the User already exist and if he has PW
> const USER = Accounts.findUserByEmail(credentials.email)
> if (USER !== undefined && (USER.services === undefined || USER.services.password === undefined || USER.services.password.bcrypt === undefined)) {
> Accounts.setPassword(USER._id, credentials.password)
> result = 'newPassword'
> } else {
> // user account creation (via the app)
> result = Accounts.createUser(credentials)
>
> }
> return result
May i add something like this ?
USER.profile.name === undefined
credentials.profile = { name: credentials.username }
there is my schema
let Schemas = {}
Schemas.User = new SimpleSchema({
createdAt: {
type: Date
},
// Services
services: {
type: Object,
optional: true
},
"services.password": {
type: Object,
optional: true
},
"services.password.bcrypt": {
type: String,
optional: true
},
"services.resume": {
type: Object,
blackbox: true,
optional: true
},
// Emails
emails: {
type: Array,
optional: true
},
"emails.$": {
type: Object
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
// Name
profile: {
type: Object,
optional: true
},
"profile.name": {
// optional:true,
type: String,
},
// Features (Activated or not)
"profile.features": {
type: Object,
optional: true,
blackbox: true
},
pushIds: {
type: [String],
optional: true
},
// Roles
roles: {
type: [String],
optional: true,
blackbox: true
},
})
Meteor.users.attachSchema(Schemas.User)