Skip to content

Commit

Permalink
Merge pull request #2 from tomatobang/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
CShame authored Jul 9, 2018
2 parents 69ada1c + 7c56762 commit 2c83d4b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/io/controller/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ module.exports = (app: Application) => {
request_time: new Date().valueOf(),
state: 1,
};
// TODO: 不能重复发送好友请求
// TODO: 不能重复发送好友请求( 目前使用逐渐验证 )
await ctx.service.userFriend.create(user_friend);

this.notify(to, 'receive_friend_request', from);
Expand Down
10 changes: 8 additions & 2 deletions app/io/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ import { Application, Context } from 'egg';

module.exports = (app: Application) => {
return async function(ctx: Context, next) {
ctx.logger.info('auth!');
await next;
const token = ctx.socket.handshake.query.token;
const reply = await app['redis'].get(token);
if (reply) {
app['redis'].expire(token, 3 * 24 * 60 * 60);
await next;
} else {
ctx.socket.disconnect();
}
ctx.logger.info('disconnect!');
};
};

0 comments on commit 2c83d4b

Please sign in to comment.