-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
519 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,30 @@ | ||
FROM debian:stable-slim as base | ||
FROM debian:11.6-slim as builder | ||
|
||
RUN useradd -md /app bao | ||
WORKDIR /app | ||
ENV PATH "/app/.bun/bin:$PATH" | ||
RUN apt-get update -y | ||
RUN apt-get install -y openssl | ||
|
||
FROM base as basenv | ||
# please don't haunt me | ||
RUN apt-get install curl unzip nodejs -y | ||
RUN apt update | ||
RUN apt install curl unzip -y | ||
|
||
FROM basenv as init | ||
RUN curl -fsSL https://bun.sh/install | bash | ||
RUN curl https://bun.sh/install | bash | ||
|
||
FROM basenv as benv | ||
COPY package.json . | ||
COPY bun.lockb . | ||
|
||
COPY --from=init --chown=bao /root /app | ||
USER bao | ||
RUN /root/.bun/bin/bun install --production | ||
|
||
FROM benv as build | ||
# ? ------------------------- | ||
FROM gcr.io/distroless/base | ||
|
||
COPY --chown=bao . . | ||
RUN bun install \ | ||
&& bun run init \ | ||
&& bun run build | ||
WORKDIR /app | ||
|
||
COPY --from=builder /root/.bun/bin/bun bun | ||
COPY --from=builder /app/node_modules node_modules | ||
|
||
COPY src src | ||
# COPY public public | ||
# COPY tsconfig.json . | ||
|
||
FROM base as runtime | ||
ENV ENV production | ||
CMD ["./bun", "src/index.ts"] | ||
|
||
COPY --from=init --chown=bao /root /app | ||
COPY --from=build --chown=bao /app/package.json /app/dist /app/node_modules/.prisma/client/*.node ./ | ||
COPY --chown=bao prisma ./ | ||
USER bao | ||
# RUN bun install -p | ||
CMD ["/app/.bun/bin/bun", "index.js"] | ||
EXPOSE 3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { Elysia, t } from "elysia"; | ||
import { saltcheck } from "../../utils/cipher"; | ||
import { protocol } from "../../shared"; | ||
import { tokener } from "../../trusted"; | ||
import { prisma } from "../func/db"; | ||
|
||
const mgex = /^[a-zA-Z0-9_]{2,16}$/; | ||
|
||
export default (app: Elysia) => | ||
app.group("/auth", (app) => | ||
app.post( | ||
"/", | ||
async ({ body: { username, password: ipassword }, set }) => { | ||
const fetch = await prisma.credential.findUnique({ | ||
where: { | ||
username: username, | ||
}, | ||
select: { | ||
password: true, | ||
realname: true, | ||
pf: { | ||
select: { | ||
id: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
if (fetch) { | ||
const { password, realname } = fetch; | ||
if (saltcheck(ipassword, password)) { | ||
const f = protocol.serialize(username, fetch.pf?.id); | ||
return { | ||
success: true, | ||
msg: "Authenticated as " + realname, | ||
token: tokener.sign(f), | ||
}; | ||
} | ||
// return new ErrorResponse( | ||
else { | ||
set.status = 400; | ||
return "Fail password"; | ||
} | ||
// 401 | ||
// ); | ||
} else { | ||
set.status = 404; | ||
return "User not found"; | ||
} | ||
}, | ||
{ | ||
body: t.Object({ | ||
username: t.String({ | ||
default: "Console", | ||
// format: "regex", | ||
// pattern: "/^[a-zA-Z0-9_]{2,16}$/", | ||
minLength: 2, | ||
maxLength: 16, | ||
}), | ||
password: t.String({ | ||
default: "f".repeat(64), | ||
description: | ||
"The password, hashed with SHA256 Digest once, encode in Hex and lowercased.", | ||
// format: "regex", | ||
// pattern: "/^[0-9a-f]*$/", | ||
minLength: 64, | ||
maxLength: 64, | ||
}), | ||
}), | ||
response: { | ||
200: t.Object({ | ||
success: t.Boolean({ | ||
default: true, | ||
}), | ||
msg: t.String(), | ||
token: t.String(), | ||
}), | ||
401: t.String({ | ||
default: "Fail password", | ||
description: "At this point if you tried to bruteforce your own brain to find the correct password, well the server would exaust!" | ||
}), | ||
404: t.String({ | ||
default: "User not found", | ||
description: "At this point you realize your keyboard sucks." | ||
}) | ||
}, | ||
} | ||
) | ||
); | ||
|
||
// async ({ body: { username, password: ipassword } }) => { | ||
// if (!mgex.test(username)) | ||
// return new ErrorResponse( | ||
// { | ||
// success: false, | ||
// msg: "Wrong username format?", | ||
// }, | ||
// 400 | ||
// ); | ||
// const fetch = await prisma.credential.findUnique({ | ||
// where: { | ||
// username: username, | ||
// }, | ||
// select: { | ||
// password: true, | ||
// realname: true, | ||
// pf: { | ||
// select: { | ||
// id: true, | ||
// }, | ||
// }, | ||
// }, | ||
// }); | ||
// if (fetch) { | ||
// const { password, realname } = fetch; | ||
// if (saltcheck(ipassword, password)) { | ||
// const f = protocol.serialize(username, fetch.pf?.id); | ||
// // return { | ||
// // success: true, | ||
// // msg: "Authenticated as " + realname, | ||
// // token: tokener.sign(f), | ||
// // }; | ||
// } | ||
// // else | ||
// // return new ErrorResponse( | ||
// // { success: false, msg: "Password check failed!", code: "fpwd" }, | ||
// // 401 | ||
// // ); | ||
// } else { | ||
// return new ErrorResponse( | ||
// { success: false, msg: "User not found?", code: "nusr" }, | ||
// 404 | ||
// ); | ||
// } | ||
// }; |
Oops, something went wrong.