vuvivian's blog

越努力,越幸运.

  1. 1. 使用三方 gravatar处理头像
  2. 2. api。https://www.npmjs.com/package/gravatar
  3. 3. 在https://en.gravatar.com/ 注册的email和头像即为邮箱的头像
  4. 4. 使用

使用三方 gravatar处理头像

npm install gravatar

api。https://www.npmjs.com/package/gravatar

https://en.gravatar.com/ 注册的email和头像即为邮箱的头像

使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const gravatar = require('gravatar');
router.post('/register', (req, res) => {
console.log(req.body);
// 查询数据库中是否拥有邮箱
User.findOne({email: req.body.email})
.then((user) => {
if(user){
return res.status(400).json({email: "邮箱已被注册"});
} else {
const avatar = gravatar.url(req.body.email, {s: '200', r: 'pg', d: 'mm'});
let newUser = new User({
name:req.body.name,
email:req.body.email,
password: req.body.password,
avatar,
});
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(newUser.password, salt, function(err, hash) {
// Store hash in your password DB.
if (err) throw err;

newUser.password = hash;
newUser.save()
.then(user => res.json(user))
.catch(err => console.log(err))

});
});
}
})
})
本文最后更新于 天前,文中所描述的信息可能已发生改变