Skip to content

Commit

Permalink
Add register composable
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Aug 8, 2024
1 parent 8a71dbf commit a672ce6
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 12 deletions.
56 changes: 56 additions & 0 deletions app/assets/composables/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import axios from 'axios'
import { AlertStyle, type AlertInterface } from '@userfrosting/sprinkle-core/types'
import { useConfigStore } from '@userfrosting/sprinkle-core/stores'
import type { UserInterface } from '../interfaces'

// Interfaces
export interface RegisterForm {
first_name: string
last_name: string
email: string
user_name: string
password: string
passwordc: string
locale: string
captcha: string
spiderbro: string
}

// Variables
const config = useConfigStore()
export const defaultForm: RegisterForm = {
first_name: '',
last_name: '',
email: '',
user_name: '',
password: '',
passwordc: '',
// @ts-ignore
locale: config.config.site.registration.user_defaults.locale,
captcha: '',
spiderbro: 'http://'
}
// @ts-ignore
export const availableLocales = config.config.locales.available
export const captchaUrl = '/account/captcha' // TODO : Add captcha path to config

// Actions
export async function doRegister(form: RegisterForm) {
return axios
.post<UserInterface>('/account/register', form)
.then((response) => {
return response.data
})
.catch((err) => {
const error: AlertInterface = {
...{
description: 'An error as occurred',
style: AlertStyle.Danger,
closeBtn: true
},
...err.response.data
}

throw error
})
}
2 changes: 1 addition & 1 deletion app/src/Controller/RegisterAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function __invoke(Request $request, Response $response): Response
*
* @param Request $request
*
* @return mixed[]|null
* @return mixed[]|null The newly created user
*/
protected function handle(Request $request): ?array
{
Expand Down
16 changes: 16 additions & 0 deletions dist/composables/register.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { UserInterface } from '../interfaces';
export interface RegisterForm {
first_name: string;
last_name: string;
email: string;
user_name: string;
password: string;
passwordc: string;
locale: string;
captcha: string;
spiderbro: string;
}
export declare const defaultForm: RegisterForm;
export declare const availableLocales: any;
export declare const captchaUrl = "/account/captcha";
export declare function doRegister(form: RegisterForm): Promise<UserInterface>;
26 changes: 15 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a672ce6

Please sign in to comment.