改进没有公开 email 的提示

This commit is contained in:
alsotang 2019-08-20 22:35:11 +08:00
parent 3fd1fcc8a7
commit 543a4e4ccd
3 changed files with 11 additions and 11 deletions

View File

@ -9,6 +9,10 @@ var validator = require('validator');
exports.callback = function (req, res, next) {
var profile = req.user;
var email = profile.emails && profile.emails[0] && profile.emails[0].value;
if (!email) {
return res.status(500)
.render('sign/no_github_email');
}
User.findOne({githubId: profile.id}, function (err, user) {
if (err) {
return next(err);
@ -27,10 +31,6 @@ exports.callback = function (req, res, next) {
if (err) {
// 根据 err.err 的错误信息决定如何回应用户,这个地方写得很难看
if (err.message.indexOf('duplicate key error') !== -1) {
if (err.message.indexOf('email') !== -1) {
return res.status(500)
.render('sign/no_github_email');
}
if (err.message.indexOf('loginname') !== -1) {
return res.status(500)
.send('您 GitHub 账号的用户名与之前在 CNodejs 注册的用户名重复了');
@ -68,6 +68,10 @@ exports.create = function (req, res, next) {
delete req.session.profile;
var email = profile.emails && profile.emails[0] && profile.emails[0].value;
if (!email) {
return res.status(500)
.render('sign/no_github_email');
}
if (isnew) { // 注册新账号
var user = new User({
loginname: profile.username,
@ -84,10 +88,6 @@ exports.create = function (req, res, next) {
if (err) {
// 根据 err.err 的错误信息决定如何回应用户,这个地方写得很难看
if (err.message.indexOf('duplicate key error') !== -1) {
if (err.message.indexOf('email') !== -1) {
return res.status(500)
.render('sign/no_github_email');
}
if (err.message.indexOf('loginname') !== -1) {
return res.status(500)
.send('您 GitHub 账号的用户名与之前在 CNodejs 注册的用户名重复了');

View File

@ -3,7 +3,7 @@
<div class='header'>
<ul class='breadcrumb'>
<li><a href='/'>主页</a><span class='divider'>/</span></li>
<li class='active'>注册新账号</li>
<li class='active'>通过GitHub登录成功</li>
</ul>
</div>
<div class='inner'>
@ -16,7 +16,7 @@
<label class='control-label'>通过 GitHub 帐号</label>
<div class='controls'>
<input type='submit' class='span-info' value="注册新账号">
<input type='submit' class='span-info' value="直接进入">
</div>
</div>
</form>

View File

@ -1,7 +1,7 @@
GitHub 登陆出错
<ul>
<li>您 GitHub 账号的 Email 与之前在 CNodejs 注册的 Email 重复了。</li>
<li>可能是您 GitHub 账号的 Email 已经在 CNode 注册过了。</li>
<li>
<p>也可能是您的 GitHub 没有提供公开的 Profile Email 导致注册失败。</p>