Skip to content

Commit

Permalink
Refactor Account Sprinkle Build
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Dec 6, 2024
1 parent 58f354a commit 51fac77
Show file tree
Hide file tree
Showing 76 changed files with 129 additions and 4,193 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ node_modules/

# Ignore compiled assets
public/assets/
dist/

# Ignore dev utils cache
.phpunit.cache
Expand Down
25 changes: 16 additions & 9 deletions app/assets/composables/forgotPassword.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
/**
* Forgot password API
*
* Fetch the forgot password API. This will send an email to the user with
* instructions to reset their password.
*
* @param {String} email - The email of the user to send the email to.
*
* @return {Promise} - The response of the API. Throw an error (AlertInterface)
* if the request failed. Return a success message (AlertInterface) if the
* request is a success.
*/
import axios from 'axios'
import { Severity, type AlertInterface } from '@userfrosting/sprinkle-core/types'
import { Severity, type AlertInterface } from '@userfrosting/sprinkle-core/interfaces'

// Actions
async function forgotPassword(email: String) {
export async function forgotPassword(email: String) {
return axios
.post<{ message: string }>('/account/forgot-password', { email: email })
.then((response) => {
const error: AlertInterface = {
.then((response): AlertInterface => {
return {
description: response.data.message,
style: Severity.Success,
closeBtn: true
}

return error
})
.catch((err) => {
const error: AlertInterface = {
Expand All @@ -27,5 +36,3 @@ async function forgotPassword(email: String) {
throw error
})
}

export default forgotPassword
8 changes: 3 additions & 5 deletions app/assets/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as Register from './register'
import forgotPassword from './forgotPassword'
import resendVerification from './resendVerification'

export { Register, forgotPassword, resendVerification }
export * as Register from './register'
export { forgotPassword } from './forgotPassword'
export { resendVerification } from './resendVerification'
18 changes: 3 additions & 15 deletions app/assets/composables/register.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import axios from 'axios'
import { Severity, type AlertInterface } from '@userfrosting/sprinkle-core/types'
import { Severity, type AlertInterface } from '@userfrosting/sprinkle-core/interfaces'
import { useConfigStore } from '@userfrosting/sprinkle-core/stores'
import type { UserInterface } from '../interfaces'
import type { UserInterface, RegisterForm } from '../interfaces'

// Interfaces
interface RegisterForm {
first_name: string
last_name: string
email: string
user_name: string
password: string
passwordc: string
locale: string
captcha: string
spiderbro: string
}
// TODO : Refactor as a true composable

// Variables
function getDefaultForm(): RegisterForm {
Expand Down Expand Up @@ -61,5 +50,4 @@ async function doRegister(form: RegisterForm) {
})
}

export type { RegisterForm }
export { getDefaultForm, getAvailableLocales, getCaptchaUrl, doRegister }
25 changes: 16 additions & 9 deletions app/assets/composables/resendVerification.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
/**
* Resend Verification API
*
* Fetch the resend verification API. This will send an email to the user with
* instructions to verify their email.
*
* @param {String} email - The email of the user to send the email to.
*
* @return {Promise} - The response of the API. Throw an error (AlertInterface)
* if the request failed. Return a success message (AlertInterface) if the
* request is a success.
*/
import axios from 'axios'
import { Severity, type AlertInterface } from '@userfrosting/sprinkle-core/types'
import { Severity, type AlertInterface } from '@userfrosting/sprinkle-core/interfaces'

// Actions
async function resendVerification(email: String) {
export async function resendVerification(email: String) {
return axios
.post<{ message: string }>('/account/resend-verification', { email: email })
.then((response) => {
const error: AlertInterface = {
.then((response): AlertInterface => {
return {
description: response.data.message,
style: Severity.Success,
closeBtn: true
}

return error
})
.catch((err) => {
const error: AlertInterface = {
Expand All @@ -27,5 +36,3 @@ async function resendVerification(email: String) {
throw error
})
}

export default resendVerification
1 change: 1 addition & 0 deletions app/assets/guards/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useAuthGuard } from './authGuard'
2 changes: 1 addition & 1 deletion app/assets/plugin.ts → app/assets/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { App } from 'vue'
import type { Router } from 'vue-router'
import { useAuthStore } from './stores/auth'
import { useAuthGuard } from './guards/authGuard'
import type { Router } from 'vue-router'

/* Install plugins */
export default {
Expand Down
10 changes: 10 additions & 0 deletions app/assets/interfaces/forms/loginForm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Interface for login form
*
* This interface is used to define what the composable used to communicate with
* the API expects as argument.
*/
export interface LoginForm {
user_name: string
password: string
}
17 changes: 17 additions & 0 deletions app/assets/interfaces/forms/registerForm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Interface for registration form
*
* This interface is used to define what the composable used to communicate with
* the API expects as argument.
*/
export interface RegisterForm {
first_name: string
last_name: string
email: string
user_name: string
password: string
passwordc: string
locale: string
captcha: string
spiderbro: string
}
22 changes: 7 additions & 15 deletions app/assets/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import type { LoginForm } from './loginForm'
import type { UserInterface } from './userInterface'
import type { GroupInterface } from './groupInterface'
import type { RoleInterface } from './roleInterface'
import type { PermissionInterface } from './permissionInterface'
import type { RouteGuard } from './routes'

export type {
GroupInterface,
LoginForm,
PermissionInterface,
RoleInterface,
RouteGuard,
UserInterface
}
export type { LoginForm } from './forms/loginForm'
export type { RegisterForm } from './forms/registerForm'
export type { UserInterface } from './models/userInterface'
export type { GroupInterface } from './models/groupInterface'
export type { RoleInterface } from './models/roleInterface'
export type { PermissionInterface } from './models/permissionInterface'
export type { RouteGuard } from './routes'
4 changes: 0 additions & 4 deletions app/assets/interfaces/loginForm.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/**
* Group Model
*
* By default, the frontend group object will have the same interface as the PHP user.
* Note that any Sprinkle can (and should!) extend this interface.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/**
* Permission Model
*
* By default, the frontend role object will have the same interface as the PHP user.
* Note that any Sprinkle can (and should!) extend this interface.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/**
* Role Model
*
* By default, the frontend role object will have the same interface as the PHP user.
* Note that any Sprinkle can (and should!) extend this interface.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/**
* User Model
*
* By default, the frontend user will have the same interface as the PHP user.
* Note that any Sprinkle can (and should!) extend this interface.
*
Expand Down
9 changes: 9 additions & 0 deletions app/assets/interfaces/routes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* Interface for custom routes meta fields.
*
* Meta Fields Added :
* - auth: RouteGuard - Guard for authenticated users
* - guest: RouteGuard - Guard for not authenticated users
*
* @see https://router.vuejs.org/guide/advanced/meta.html#TypeScript
*/
import 'vue-router'

export interface RouteGuard {
Expand Down
4 changes: 1 addition & 3 deletions app/assets/router/routes.ts → app/assets/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const routes = [
export default [
{
path: '/account/sign-in',
name: 'account.login',
Expand Down Expand Up @@ -40,5 +40,3 @@ const routes = [
component: () => import('../views/ResendVerificationView.vue')
}
]

export default routes
2 changes: 1 addition & 1 deletion app/assets/stores/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia'
import axios from 'axios'
import type { UserInterface, LoginForm } from '../interfaces'
import { type AlertInterface, Severity } from '@userfrosting/sprinkle-core/types'
import { type AlertInterface, Severity } from '@userfrosting/sprinkle-core/interfaces'

interface AuthCheckApi {
auth: boolean
Expand Down
1 change: 1 addition & 0 deletions app/assets/stores/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useAuthStore } from './auth'
2 changes: 1 addition & 1 deletion app/assets/tests/composables/forgotPassword.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, test, vi } from 'vitest'
import axios from 'axios'
import { Severity } from '@userfrosting/sprinkle-core/types'
import { Severity } from '@userfrosting/sprinkle-core/interfaces'
import { forgotPassword } from '../../composables'

const email: String = '[email protected]'
Expand Down
5 changes: 3 additions & 2 deletions app/assets/tests/composables/register.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { afterEach, describe, expect, test, vi } from 'vitest'
import axios from 'axios'
import type { UserInterface } from 'app/assets/interfaces'
import { Severity } from '@userfrosting/sprinkle-core/types'
import { Severity } from '@userfrosting/sprinkle-core/interfaces'
import { useConfigStore } from '@userfrosting/sprinkle-core/stores'
import type { RegisterForm } from '../../interfaces'
import { Register } from '../../composables'

const { getDefaultForm, doRegister, getAvailableLocales, getCaptchaUrl } = Register
Expand All @@ -24,7 +25,7 @@ const testUser: UserInterface = {
deleted_at: null
}

const form: Register.RegisterForm = {
const form: RegisterForm = {
first_name: 'John',
last_name: 'Doe',
email: '[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion app/assets/tests/composables/resendVerification.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, test, vi } from 'vitest'
import axios from 'axios'
import { Severity } from '@userfrosting/sprinkle-core/types'
import { Severity } from '@userfrosting/sprinkle-core/interfaces'
import { resendVerification } from '../../composables'

const email: String = '[email protected]'
Expand Down
2 changes: 1 addition & 1 deletion app/assets/tests/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createApp } from 'vue'
import { useAuthStore } from '../stores/auth'
import { useAuthGuard } from '../guards/authGuard'
import { useRouter } from 'vue-router'
import plugin from '../plugin'
import plugin from '../'
import * as Auth from '../stores/auth'
import * as AuthGuard from '../guards/authGuard'

Expand Down
4 changes: 2 additions & 2 deletions app/assets/tests/stores/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { setActivePinia, createPinia } from 'pinia'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { beforeEach, describe, expect, test, vi } from 'vitest'
import { useAuthStore } from '../../stores/auth'
import axios from 'axios'
import type { LoginForm, UserInterface } from 'app/assets/interfaces'
import { Severity } from '@userfrosting/sprinkle-core/types'
import { Severity } from '@userfrosting/sprinkle-core/interfaces'

const testUser: UserInterface = {
id: 1,
Expand Down
6 changes: 6 additions & 0 deletions app/assets/views/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import ForgotPasswordView from './ForgotPasswordView.vue'
import LoginView from './LoginView.vue'
import RegisterView from './RegisterView.vue'
import ResendVerificationView from './ResendVerificationView.vue'

export { ForgotPasswordView, LoginView, RegisterView, ResendVerificationView }
11 changes: 0 additions & 11 deletions dist/ForgotPasswordView-Ct0WfO54.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/ForgotPasswordView-Do1jt-vY.cjs

This file was deleted.

19 changes: 0 additions & 19 deletions dist/LoginView-DgGcaGh5.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/LoginView-DwEVPIza.cjs

This file was deleted.

1 change: 0 additions & 1 deletion dist/RegisterView-BX7SoD5B.cjs

This file was deleted.

17 changes: 0 additions & 17 deletions dist/RegisterView-D9MTwaNP.js

This file was deleted.

11 changes: 0 additions & 11 deletions dist/ResendVerificationView-BBUXSJO0.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/ResendVerificationView-D4anMPwm.cjs

This file was deleted.

1 change: 0 additions & 1 deletion dist/_plugin-vue_export-helper-BHFhmbuH.cjs

This file was deleted.

Loading

0 comments on commit 51fac77

Please sign in to comment.