#6434 - SignIn issue_improve-signInLogMethod #1848

Closed
jsegarra wants to merge 65 commits from 6434-improve-signInLog into test
2 changed files with 16 additions and 10 deletions
Showing only changes of commit 891738bd57 - Show all commits

View File

@ -124,10 +124,16 @@ module.exports = function(Self) {
return email.send();
});
Self.signInValidate = (user, userToken) => {
Self.signInValidate = async(user, userToken) => {
const [[key, value]] = Object.entries(Self.userUses(user));
if (userToken[key].toLowerCase() !== value.toLowerCase()) {
const isOwner = userToken[key].toLowerCase() !== value.toLowerCase();
await Self.app.models.SignInLog.create({
token: token.id,
userFk: userToken.id,
ip: ctx.req.ip,
owner: isOwner
});
if (isOwner) {
console.error('ERROR!!! - Signin with other user', userToken, user);
throw new UserError('Try again');
}
@ -139,12 +145,7 @@ module.exports = function(Self) {
const userToken = await token.user.get();
await Self.app.models.SignInLog.create({
token: token.id,
userFk: userToken.id,
ip: ctx.req.ip
});
Self.signInValidate(user, userToken);
await Self.signInValidate(user, userToken);
try {
await Self.app.models.Account.sync(userToken.name, password);

View File

@ -25,7 +25,12 @@
"type": "number"
},
"ip": {
"type": "string"
"type": "string"
},
"owner": {
"type": "boolean",
"required": true,
"default": true
}
},
"relations": {