Fix signin (#5181)
* Revert "Fix signin history (#5180)"
This reverts commit a97c14a7b7
.
* fix signin
* failはfail専用に
* fix password less 200
This commit is contained in:
parent
a97c14a7b7
commit
d8c835fa51
|
@ -53,9 +53,9 @@ export default async (ctx: Koa.BaseContext) => {
|
||||||
// Compare password
|
// Compare password
|
||||||
const same = await bcrypt.compare(password, profile.password!);
|
const same = await bcrypt.compare(password, profile.password!);
|
||||||
|
|
||||||
async function fail(status?: number, failure?: {error: string}) {
|
async function fail(status?: number, failure?: { error: string }) {
|
||||||
// Append signin history
|
// Append signin history
|
||||||
const record = await Signins.save({
|
await Signins.save({
|
||||||
id: genId(),
|
id: genId(),
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
@ -64,23 +64,19 @@ export default async (ctx: Koa.BaseContext) => {
|
||||||
success: false
|
success: false
|
||||||
});
|
});
|
||||||
|
|
||||||
// Publish signin event
|
ctx.throw(status || 500, failure || { error: 'someting happened' });
|
||||||
publishMainStream(user.id, 'signin', await Signins.pack(record));
|
|
||||||
|
|
||||||
if (status && failure) {
|
|
||||||
ctx.throw(status, failure);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!profile.twoFactorEnabled) {
|
if (!profile.twoFactorEnabled) {
|
||||||
if (same) {
|
if (same) {
|
||||||
signin(ctx, user);
|
signin(ctx, user);
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
await fail(403, {
|
await fail(403, {
|
||||||
error: 'incorrect password'
|
error: 'incorrect password'
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
|
@ -169,6 +165,7 @@ export default async (ctx: Koa.BaseContext) => {
|
||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
signin(ctx, user);
|
signin(ctx, user);
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
await fail(403, {
|
await fail(403, {
|
||||||
error: 'invalid challenge data'
|
error: 'invalid challenge data'
|
||||||
|
@ -191,6 +188,7 @@ export default async (ctx: Koa.BaseContext) => {
|
||||||
await fail(403, {
|
await fail(403, {
|
||||||
error: 'no keys found'
|
error: 'no keys found'
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 32 byte challenge
|
// 32 byte challenge
|
||||||
|
@ -219,6 +217,5 @@ export default async (ctx: Koa.BaseContext) => {
|
||||||
ctx.status = 200;
|
ctx.status = 200;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// never get here
|
||||||
await fail();
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue