add activation and forget tokens

parent 62906b73
/**
* Created by danilaeremin on 17.06.16.
*/
'use strict';
const dbUtils = require('db-utils');
module.exports = function (ActivationToken) {
return {
saveActivationToken : function(token, userId) {
return dbUtils.dbCreateItem(ActivationToken,{token: token, user: userId});
},
getActivationToken : function(token) {
return dbUtils.dbFindOne(ActivationToken, {token: token});
},
removeActivationToken : function(token) {
return dbUtils.dbRemoveItem(ActivationToken, {token: token});
}
};
};
/**
* Created by danilaeremin on 17.06.16.
*/
'use strict';
const dbUtils = require('db-utils');
module.exports = function (ForgetToken) {
return {
saveForgetToken : function(token, userId) {
return dbUtils.dbCreateItem(ForgetToken,{token: token, user: userId});
},
getForgetToken : function(token) {
return dbUtils.dbFindOne(ForgetToken, {token: token});
},
removeForgetToken : function(token) {
return dbUtils.dbRemoveItem(ForgetToken, {token: token});
}
};
};
......@@ -38,10 +38,10 @@ module.exports = function (User) {
return dbUtils.dbCreateItem(User, newUser);
},
createSocialUser : function (socialId, accountType, mail, name, surname, meta) {
createVKUser : function (socialId, accountType, mail, name, surname, meta) {
var newUser = {
username : surname + " " + name[0] + ".",
login : socialId,
login : socialId,// TODO random string
password : ' ',
accountType : accountType,
mail : mail,
......@@ -49,7 +49,7 @@ module.exports = function (User) {
surname : surname,
meta:meta,
activated : true,
isSocial : true
vk_login : socialId
};
return dbUtils.dbCreateItem(User, newUser);
......
......@@ -21,7 +21,7 @@ module.exports = function (uri) {
return dbUtils.connect(uri)
.then(connection => {
let models = ['AccessToken','RefreshToken','User','Code','Client','Course', 'Contest', 'Task', 'Program'];
let models = ['ActivationToken','ForgetToken','AccessToken','RefreshToken','User','Code','Client','Course', 'Contest', 'Task', 'Program'];
for (let i = 0; i < models.length; i++) {
let schema = require('./models/' + models[i]);
......@@ -36,4 +36,4 @@ module.exports = function (uri) {
return dbHelper;
});
}
\ No newline at end of file
};
\ No newline at end of file
/**
* Created by antonded on 23.11.14.
*/
var mongoose = require('mongoose');
var ActivationTokenSchema = new mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
token: {
type: String,
unique: true,
required: true
},
created: {
type: Date,
default: Date.now,
required: true,
expires: config.get('activationTokenLife')
}
});
module.exports = ActivationTokenTokenSchema;
\ No newline at end of file
/**
* Created by antonded on 23.11.14.
*/
var mongoose = require('mongoose');
var AccessTokenSchema = new mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
token: {
type: String,
unique: true,
required: true
},
created: {
type: Date,
default: Date.now,
required: true,
expires: config.get('forgetTokenLife')
}
});
module.exports = AccessTokenSchema;
\ No newline at end of file
......@@ -68,7 +68,9 @@ var hashPasswordOnUpdate = function(next) {
global.USER_TYPE = {
ADMIN : "admin",
USER : "user"
USER : "user",
TEACHER : "teacher",
PARENT : "parent"
};
var UserSchema = new mongoose.Schema({
......@@ -109,13 +111,16 @@ var UserSchema = new mongoose.Schema({
},
lastLogin : {
type: Date,
equired: true,
required: true,
default: Date.now
},
isSocial: {
type: Boolean,
required: true,
default: false
vk_login: {
type: String,
unique: true
},
fb_login: {
type: String,
unique: true
},
meta: {
type: {},
......
{
"name": "mirera-db",
"version": "1.4.3",
"version": "1.5.0",
"description": "DB utils for mirera program testing server",
"main": "index.js",
"scripts": {
......
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