diff --git a/.gitignore b/.gitignore
index 403adbc..834fd88 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/index.html b/index.html
index 87cb237..613592b 100644
--- a/index.html
+++ b/index.html
@@ -2,7 +2,8 @@
-
+
+
Captive Portal
diff --git a/public/ti.png b/public/ti.png
new file mode 100755
index 0000000..030eaf9
Binary files /dev/null and b/public/ti.png differ
diff --git a/src/server/Auth/LdapAuth.ts b/src/server/auth/LdapAuth.ts
similarity index 100%
rename from src/server/Auth/LdapAuth.ts
rename to src/server/auth/LdapAuth.ts
diff --git a/src/server/interfaces/Auth.ts b/src/server/interfaces/Auth.ts
index 088c845..7ad66f2 100644
--- a/src/server/interfaces/Auth.ts
+++ b/src/server/interfaces/Auth.ts
@@ -5,5 +5,5 @@ type LoginResult = {
}
interface Auth {
- login(username: string, password: string): Promise
+ login(username: string, password: string): Promise | LoginResult
}
diff --git a/src/server/lib/getIpFromContext.ts b/src/server/lib/getIpFromContext.ts
new file mode 100644
index 0000000..78d6a07
--- /dev/null
+++ b/src/server/lib/getIpFromContext.ts
@@ -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
+}
diff --git a/src/server/lib/login.ts b/src/server/lib/login.ts
index 7323945..9baaa54 100644
--- a/src/server/lib/login.ts
+++ b/src/server/lib/login.ts
@@ -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
}
diff --git a/src/server/trpc.ts b/src/server/trpc.ts
index c7f4716..dbb7caf 100644
--- a/src/server/trpc.ts
+++ b/src/server/trpc.ts
@@ -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
+export type Context = inferAsyncReturnType
export const t = initTRPC.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 }) => {