Skip to content

Commit

Permalink
version 2.2.0 - update dependents
Browse files Browse the repository at this point in the history
  • Loading branch information
helloyou2012 committed Dec 9, 2020
1 parent 6a97a69 commit 9980144
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
5 changes: 2 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "auth-center",
"version": "2.1.2",
"version": "2.2.0",
"description": "auth center with TOTP",
"main": "app/index.js",
"bin": {
Expand Down Expand Up @@ -67,7 +67,6 @@
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.2",
"jquery": "^3.5.1",
"koa-passport": "^4.1.3",
"mocha": "^8.2.1",
Expand All @@ -89,7 +88,7 @@
"koa-bodyparser": "^4.3.0",
"koa-csrf": "^3.0.8",
"koa-logger": "^3.2.1",
"koa-orm": "^3.0.2",
"koa-orm": "^3.2.1",
"koa-router": "^10.0.0",
"koa-session": "^6.1.0",
"koa-static": "^5.0.0",
Expand Down
20 changes: 10 additions & 10 deletions src/controllers/admin.js
Expand Up @@ -18,14 +18,14 @@ export async function checkLogin (ctx, next) {
}

export async function searchUser (ctx) {
const { User } = ctx.orm();
const { User, Op } = ctx.orm();
const q = ctx.request.body.q || '';
const users = await User.findAll({
attributes: ['email'],
where: {
enable: 1,
email: {
$like: q + '%'
[Op.like]: q + '%'
}
},
offset: 0,
Expand All @@ -35,14 +35,14 @@ export async function searchUser (ctx) {
}

export async function userList (ctx) {
const { User } = ctx.orm();
const { User, Op } = ctx.orm();
const page = parseInt(ctx.query.p, 10) || 1;
const query = ctx.query.q || '';
const limit = 20;
const offset = (page - 1) * limit;
const where = { enable: 1 };
if (query) {
where.email = { $like: `%${query}%` };
where.email = { [Op.like]: `%${query}%` };
}
const users = await User.findAndCountAll({
where,
Expand All @@ -65,14 +65,14 @@ export async function userList (ctx) {
}

export async function clientList (ctx) {
const { Client } = ctx.orm();
const { Client, Op } = ctx.orm();
const page = parseInt(ctx.query.p, 10) || 1;
const query = ctx.query.q || '';
const limit = 20;
const offset = (page - 1) * limit;
const where = {};
if (query) {
where.name = { $like: `%${query}%` };
where.name = { [Op.like]: `%${query}%` };
}
const clients = await Client.findAndCountAll({
where,
Expand Down Expand Up @@ -208,7 +208,7 @@ export async function generateSecret (ctx) {
}

export async function roleList (ctx) {
const { User, Role, Client, DicRole } = ctx.orm();
const { User, Role, Client, DicRole, Op } = ctx.orm();
const page = parseInt(ctx.query.p, 10) || 1;
const query = ctx.query.q || '';
const client = ctx.query.client;
Expand All @@ -219,11 +219,11 @@ export async function roleList (ctx) {
limit: 100,
attributes: ['id'],
where: {
email: { $like: `%${query}%` }
email: { [Op.like]: `%${query}%` }
}
});
where.user_id = {
$in: temp.map(v => v.id)
[Op.in]: temp.map(v => v.id)
};
}
if (client) {
Expand All @@ -241,7 +241,7 @@ export async function roleList (ctx) {
const users = await User.findAll({
attributes: ['id', 'email'],
where: {
id: { $in: roles.rows.map(v => v.user_id) }
id: { [Op.in]: roles.rows.map(v => v.user_id) }
}
});
const userMap = users.reduce((o, c) => {
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/user.js
Expand Up @@ -5,7 +5,7 @@ import randomColor from 'randomcolor';
import { totp, getCaptcha } from '../util';

export async function home (ctx) {
const { Role, Client } = ctx.orm();
const { Role, Client, Op } = ctx.orm();
const { user } = ctx.session;
const roles = await Role.findAll({
attributes: ['client_id'],
Expand All @@ -14,8 +14,8 @@ export async function home (ctx) {
const clients = await Client.findAll({
attributes: ['name', 'name_cn', 'redirect_uri'],
where: {
id: { $in: roles.map(r => r.client_id) },
redirect_uri: { $ne: '' }
id: { [Op.in]: roles.map(r => r.client_id) },
redirect_uri: { [Op.ne]: '' }
}
});
const colors = randomColor({
Expand Down
4 changes: 2 additions & 2 deletions src/middlewares/log.js
Expand Up @@ -11,7 +11,7 @@ const ACTIONS = {

export default function (app) {
app.use(async function logFn (ctx, next) {
const { Log } = ctx.orm();
const { Log, Op } = ctx.orm();
ctx.log = async (user, action) => {
try {
await Log.create({
Expand All @@ -29,7 +29,7 @@ export default function (app) {
where: {
user,
action: ACTIONS[action],
createdAt: { $gt: date }
createdAt: { [Op.gt]: date }
}
});
};
Expand Down

0 comments on commit 9980144

Please sign in to comment.