Skip to content

Commit

Permalink
Added register
Browse files Browse the repository at this point in the history
  • Loading branch information
cr4yfish committed Jul 15, 2023
1 parent 9b73fe0 commit b18c4f5
Show file tree
Hide file tree
Showing 14 changed files with 649 additions and 22 deletions.
18 changes: 18 additions & 0 deletions app/api/auth/getCaptcha/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { LemmyHttp, Login, GetCaptcha} from "lemmy-js-client"

export async function POST(req: Request) {
try {
const body = await req.json();

const auth = body.auth, instance = body.instance ? `https://${body.instance}` : "https://lemmy.world";
console.log(body.instance, instance);
const client = new LemmyHttp(instance);

const response = await client.getCaptcha();
return new Response(JSON.stringify({ response }), { status: 200, headers: { 'Content-Type': 'application/json' } })

} catch (e: any) {
console.error(e);
return new Response(JSON.stringify({ error: e }), { status: 500, headers: { 'Content-Type': 'application/json' } })
}
}
1 change: 0 additions & 1 deletion app/api/auth/login/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { LemmyHttp, Login} from "lemmy-js-client"

async function userLogin(username: string, password: string, baseUrl: string) {
console.log("Logging", username, "into", baseUrl);
let client: LemmyHttp = new LemmyHttp(baseUrl);
let loginForm: Login = {
username_or_email: username,
Expand Down
22 changes: 22 additions & 0 deletions app/api/auth/signup/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { LemmyHttp, Login} from "lemmy-js-client"

export async function POST(req: Request) {
try {
const body = await req.json();

const username = body.username, password = body.password, email = body.email, show_nsfw = body.show_nsfw, instance = body.instance ? `https://${body.instance}` : "https://lemmy.world",
captcha_uuid = body.captcha_uuid, captcha_answer = body.captcha_answer, honeypot = body.honeypot, answer = body.answer;

const client = new LemmyHttp(instance);

console.log(username, password, email, show_nsfw, instance);

const register = await client.register({ username, password, password_verify: password, email, show_nsfw: show_nsfw, captcha_uuid, captcha_answer, honeypot, answer });

return new Response(JSON.stringify({ register }), { status: 200, headers: { 'Content-Type': 'application/json' } })

} catch (e: any) {
console.error(e);
return new Response(JSON.stringify({ error: e }), { status: 500, headers: { 'Content-Type': 'application/json' } })
}
}
16 changes: 16 additions & 0 deletions app/api/getCuratedInstances/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { parse } from "papaparse";

export async function GET(req: Request) {
try {
const url_to_csv = "https://raw.githubusercontent.com/maltfield/awesome-lemmy-instances/main/awesome-lemmy-instances.csv";

const data = parse(await (await fetch(url_to_csv)).text(), { header: true }).data;


return new Response(JSON.stringify(data), { status: 200, headers: { 'Content-Type': 'application/json' } })

} catch (e: any) {
console.error(e);
return new Response(JSON.stringify({ error: e }), { status: 500, headers: { 'Content-Type': 'application/json' } })
}
}
23 changes: 23 additions & 0 deletions app/api/getFederatedInstances/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { LemmyHttp, PostId, CommentId } from "lemmy-js-client"

export async function GET(req: Request) {
try {

// get params from Resuest
let params = new URL(req.url).searchParams;
let auth = params.get("auth") || "";
let instance = params.get("instance") || undefined;

let client: LemmyHttp = new LemmyHttp((instance && instance !== "undefined") ? `https://${instance}` : "https://lemmy.world");

let instances = await client.getFederatedInstances({
auth: auth as unknown as string,
});

return new Response(JSON.stringify(instances), { status: 200, headers: { 'Content-Type': 'application/json' } })

} catch (e: any) {
console.error(e);
return new Response(JSON.stringify({ error: e }), { status: 500, headers: { 'Content-Type': 'application/json' } })
}
}
2 changes: 1 addition & 1 deletion app/auth/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function Layout({
}, [navbar])

return (
<div>
<div className=" w-full min-h-screen">
{children}
</div>
)
Expand Down
1 change: 0 additions & 1 deletion app/auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export default function Login() {
// get user details
const user = await getUserDetails(jwt.jwt, form.instance);

console.log("Got user:", user);

setSession({ ...session, jwt: jwt.jwt, user: user })

Expand Down
Loading

0 comments on commit b18c4f5

Please sign in to comment.