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