fix: 第三方登录的bug

This commit is contained in:
wenbo.dong 2017-09-27 14:15:49 +08:00
parent eb8bead6a6
commit 8fb625b523

View File

@ -24,7 +24,7 @@ class userController extends baseController {
* @foldnumber 10
* @param {String} email email名称不能为空
* @param {String} password 密码不能为空
* @returns {Object}
* @returns {Object}
* @example ./api/user/login.json
*/
async login(ctx) { //登录
@ -68,7 +68,7 @@ class userController extends baseController {
* @method GET
* @category user
* @foldnumber 10
* @returns {Object}
* @returns {Object}
* @example ./api/user/logout.json
*/
@ -144,6 +144,7 @@ class userController extends baseController {
type: 'third'
};
user = await userInst.save(data);
await this.handlePrivateGroup(user._id);
yapi.commons.sendMail({
to: email,
contents: `<h3>亲爱的用户:</h3><p>您好感谢使用YApi平台你的邮箱账号是${email}</p>`
@ -151,7 +152,6 @@ class userController extends baseController {
}
this.setLoginCookie(user._id, user.passsalt);
await handlePrivateGroup(user._id);
return true;
} catch (e) {
console.error('third_login:', e.message); // eslint-disable-line
@ -226,7 +226,7 @@ class userController extends baseController {
email: this.getEmail()
}]
})
}
setLoginCookie(uid, passsalt) {
@ -251,7 +251,7 @@ class userController extends baseController {
* @param {String} email email名称不能为空
* @param {String} password 密码不能为空
* @param {String} [username] 用户名
* @returns {Object}
* @returns {Object}
* @example ./api/user/login.json
*/
async reg(ctx) { //注册
@ -325,8 +325,8 @@ class userController extends baseController {
* @foldnumber 10
* @param {Number} [page] 分页页码
* @param {Number} [limit] 分页大小,默认为10条
* @returns {Object}
* @example
* @returns {Object}
* @example
*/
async list(ctx) {
let page = ctx.request.query.page || 1,
@ -353,8 +353,8 @@ class userController extends baseController {
* @param id 用户uid
* @category user
* @foldnumber 10
* @returns {Object}
* @example
* @returns {Object}
* @example
*/
async findById(ctx) { //根据id获取用户信息
try {
@ -392,8 +392,8 @@ class userController extends baseController {
* @param id 用户uid
* @category user
* @foldnumber 10
* @returns {Object}
* @example
* @returns {Object}
* @example
*/
async del(ctx) { //根据id删除一个用户
try {
@ -426,8 +426,8 @@ class userController extends baseController {
* @param [email] String
* @category user
* @foldnumber 10
* @returns {Object}
* @example
* @returns {Object}
* @example
*/
async update(ctx) { //更新用户信息
try {
@ -474,11 +474,11 @@ class userController extends baseController {
/**
* 上传用户头像
* @interface /user/upload_avatar
* @method POST
* @method POST
* @param {*} basecode base64编码通过h5 api传给后端
* @category user
* @returns {Object}
* @example
* @returns {Object}
* @example
*/
async uploadAvatar(ctx) {
@ -490,7 +490,7 @@ class userController extends baseController {
let pngPrefix = 'data:image/png;base64,';
let jpegPrefix = 'data:image/jpeg;base64,';
let type;
if(basecode.substr(0, pngPrefix.length ) === pngPrefix){
if(basecode.substr(0, pngPrefix.length ) === pngPrefix){
basecode = basecode.substr(pngPrefix.length);
type = 'image/png';
}else if(basecode.substr(0, jpegPrefix.length ) === jpegPrefix){
@ -498,7 +498,7 @@ class userController extends baseController {
type = 'image/jpeg';
}else{
return ctx.body = yapi.commons.resReturn(null, 400, '仅支持jpeg和png格式的图片')
}
}
let strLength = basecode.length;
if(parseInt(strLength-(strLength/8)*2) > 200000){
return ctx.body = yapi.commons.resReturn(null, 400, '图片大小不能超过200kb');
@ -507,7 +507,7 @@ class userController extends baseController {
let avatarInst = yapi.getInst(avatarModel);
let result = await avatarInst.up(this.getUid(), basecode, type)
ctx.body = yapi.commons.resReturn(result);
} catch (e) {
ctx.body = yapi.commons.resReturn(null, 401, e.message);
}
@ -517,15 +517,15 @@ class userController extends baseController {
/**
* 根据用户uid头像
* @interface /user/avatar
* @method GET
* @param {*} uid
* @method GET
* @param {*} uid
* @category user
* @returns {Object}
* @example
* @returns {Object}
* @example
*/
async avatar(ctx) {
async avatar(ctx) {
try{
let uid = ctx.query.uid ? ctx.query.uid: this.getUid();
let avatarInst = yapi.getInst(avatarModel);
@ -536,7 +536,7 @@ class userController extends baseController {
type = 'image/png'
}else{
type = data.type;
dataBuffer = new Buffer(data.basecode, 'base64');
dataBuffer = new Buffer(data.basecode, 'base64');
}
ctx.set('Content-type', type);
@ -598,9 +598,9 @@ class userController extends baseController {
* @category user
* @foldnumber 10
* @param {String} type 可选group|interface|project
* @param {Number} id
* @param {Number} id
* @return {Object}
* @example
* @example
*/
async project(ctx) {
let { id, type } = ctx.request.query;
@ -609,7 +609,7 @@ class userController extends baseController {
if (type === 'interface') {
let interfaceInst = yapi.getInst(interfaceModel);
let interfaceData = await interfaceInst.get(id)
result.interface = interfaceData;
result.interface = interfaceData;
type = 'project';
id = interfaceData.project_id;
}
@ -636,7 +636,7 @@ class userController extends baseController {
if (type === 'group') {
let groupInst = yapi.getInst(groupModel);
let groupData = await groupInst.get(id);
result.group = groupData.toObject();
result.group = groupData.toObject();
let ownerAuth = await this.checkAuth(id, 'group', 'danger'), devAuth;
if(ownerAuth){
result.group.role = 'owner'
@ -648,7 +648,7 @@ class userController extends baseController {
result.group.role = 'member'
}
}
}
return ctx.body = yapi.commons.resReturn(result)
@ -660,4 +660,4 @@ class userController extends baseController {
}
module.exports = userController;
module.exports = userController;