以下是身份验证流程的步骤:
如何解决这个请帮帮我。我的一些代码如下所示。
var UserSchema = new Schema({
name: String,
email: {type: String, required: true, select: true},
mobile: {type: String, required: true, select: true},
password: {type: String, required: true, select: true},
});
vm.submitPost = function(userData){
$http({
url: 'http://192.168.2.8:7200/api/pages/auth/register',
method: 'POST',
data: userData
}).then(function(res) {
if(res.data.success){
$location.path('/pages/auth/otp');
} else {
alert('Please fill all credentials');
}
}, function(error) {
alert(error.data);
});
};
router.post('/pages/auth/register',function(req, res, next){
var user = new User({
name: req.body.username,
email: req.body.email,
password: req.body.password,
mobile: req.body.mobile,
});
var secret = "mysecretkey";
var code = otp.generate(secret);
var insertOtp = function(db, callback) {
db.collection('otp').createIndex( { "createdAt": 1 }, { expireAfterSeconds: 10 } );
db.collection('otp').insertOne( {
"createdAt": new Date(),
"generatedOtp": code,
"logEvent": 2,
"logMessage": "Success!"
}, function(err, result) {
assert.equal(err, null);
callback(result);
});
};
MongoClient.connect(config.database, function(err, db) {
assert.equal(null, err);
insertOtp(db, function(err,docs) {
db.close();
});
});
var mailOptions={
to : req.body.email,
subject : 'OTP',
text : "Your One-Time Password is "+code
}
transport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
res.end("error");
}else{
res.end("sent");
}
});
user.save(function(err){
if(err){
res.send(err);
return;
}
res.json({
success:true,
message: 'User has been created!'
});
});
});
答案 0 :(得分:2)
当用户通过OTP验证时,为您的架构添加活动属性,默认值为false,然后将此属性设置为true,并允许用户在此属性为true时登录。
var UserSchema = new Schema({
name: String,
email: {type: String, required: true, select: true},
mobile: {type: String, required: true, select: true},
password: {type: String, required: true, select: true},
active:{ type: 'Boolean',
default: false}
});