一點點進擊前端--vue3.0資金權限管理系統

初始化項目

在這裏插入圖片描述
創建入口文件index.js
在這裏插入圖片描述
全局安裝nodemon(實現後臺熱部署)

cnpm install nodemon -g
在這裏插入圖片描述
在這裏插入圖片描述

熱部署的啓動方式

npm run server

需要安裝的依賴

npm install express  # node的服務器插件
npm install bcrypt   # 給密碼進行加密的插件
npm install express
npm install express
npm install express
npm install express
npm install express

想mongo db中出入數據

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

//註冊接口
router.post('/register',(req,res)=>{
    User.findOne({email:req.body.email})
        .then((user)=>{
            if(user){
                return res.status(400).json('郵箱已被註冊!')
            }else{
               // const url = gravatar.url(req.body.email, {s: '200', r: 'pg', d: 'mm'});
                const newUser = new User({
                    name:req.body.name,
                    email:req.body.email,
                    password:req.body.password,
                    identity:req.body.identity
                })
                //密碼加密
                bcrypt.genSalt(10, function(err, salt) {
                    bcrypt.hash(newUser.password, salt, (err, hash)=> {
                        if(err) throw err;
                        newUser.password = hash;
                        newUser.save()
                            .then(user=>res.json(user))
                            .catch(err=>console.log(err))
                    });
                });
            }
        })
})

使用jwt(token方式進行登錄)

 //jwt.sign("規則","加密名字(密鑰)","過期時間","箭頭函數")
   jwt.sign(rule,'secret',{ expiresIn:3600 },(err,token)=>{}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章