mail, login and password now not required

parent 2dff8a9c
......@@ -23,6 +23,9 @@ module.exports = function (User) {
getUserByVKLogin : function (vk_login) {
return dbUtils.dbFindOne(User, {vk_login: vk_login});
},
getUserByFBLogin : function (fb_login) {
return dbUtils.dbFindOne(User, {fb_login: fb_login});
},
getUserByIds : function (ids) {
return dbUtils.dbFind(User, { _id: { $in: ids }});
},
......@@ -41,24 +44,28 @@ module.exports = function (User) {
return dbUtils.dbCreateItem(User, newUser);
},
createVKUser : function (login, socialId, accountType, mail, name, surname, meta) {
createVKUser : function (login, vk_uid, accountType, name, surname, meta) {
var newUser = {
username : surname + " " + name[0] + ".",
login : login,
password : ' ',
accountType : accountType,
mail : mail,
name : name,
surname : surname,
meta : meta,
activated : true,
vk_login : socialId
vk_login : vk_uid
};
return dbUtils.dbCreateItem(User, newUser);
},
addVKLogin : function (userId,socialId) {
return dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {vk_login : socialId});
addLogin : function (userId,login) {
return dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {login : login});
},
addVKLogin : function (userId,vk_login) {
return dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {vk_login : vk_login});
},
addFBLogin : function (userId,fb_login) {
return dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {fb_login : fb_login});
},
changeUserAccountType : function (userId, accountType) {
return dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {accountType : accountType});
......@@ -75,13 +82,12 @@ module.exports = function (User) {
updatePassword : function (userId, password) {
return dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {password : password});
},
updateUserInfo : function (userId, mail, name, surname, username, login) {
updateUserInfo : function (userId, mail, name, surname, username) {
var update = {
username : username,
mail : mail,
name : name,
surname : surname,
login : login
surname : surname
};
return dbUtils.dbFindOneAndUpdate(User, {_id : userId}, update);
......
......@@ -8,7 +8,7 @@ const bcrypt = require('bcrypt');
const SALT_WORK_FACTOR = 10;
var isValidPassword = function(candidatePassword) {
var self = this;
let self = this;
return new Promise((resolve, reject) => {
bcrypt.compare(candidatePassword, self.password, function(err, isMatch) {
if (err) {
......@@ -21,7 +21,7 @@ var isValidPassword = function(candidatePassword) {
};
var hashPassword = function(next) {
var user = this;
let user = this;
if (!user.isModified('password')) {
next();
......@@ -44,7 +44,7 @@ var hashPassword = function(next) {
};
var hashPasswordOnUpdate = function(next) {
var update = this;
let update = this;
if (update._update.password) {
bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) {
......@@ -66,36 +66,35 @@ var hashPasswordOnUpdate = function(next) {
}
};
global.USER_TYPE = {
ADMIN : "admin",
USER : "user",
TEACHER : "teacher",
PARENT : "parent"
};
var UserSchema = new mongoose.Schema({
username: {
type: String,
required: true
},
login: {
type: String,
unique: true,
required: true
unique: true
},
password: {
type: String
},
vk_login: {
type: String,
required: true
unique: true
},
accountType: {
fb_login: {
type: String,
required: true,
default: global.USER_TYPE.USER
unique: true
},
mail: {
accountType: {
type: String,
required: true
},
mail: {
type: String
},
name: {
type: String,
required: true
......@@ -114,14 +113,6 @@ var UserSchema = new mongoose.Schema({
required: true,
default: Date.now
},
vk_login: {
type: String,
unique: true
},
fb_login: {
type: String,
unique: true
},
meta: {
type: {},
required: true,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment