Skip to content

Commit

Permalink
fix: login D1
Browse files Browse the repository at this point in the history
Signed-off-by: 0x73746F66 <[email protected]>
  • Loading branch information
0x73746F66 committed Jun 11, 2024
1 parent ca4ceec commit 9937250
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 70 deletions.
2 changes: 1 addition & 1 deletion functions/register/[org]/[email]/[hash].js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const onRequestGet = async context => {
) {
console.log('org', context.params.org)
// const kid = crypto.randomUUID()
const info = await db.prepare('INSERT INTO members (orgName, email, passwordhash) VALUES (?1, ?2, ?3)')
const info = await context.env.d1db.prepare('INSERT INTO members (orgName, email, passwordHash) VALUES (?1, ?2, ?3)')
.bind(context.params.org, context.params.email, pbkdf2(context.params.hash))
.run()
return Response.json(info)
Expand Down
86 changes: 18 additions & 68 deletions src/pages/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import IconTrivialSecurity from '@images/IconTrivialSecurity.vue'
import { useVuelidate } from '@vuelidate/core'
import { email, required } from '@vuelidate/validators'
import { PBKDF2 } from 'crypto-es/lib/pbkdf2'
import axios from 'axios'
import { SHA1 } from 'crypto-es/lib/sha1'
import { reactive } from 'vue'
import router from "../router"
const initialState = {
email: localStorage.getItem('/member/email') || '',
password: '',
rememberMe: false,
}
const state = reactive({
Expand All @@ -19,29 +19,18 @@ const state = reactive({
const rules = {
email: { required, email },
password: { required },
rememberMe: { required },
}
const v$ = useVuelidate(rules, state)
const isPasswordVisible = ref(false)
const login = () => {
const storedPassword = localStorage.getItem('/member/password')
const storedSalt = localStorage.getItem('/member/password/salt')
if (storedSalt && storedPassword && state.email && state.password) {
// Do login
// axios.get("http://local.getusers.com)
// .then(response => {
// this.users = response.data;
// })
// .catch(error => {
// console.log(error)
// })
const passwordHash = PBKDF2(state.password, storedSalt, { keySize: 512/32, iterations: 1000 }).toString()
if (storedPassword !== passwordHash) {
console.log(403, 'Forbidden')
return
}
if (state.email && state.password) {
axios.get(`/login/${state.email}/${SHA1(state.password)}`)
.then(console.log)
.catch(console.log)
localStorage.setItem('/member/email', state.email)
localStorage.setItem('/session/token', "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0cmlhZ2UiLCJuYmYiOjE3MTgwMjQzNTgsImlhdCI6MTcxODAyNDM1OCwiZXhwIjoxNzE4MTEwNzU4LCJhdWQiOiJ1cm46dXVpZDowMGQwYzI3ZC1lNjA5LTRiMWMtYjIxMS02NzFjOGFjZDVhYWEiLCJpc3MiOiJ1cm46dXVpZDowMGQwYzI3ZC1lNjA5LTRiMWMtYjIxMS02NzFjOGFjZDVhYWEiLCJraWQiOiJ1cm46dXVpZDo0MjUwNWE1My05YzRiLTQ1OTgtYTcxYy03ZmQzMzI0ZGZhYTIiLCJuYW1lIjoiRGVtbyBVc2VyIiwicm9sZSI6InVybjp1dWlkOjdhZGE1YWNkLWQxOGYtNGZmNC04NDA5LTEzMjk3MmJhYmEyOCJ9.2bLuGpY9APA8qbPp73tk-7sDWO4IoLpC3ifRLWzs_O5jZG9b0kFtQhAo2DiBr_CRBsBYuMMb0zsxaW8Maa2uXQ")
router.push('/dashboard')
}
Expand All @@ -50,20 +39,17 @@ const login = () => {

<template>
<div class="auth-wrapper d-flex align-center justify-center pa-4">
<VCard
class="auth-card pa-4 pt-7"
max-width="448"
>
<VCard class="auth-card pa-4 pt-7" max-width="448">
<VCardItem class="justify-center">
<template #prepend>
<div class="d-flex">
<IconTrivialSecurity class="d-flex text-primary" width="150"/>
<IconTrivialSecurity class="d-flex text-primary" width="150" />
</div>
</template>
</VCardItem>

<VCardText class="pt-2">
<h5 class="text-h5 mb-1 text-center">
<h5 class="text-h5 mb-1 text-center">
Trivial Triage
</h5>
<p class="mb-0">
Expand All @@ -76,61 +62,24 @@ const login = () => {
<VRow>
<!-- email -->
<VCol cols="12">
<VTextField
v-model="state.email"
autofocus
placeholder="[email protected]"
label="Email"
type="email"
/>
<VTextField v-model="state.email" autofocus placeholder="[email protected]" label="Email" type="email" />
</VCol>

<!-- password -->
<VCol cols="12">
<VTextField
required
v-model="state.password"
label="Password"
placeholder="············"
<VTextField required v-model="state.password" label="Password" placeholder="············"
:type="isPasswordVisible ? 'text' : 'password'"
:append-inner-icon="isPasswordVisible ? 'bx-hide' : 'bx-show'"
@click:append-inner="isPasswordVisible = !isPasswordVisible"
/>

<!-- remember me checkbox -->
<div class="d-flex align-center justify-space-between flex-wrap mt-1 mb-4">
<VCheckbox
v-model="state.rememberMe"
label="Remember me"
/>

<RouterLink
class="text-primary ms-2 mb-1"
to="javascript:void(0)"
>
Forgot Password?
</RouterLink>
</div>
@click:append-inner="isPasswordVisible = !isPasswordVisible" />

<!-- login button -->
<VBtn
@click="v$.$validate"
block
text="Login"
type="submit"
/>
<VBtn @click="v$.$validate" block text="Login" type="submit" />
</VCol>

<!-- create account -->
<VCol
cols="12"
class="text-center text-base"
>
<VCol cols="12" class="text-center text-base">
<span>New on our platform?</span>
<RouterLink
class="text-primary ms-2"
to="/register"
>
<RouterLink class="text-primary ms-2" to="/register">
Create an account
</RouterLink>
</VCol>
Expand All @@ -143,6 +92,7 @@ const login = () => {

<style lang="scss" scoped>
@use "@core/scss/template/pages/page-auth.scss";
.v-btn {
text-transform: none;
}
Expand Down
1 change: 0 additions & 1 deletion src/pages/Register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const register = () => {
.catch(console.log)
localStorage.setItem('/account/name', state.org)
localStorage.setItem('/member/email', state.email)
localStorage.setItem('/session/token', 'temp')
router.push('/login')
}
}
Expand Down

0 comments on commit 9937250

Please sign in to comment.