Compare commits
No commits in common. "703e16ffcd4e1e57f63e38b90942cc1ae056fcaf" and "36698c1ace782b564eda57f16d71aac6797fbaf4" have entirely different histories.
703e16ffcd
...
36698c1ace
|
@ -27,10 +27,8 @@ describe('Renew Token', () => {
|
||||||
jasmine.clock().uninstall();
|
jasmine.clock().uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should renew token', async() => {
|
it('should renew process', async() => {
|
||||||
const mockDate = new Date(startingTime + 26600000);
|
jasmine.clock().mockDate(new Date(startingTime + 21600000));
|
||||||
jasmine.clock().mockDate(mockDate);
|
|
||||||
console.log(startingTime, mockDate)
|
|
||||||
const {id} = await models.VnUser.renewToken(ctx);
|
const {id} = await models.VnUser.renewToken(ctx);
|
||||||
|
|
||||||
expect(id).not.toEqual(ctx.req.accessToken.id);
|
expect(id).not.toEqual(ctx.req.accessToken.id);
|
||||||
|
|
|
@ -20,7 +20,10 @@ describe('VnUser Sign-in()', () => {
|
||||||
let ctx = {req: {accessToken: accessToken}};
|
let ctx = {req: {accessToken: accessToken}};
|
||||||
let signInLog = await SignInLog.find({where: {token: accessToken.id}});
|
let signInLog = await SignInLog.find({where: {token: accessToken.id}});
|
||||||
|
|
||||||
expect(signInLog.length).toEqual(0);
|
expect(signInLog.length).toEqual(1);
|
||||||
|
expect(signInLog[0].userFk).toEqual(accessToken.userId);
|
||||||
|
expect(signInLog[0].owner).toEqual(true);
|
||||||
|
expect(login.token).toBeDefined();
|
||||||
|
|
||||||
await VnUser.logout(ctx.req.accessToken.id);
|
await VnUser.logout(ctx.req.accessToken.id);
|
||||||
});
|
});
|
||||||
|
|
|
@ -134,16 +134,15 @@ module.exports = function(Self) {
|
||||||
Self.signInValidate = async(user, userToken, token, ctx) => {
|
Self.signInValidate = async(user, userToken, token, ctx) => {
|
||||||
const [[key, value]] = Object.entries(Self.userUses(user));
|
const [[key, value]] = Object.entries(Self.userUses(user));
|
||||||
const isOwner = Self.rawSql(`SELECT ? = ? `, [userToken[key], value]);
|
const isOwner = Self.rawSql(`SELECT ? = ? `, [userToken[key], value]);
|
||||||
if (!isOwner) {
|
await Self.app.models.SignInLog.create({
|
||||||
await Self.app.models.SignInLog.create({
|
userName: user,
|
||||||
userName: user,
|
token: token.id,
|
||||||
token: token.id,
|
userFk: userToken.id,
|
||||||
userFk: userToken.id,
|
ip: ctx.req.ip,
|
||||||
ip: ctx.req.ip,
|
owner: isOwner
|
||||||
owner: isOwner
|
});
|
||||||
});
|
if (!isOwner)
|
||||||
throw new UserError('Try again');
|
throw new UserError('Try again');
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
DELETE FROM `account`.`signInLog` where owner <> FALSE
|
|
Loading…
Reference in New Issue