Refactoring
This commit is contained in:
parent
2771b3cd96
commit
f2c4ea49cb
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,7 +2,6 @@
|
|||
node_modules
|
||||
/dist
|
||||
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
@ -21,3 +20,5 @@ pnpm-debug.log*
|
|||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
.env
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<!-- <link rel="icon" href="/favicon.ico" /> -->
|
||||
<link rel="icon" href="/ti.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Captive Portal</title>
|
||||
</head>
|
||||
|
|
BIN
public/ti.png
Executable file
BIN
public/ti.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
|
@ -5,5 +5,5 @@ type LoginResult = {
|
|||
}
|
||||
|
||||
interface Auth {
|
||||
login(username: string, password: string): Promise<LoginResult>
|
||||
login(username: string, password: string): Promise<LoginResult> | LoginResult
|
||||
}
|
||||
|
|
10
src/server/lib/getIpFromContext.ts
Normal file
10
src/server/lib/getIpFromContext.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { Context } from '../trpc'
|
||||
|
||||
export function getIpFromContext(ctx: Context) {
|
||||
if (process.env.NODE_ENV === 'development') return '10.7.16.254'
|
||||
|
||||
const ip = ctx.ip.split(':').slice(-1)[0]
|
||||
// console.log(`IP: ${ip}`)
|
||||
|
||||
return ip
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { Client } from 'ldapts'
|
||||
|
||||
import { LdapAuth } from '../Auth/LdapAuth'
|
||||
import { LdapAuth } from '../auth/LdapAuth'
|
||||
|
||||
export async function login(username: string, password: string) {
|
||||
const ldapClient = new Client({
|
||||
|
@ -9,9 +9,9 @@ export async function login(username: string, password: string) {
|
|||
|
||||
const ldapAuth = new LdapAuth(ldapClient, 'ifms', 'DC=ifms,DC=edu,DC=br')
|
||||
|
||||
const result = await ldapAuth.login(username, password)
|
||||
const user = await ldapAuth.login(username, password)
|
||||
|
||||
console.log('Login result:', result)
|
||||
console.log('Login result:', user)
|
||||
|
||||
return result
|
||||
return user
|
||||
}
|
||||
|
|
|
@ -3,25 +3,22 @@ import * as trpcExpress from '@trpc/server/adapters/express'
|
|||
|
||||
import { z } from 'zod'
|
||||
import { login } from './lib/login'
|
||||
import { getIpFromContext } from './lib/getIpFromContext'
|
||||
|
||||
// Created for each request
|
||||
function createContext({ req, res }: trpcExpress.CreateExpressContextOptions) {
|
||||
return { ip: req.ip }
|
||||
}
|
||||
|
||||
type Context = inferAsyncReturnType<typeof createContext>
|
||||
export type Context = inferAsyncReturnType<typeof createContext>
|
||||
|
||||
export const t = initTRPC.context<Context>().create()
|
||||
|
||||
export const appRouter = t.router({
|
||||
myIp: t.procedure.query(({ ctx }) => {
|
||||
const ip = ctx.ip.split(':').slice(-1)[0]
|
||||
console.log(`IP: ${ip}`)
|
||||
|
||||
if (process.env.NODE_ENV === 'development') return '10.7.16.254'
|
||||
|
||||
return ip
|
||||
return getIpFromContext(ctx)
|
||||
}),
|
||||
|
||||
login: t.procedure
|
||||
.input(z.object({ username: z.string(), password: z.string() }))
|
||||
.mutation(async ({ input }) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user