subvind-components
Advanced tools
| <script>import { onMount } from "svelte"; | ||
| import { jwtDecode } from "jwt-decode"; | ||
| let loading = false; | ||
| let email = ""; | ||
| let password = ""; | ||
| export let organization; | ||
| async function login(event) { | ||
| event.preventDefault(); | ||
| if (email === "") | ||
| return alert("Email must be defined."); | ||
| if (password === "") | ||
| return alert("Password must be defined."); | ||
| loading = true; | ||
| try { | ||
| const response = await fetch(`https://api.subvind.com/auth/accountLogin`, { | ||
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/json" | ||
| }, | ||
| body: JSON.stringify({ | ||
| email, | ||
| password, | ||
| organizationId: organization.id | ||
| }) | ||
| }); | ||
| if (response.ok) { | ||
| let res = await response.json(); | ||
| console.log("access_token", res.access_token); | ||
| localStorage.setItem("access_token", res.access_token); | ||
| let decodedToken = jwtDecode(res.access_token); | ||
| window.location.href = `/auth/success`; | ||
| } else { | ||
| const errorData = await response.json(); | ||
| alert(errorData.error); | ||
| } | ||
| } catch (error) { | ||
| console.error("Error logging in user:", error); | ||
| alert("An error occurred during login."); | ||
| } | ||
| loading = false; | ||
| } | ||
| onMount(async () => { | ||
| M.updateTextFields(); | ||
| var elems = document.querySelectorAll("select"); | ||
| var instances = M.FormSelect.init(elems, {}); | ||
| }); | ||
| </script> | ||
| <div class="contain"> | ||
| <div class="header"> | ||
| <!-- <a href="https://underwind.solutions"> | ||
| <img src="/anchor.png" alt="underwind.solutions" class="anchor"> | ||
| </a> --> | ||
| <h1 class="title"> | ||
| Login | ||
| </h1> | ||
| {#if organization} | ||
| {organization.frontendHostname} | ||
| {:else} | ||
| authentication | ||
| {/if} | ||
| </div> | ||
| <form class="card" on:submit={(e) => login(e)}> | ||
| <div class="card-content"> | ||
| <div class="row"> | ||
| <!-- <div class="input-field col s12"> | ||
| <select bind:value={type}> | ||
| <option value="" disabled selected>Choose your membership</option> | ||
| <option value="organization-customer">customer</option> | ||
| <option value="organization-employee">employee</option> | ||
| <option value="organization-supplier">supplier</option> | ||
| </select> | ||
| <label>Account Type</label> | ||
| </div> --> | ||
| <div class="input-field col s12"> | ||
| <input id="email" type="email" placeholder="test@test.com" class="validate" bind:value={email}> | ||
| <label for="email">Email</label> | ||
| </div> | ||
| <div class="input-field col s12"> | ||
| <input id="password" type="password" placeholder="test123" class="validate" bind:value={password}> | ||
| <label for="password">Password</label> | ||
| </div> | ||
| <br /> | ||
| {#if loading} | ||
| <button style="margin-left: 1em;" class="waves-effect btn disabled">Loading</button> | ||
| {:else} | ||
| <button style="margin-left: 1em;" type='submit' class="waves-effect yellow black-text lighten-2 btn">Submit</button> | ||
| {/if} | ||
| </div> | ||
| </div> | ||
| </form> | ||
| <div> | ||
| <a href="/auth/register" class="waves-effect black white-text btn" style="float: right;">Register</a> | ||
| <br /> | ||
| <br /> | ||
| <a href="/password-recovery" class="waves-effect white black-text btn" style="float: right;">Password Recovery</a> | ||
| <br /> | ||
| <br /> | ||
| <br /> | ||
| <br /> | ||
| </div> | ||
| </div> | ||
| <style> | ||
| .contain { | ||
| max-width: 400px; | ||
| margin: 0 auto; | ||
| } | ||
| .header { | ||
| text-align: center; | ||
| } | ||
| .title { | ||
| font-weight: 900; | ||
| font-size: 2em; | ||
| margin: 0; | ||
| } | ||
| .anchor { | ||
| height: 150px; | ||
| -webkit-filter: invert(1); | ||
| filter: invert(1); | ||
| text-align: center; | ||
| } | ||
| </style> |
| import { SvelteComponent } from "svelte"; | ||
| declare const __propDef: { | ||
| props: { | ||
| organization: any; | ||
| }; | ||
| events: { | ||
| [evt: string]: CustomEvent<any>; | ||
| }; | ||
| slots: {}; | ||
| }; | ||
| export type LoginProps = typeof __propDef.props; | ||
| export type LoginEvents = typeof __propDef.events; | ||
| export type LoginSlots = typeof __propDef.slots; | ||
| export default class Login extends SvelteComponent<LoginProps, LoginEvents, LoginSlots> { | ||
| } | ||
| export {}; |
| <script>import { onMount } from "svelte"; | ||
| import { jwtDecode } from "jwt-decode"; | ||
| let loading = false; | ||
| let accountname = ""; | ||
| let firstName = ""; | ||
| let lastName = ""; | ||
| let email = ""; | ||
| let password = ""; | ||
| let passwordRepeat = ""; | ||
| let deskHostname = ""; | ||
| export let organization; | ||
| async function register(event) { | ||
| event.preventDefault(); | ||
| if (accountname === "") | ||
| return alert("Accountname must be defined."); | ||
| if (firstName === "") | ||
| return alert("First name must be defined."); | ||
| if (lastName === "") | ||
| return alert("Last name must be defined."); | ||
| if (email === "") | ||
| return alert("Email must be defined."); | ||
| if (password === "") | ||
| return alert("Password must be defined."); | ||
| if (passwordRepeat === "") | ||
| return alert("Confirm Password must be defined."); | ||
| if (passwordRepeat !== password) | ||
| return alert("Passwords must match."); | ||
| loading = true; | ||
| try { | ||
| const response = await fetch("https://api.subvind.com/accounts", { | ||
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/json" | ||
| }, | ||
| body: JSON.stringify({ | ||
| accountname, | ||
| firstName, | ||
| lastName, | ||
| email, | ||
| password, | ||
| organization: { | ||
| id: organization.id | ||
| } | ||
| }) | ||
| }); | ||
| if (response.ok) { | ||
| const response2 = await fetch("https://api.subvind.com/auth/accountLogin", { | ||
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/json" | ||
| }, | ||
| body: JSON.stringify({ | ||
| email, | ||
| password, | ||
| organizationId: organization.id | ||
| }) | ||
| }); | ||
| if (response2.ok) { | ||
| let res = await response2.json(); | ||
| console.log("access_token", res.access_token); | ||
| localStorage.setItem("access_token", res.access_token); | ||
| let decodedToken = jwtDecode(res.access_token); | ||
| console.log("decoded_token", decodedToken); | ||
| window.location.href = `/portal/dashboard`; | ||
| } else { | ||
| const errorData = await response2.json(); | ||
| alert(errorData.error); | ||
| } | ||
| } else { | ||
| const errorData = await response.json(); | ||
| alert(errorData.error); | ||
| } | ||
| } catch (error) { | ||
| console.error("Error registering user:", error); | ||
| alert("An error occurred during submission."); | ||
| } | ||
| loading = false; | ||
| } | ||
| onMount(async () => { | ||
| deskHostname = window.location.hostname; | ||
| if (deskHostname === "localhost") { | ||
| deskHostname = "client-area.subvind.com"; | ||
| } | ||
| const response = await fetch(`https://api.subvind.com/organizations/deskHostname/${deskHostname}`, { | ||
| method: "GET", | ||
| headers: { | ||
| "Content-Type": "application/json" | ||
| } | ||
| }); | ||
| if (response.ok) { | ||
| organization = await response.json(); | ||
| } else { | ||
| const errorData = await response.json(); | ||
| alert(errorData.error); | ||
| } | ||
| }); | ||
| </script> | ||
| <div class="contain"> | ||
| <div class="header"> | ||
| <!-- <a href="https://underwind.solutions"> | ||
| <img src="/anchor.png" alt="underwind.solutions" class="anchor"> | ||
| </a> --> | ||
| <h1 class="title"> | ||
| Register | ||
| </h1> | ||
| {#if organization} | ||
| {organization.frontendHostname} | ||
| {:else} | ||
| authentication | ||
| {/if} | ||
| </div> | ||
| <form class="card" on:submit={(e) => register(e)}> | ||
| <div class="card-content"> | ||
| <div class="row"> | ||
| <div class="input-field col s12"> | ||
| <input id="accountname" type="text" class="validate" bind:value={accountname}> | ||
| <label for="accountname">Username</label> | ||
| </div> | ||
| <div class="input-field col s6"> | ||
| <input id="firstName" type="text" class="validate" bind:value={firstName}> | ||
| <label for="firstName">First Name</label> | ||
| </div> | ||
| <div class="input-field col s6"> | ||
| <input id="lastName" type="text" class="validate" bind:value={lastName}> | ||
| <label for="lastName">Last Name</label> | ||
| </div> | ||
| <div class="input-field col s12"> | ||
| <input id="email" type="email" class="validate" bind:value={email}> | ||
| <label for="email">Email</label> | ||
| </div> | ||
| <div class="input-field col s12"> | ||
| <input id="password" type="password" class="validate" bind:value={password}> | ||
| <label for="password">Password</label> | ||
| </div> | ||
| <div class="input-field col s12"> | ||
| <input id="passwordRepeat" type="password" class="validate" bind:value={passwordRepeat}> | ||
| <label for="passwordRepeat">Password Confirm</label> | ||
| </div> | ||
| <br /> | ||
| {#if loading} | ||
| <button style="margin-left: 1em;" class="waves-effect btn disabled">Loading</button> | ||
| {:else} | ||
| <button style="margin-left: 1em;" type='submit' class="waves-effect yellow black-text lighten-2 btn">Submit</button> | ||
| {/if} | ||
| </div> | ||
| </div> | ||
| </form> | ||
| <div> | ||
| <a href="/auth/login" class="waves-effect black white-text btn" style="float: right;">Login</a> | ||
| <br /> | ||
| <br /> | ||
| <a href="/password-recovery" class="waves-effect white black-text btn" style="float: right;">Password Recovery</a> | ||
| <br /> | ||
| <br /> | ||
| <br /> | ||
| <br /> | ||
| </div> | ||
| </div> | ||
| <style> | ||
| .contain { | ||
| max-width: 400px; | ||
| margin: 0 auto; | ||
| } | ||
| .header { | ||
| text-align: center; | ||
| } | ||
| .title { | ||
| font-weight: 900; | ||
| font-size: 2em; | ||
| margin: 0; | ||
| } | ||
| .anchor { | ||
| height: 150px; | ||
| -webkit-filter: invert(1); | ||
| filter: invert(1); | ||
| text-align: center; | ||
| } | ||
| </style> |
| import { SvelteComponent } from "svelte"; | ||
| declare const __propDef: { | ||
| props: { | ||
| organization: any; | ||
| }; | ||
| events: { | ||
| [evt: string]: CustomEvent<any>; | ||
| }; | ||
| slots: {}; | ||
| }; | ||
| export type RegisterProps = typeof __propDef.props; | ||
| export type RegisterEvents = typeof __propDef.events; | ||
| export type RegisterSlots = typeof __propDef.slots; | ||
| export default class Register extends SvelteComponent<RegisterProps, RegisterEvents, RegisterSlots> { | ||
| } | ||
| export {}; |
+2
-0
@@ -13,1 +13,3 @@ export { default as Auth } from "./Auth.svelte"; | ||
| export { default as AuthSelectOrganization } from "./auth/SelectOrganization.svelte"; | ||
| export { default as AuthAccountLogin } from "./authAccount/Login.svelte"; | ||
| export { default as AuthAccountRegister } from "./authAccount/Register.svelte"; |
+4
-1
@@ -17,2 +17,5 @@ // Reexport your entry components here | ||
| export { default as AuthRegister } from './auth/Register.svelte'; | ||
| export { default as AuthSelectOrganization } from './auth/SelectOrganization.svelte'; | ||
| export { default as AuthSelectOrganization } from './auth/SelectOrganization.svelte'; | ||
| export { default as AuthAccountLogin } from './authAccount/Login.svelte'; | ||
| export { default as AuthAccountRegister } from './authAccount/Register.svelte'; |
+1
-1
| { | ||
| "name": "subvind-components", | ||
| "version": "0.0.14", | ||
| "version": "0.0.15", | ||
| "scripts": { | ||
@@ -5,0 +5,0 @@ "dev": "vite dev", |
47599
27.03%32
14.29%250
17.37%