1
0
Fork 0
mirror of synced 2024-09-09 22:16:26 +12:00
budibase/packages/standard-components/src/Login.svelte

180 lines
3.5 KiB
Svelte
Raw Normal View History

2019-08-27 18:32:56 +12:00
<script>
2020-02-03 22:50:30 +13:00
import Button from "./Button.svelte"
export let loginButtonLabel = "Login"
export let logo = ""
export let name = ""
2020-02-03 22:50:30 +13:00
export let buttonClass = ""
export let inputClass = ""
export let _bb
let username = ""
let password = ""
let loading = false
let error = false
2020-02-03 22:50:30 +13:00
let _buttonClass = ""
let _inputClass = ""
$: {
_buttonClass = buttonClass || "default-button"
_inputClass = inputClass || "default-input"
}
const login = async () => {
loading = true
2020-06-25 03:20:15 +12:00
const response = await _bb.api.post("/api/authenticate", {
username,
password,
})
if (response.status === 200) {
2020-05-07 21:53:34 +12:00
const json = await response.json()
localStorage.setItem("budibase:token", json.token)
// TODO: possibly do something with the user information in the response?
location.reload()
} else {
loading = false
error = true
}
2020-02-03 22:50:30 +13:00
}
2019-08-27 18:32:56 +12:00
</script>
2020-06-25 02:41:33 +12:00
<div class="container">
<div class="root">
<div class="content">
2020-06-25 03:20:15 +12:00
{#if logo}
<div class="logo-container">
2020-06-25 03:20:15 +12:00
<img src={logo} alt="logo" />
</div>
{/if}
<div class="login-button-container">
<button disabled={loading} on:click={login} class={_buttonClass}>
Log in to {name}
</button>
2020-02-03 22:50:30 +13:00
</div>
{#if error}
2020-06-25 02:41:33 +12:00
<div class="incorrect-details-panel">
Incorrect username or password
</div>
{/if}
2020-02-03 22:50:30 +13:00
</div>
</div>
2019-08-27 18:32:56 +12:00
</div>
<style>
2020-06-25 02:41:33 +12:00
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
position: absolute;
}
2020-02-03 22:50:30 +13:00
.root {
2019-08-27 18:32:56 +12:00
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
2020-02-03 22:50:30 +13:00
}
2019-08-27 18:32:56 +12:00
2020-02-03 22:50:30 +13:00
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
2020-02-03 22:50:30 +13:00
}
2019-08-27 18:32:56 +12:00
2020-02-03 22:50:30 +13:00
.logo-container {
2020-06-04 02:55:42 +12:00
margin-bottom: 10px;
2020-02-03 22:50:30 +13:00
}
2019-08-27 18:32:56 +12:00
2020-02-03 22:50:30 +13:00
.logo-container > img {
2020-06-04 02:55:42 +12:00
max-width: 200px;
2020-02-03 22:50:30 +13:00
}
2019-08-27 18:32:56 +12:00
2020-02-03 22:50:30 +13:00
.login-button-container {
margin-top: 6px;
max-width: 100%;
}
.header-content {
font-family: Inter;
font-weight: 600;
color: #1f1f1f;
font-size: 48px;
line-height: 72px;
margin-bottom: 30px;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
font-feature-settings: "case" "rlig" "calt" 0;
2020-02-03 22:50:30 +13:00
}
2019-08-27 18:32:56 +12:00
2020-02-03 22:50:30 +13:00
.incorrect-details-panel {
margin-top: 30px;
padding: 10px;
border-style: solid;
border-width: 1px;
border-color: maroon;
border-radius: 1px;
text-align: center;
color: maroon;
background-color: mistyrose;
2020-02-03 22:50:30 +13:00
}
2020-02-03 22:50:30 +13:00
.form-root {
display: flex;
flex-direction: column;
align-items: center;
width: 300px;
2020-02-03 22:50:30 +13:00
}
2020-02-03 22:50:30 +13:00
.control {
padding: 6px 0px;
width: 100%;
2020-02-03 22:50:30 +13:00
}
.default-input {
font-family: Inter;
font-size: 14px;
color: #393c44;
padding: 2px 6px 2px 12px;
2020-02-03 22:50:30 +13:00
margin: 0 0 0.5em 0;
box-sizing: border-box;
border: 0.5px solid #d8d8d8;
border-radius: 4px;
width: 100%;
height: 40px;
transition: border-color 100ms ease-in 0s;
outline-color: #797979;
2020-02-03 22:50:30 +13:00
}
.default-button {
font-family: Inter;
font-size: 16px;
2020-02-03 22:50:30 +13:00
padding: 0.4em;
box-sizing: border-box;
border-radius: 4px;
color: white;
background-color: #393c44;
2020-02-03 22:50:30 +13:00
outline: none;
width: 300px;
height: 40px;
cursor: pointer;
transition: all 0.2s ease 0s;
overflow: hidden;
outline: none;
user-select: none;
white-space: nowrap;
text-align: center;
2020-02-03 22:50:30 +13:00
}
.default-button:hover {
background-color: white;
border-color: #393c44;
color: #393c44;
2020-02-03 22:50:30 +13:00
}
</style>