mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Merge branch 'captcha-n' into 'main'
Switch captcha_solved from a label event to an n-tag on a user event See merge request soapbox-pub/ditto!547
This commit is contained in:
commit
7dff4e88d4
4 changed files with 9 additions and 38 deletions
|
|
@ -51,7 +51,7 @@ const verifyCredentialsController: AppController = async (c) => {
|
||||||
|
|
||||||
const store = await Storages.db();
|
const store = await Storages.db();
|
||||||
|
|
||||||
const [author, [settingsEvent], [captcha]] = await Promise.all([
|
const [author, [settingsEvent]] = await Promise.all([
|
||||||
getAuthor(pubkey, { signal: AbortSignal.timeout(5000) }),
|
getAuthor(pubkey, { signal: AbortSignal.timeout(5000) }),
|
||||||
|
|
||||||
store.query([{
|
store.query([{
|
||||||
|
|
@ -60,15 +60,6 @@ const verifyCredentialsController: AppController = async (c) => {
|
||||||
'#d': ['pub.ditto.pleroma_settings_store'],
|
'#d': ['pub.ditto.pleroma_settings_store'],
|
||||||
limit: 1,
|
limit: 1,
|
||||||
}]),
|
}]),
|
||||||
|
|
||||||
store.query([{
|
|
||||||
kinds: [1985],
|
|
||||||
authors: [Conf.pubkey],
|
|
||||||
'#L': ['pub.ditto.captcha'],
|
|
||||||
'#l': ['solved'],
|
|
||||||
'#p': [pubkey],
|
|
||||||
limit: 1,
|
|
||||||
}]),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let settingsStore: Record<string, unknown> | undefined;
|
let settingsStore: Record<string, unknown> | undefined;
|
||||||
|
|
@ -79,8 +70,8 @@ const verifyCredentialsController: AppController = async (c) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const account = author
|
const account = author
|
||||||
? await renderAccount(author, { withSource: true, settingsStore, captcha })
|
? await renderAccount(author, { withSource: true, settingsStore })
|
||||||
: await accountFromPubkey(pubkey, { withSource: true, settingsStore, captcha });
|
: await accountFromPubkey(pubkey, { withSource: true, settingsStore });
|
||||||
|
|
||||||
return c.json(account);
|
return c.json(account);
|
||||||
};
|
};
|
||||||
|
|
@ -285,7 +276,6 @@ const updateCredentialsController: AppController = async (c) => {
|
||||||
const pubkey = await signer.getPublicKey();
|
const pubkey = await signer.getPublicKey();
|
||||||
const body = await parseBody(c.req.raw);
|
const body = await parseBody(c.req.raw);
|
||||||
const result = updateCredentialsSchema.safeParse(body);
|
const result = updateCredentialsSchema.safeParse(body);
|
||||||
const store = await Storages.db();
|
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
return c.json(result.error, 422);
|
return c.json(result.error, 422);
|
||||||
|
|
@ -335,17 +325,8 @@ const updateCredentialsController: AppController = async (c) => {
|
||||||
c,
|
c,
|
||||||
);
|
);
|
||||||
|
|
||||||
const [captcha] = await store.query([{
|
|
||||||
kinds: [1985],
|
|
||||||
authors: [Conf.pubkey],
|
|
||||||
'#L': ['pub.ditto.captcha'],
|
|
||||||
'#l': ['solved'],
|
|
||||||
'#p': [pubkey],
|
|
||||||
limit: 1,
|
|
||||||
}]);
|
|
||||||
|
|
||||||
const settingsStore = result.data.pleroma_settings_store;
|
const settingsStore = result.data.pleroma_settings_store;
|
||||||
const account = await renderAccount(event, { withSource: true, settingsStore, captcha });
|
const account = await renderAccount(event, { withSource: true, settingsStore });
|
||||||
|
|
||||||
if (settingsStore) {
|
if (settingsStore) {
|
||||||
await createEvent({
|
await createEvent({
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { z } from 'zod';
|
||||||
|
|
||||||
import { AppController } from '@/app.ts';
|
import { AppController } from '@/app.ts';
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { createAdminEvent } from '@/utils/api.ts';
|
import { updateUser } from '@/utils/api.ts';
|
||||||
|
|
||||||
interface Point {
|
interface Point {
|
||||||
x: number;
|
x: number;
|
||||||
|
|
@ -169,16 +169,7 @@ export const captchaVerifyController: AppController = async (c) => {
|
||||||
|
|
||||||
if (solved) {
|
if (solved) {
|
||||||
captchas.delete(id);
|
captchas.delete(id);
|
||||||
|
await updateUser(pubkey, { captcha_solved: true }, c);
|
||||||
await createAdminEvent({
|
|
||||||
kind: 1985,
|
|
||||||
tags: [
|
|
||||||
['L', 'pub.ditto.captcha'],
|
|
||||||
['l', 'solved', 'pub.ditto.captcha'],
|
|
||||||
['p', pubkey, Conf.relay],
|
|
||||||
],
|
|
||||||
}, c);
|
|
||||||
|
|
||||||
return new Response(null, { status: 204 });
|
return new Response(null, { status: 204 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Context } from '@hono/hono';
|
import { type Context } from '@hono/hono';
|
||||||
import { HTTPException } from '@hono/hono/http-exception';
|
import { HTTPException } from '@hono/hono/http-exception';
|
||||||
import { NostrEvent, NostrFilter } from '@nostrify/nostrify';
|
import { NostrEvent, NostrFilter } from '@nostrify/nostrify';
|
||||||
import Debug from '@soapbox/stickynotes/debug';
|
import Debug from '@soapbox/stickynotes/debug';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { type NostrEvent, NSchema as n } from '@nostrify/nostrify';
|
import { NSchema as n } from '@nostrify/nostrify';
|
||||||
import { escape } from 'entities';
|
import { escape } from 'entities';
|
||||||
import { nip19, UnsignedEvent } from 'nostr-tools';
|
import { nip19, UnsignedEvent } from 'nostr-tools';
|
||||||
|
|
||||||
|
|
@ -15,7 +15,6 @@ import { renderEmojis } from '@/views/mastodon/emojis.ts';
|
||||||
type ToAccountOpts = {
|
type ToAccountOpts = {
|
||||||
withSource: true;
|
withSource: true;
|
||||||
settingsStore: Record<string, unknown> | undefined;
|
settingsStore: Record<string, unknown> | undefined;
|
||||||
captcha: NostrEvent | undefined;
|
|
||||||
} | {
|
} | {
|
||||||
withSource?: false;
|
withSource?: false;
|
||||||
};
|
};
|
||||||
|
|
@ -91,7 +90,7 @@ async function renderAccount(
|
||||||
nip05,
|
nip05,
|
||||||
},
|
},
|
||||||
ditto: {
|
ditto: {
|
||||||
captcha_solved: Boolean(opts.captcha),
|
captcha_solved: names.has('captcha_solved'),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue