userController.js 1.6 KB
var userModel =  require('../model/userModel');
var saitMd5 = require('../util/saltMD5')
var status = require('../util/resTemplate') 
const userService = require('../services/userService')
const uuid = require('../util/UuidUtil')


var userController =function (){

};

userController.prototype.addUser = async(ctx, next) =>{
    var params = ctx.request.body;
    const pw = saitMd5.md5AddSalt(params.password)
    console.dir(params.password.length,7)
    console.dir(params.password.length<6)
    

    if(!params.loginName){
        return status.paramError('loginName');
    }else if(!params.password){
        return status.paramError('password','不能为空');        
    }if(params.password.length < 6){
        return status.paramError('password','不得小于6位');                
    }
    var user = {
        loginName:params.loginName,
        password:pw.md5Pass,
        salt:pw.salt,
        userType:params.type
    }
    try{
        return await userService.addUser(user)        
    }catch (e){ 
        throw new Error(e);         
    }
}
userController.prototype.login = async(ctx, next) =>{
    const body = ctx.request.body;
    if(!body.name){
        return status.paramError('name');        
    }else if(!body.password){
        return status.paramError('password');
    }

    try{
        // let userData =  await userService.login(body.name ,body.password);
        // delete userData.password;
        // delete userData.salt;
        return await userService.login(body.name ,body.password);
        
    }catch (we){ 
        throw new Error(we)
    }

}
module.exports = new userController();