Add register functionality.
This commit is contained in:
parent
fc85170492
commit
b5b92a9af7
|
|
@ -10,7 +10,7 @@ export class AuthApiClient extends ApiClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
async register(username: string, password: string): Promise<void> {
|
async register(username: string, password: string): Promise<void> {
|
||||||
await super.postJson('/register', { username, password })
|
await super.postNoResponse('/register', { username, password })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUsernameAvailability(username: string): Promise<boolean> {
|
async getUsernameAvailability(username: string): Promise<boolean> {
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,24 @@ async function doLogin() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function doRegister() {
|
||||||
|
disableForm.value = true
|
||||||
|
showLoader()
|
||||||
|
try {
|
||||||
|
await apiClient.register(username.value, password.value)
|
||||||
|
await doLogin()
|
||||||
|
} catch (err) {
|
||||||
|
hideLoader()
|
||||||
|
if (err instanceof ApiError) {
|
||||||
|
await showAlert(err.message)
|
||||||
|
} else {
|
||||||
|
await showAlert('Request failed: ' + JSON.stringify(err))
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
disableForm.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function isDataValid() {
|
function isDataValid() {
|
||||||
return username.value.length > 0 && password.value.length >= 8
|
return username.value.length > 0 && password.value.length >= 8
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +88,8 @@ function generateSampleData() {
|
||||||
<div style="display: flex; margin-left: 1rem; margin-right: 1rem;">
|
<div style="display: flex; margin-left: 1rem; margin-right: 1rem;">
|
||||||
<AppButton button-type="submit" :disabled="disableForm || !isDataValid()" style="flex-grow: 1;">Login
|
<AppButton button-type="submit" :disabled="disableForm || !isDataValid()" style="flex-grow: 1;">Login
|
||||||
</AppButton>
|
</AppButton>
|
||||||
<AppButton button-type="button" button-style="secondary" :disabled="true">Register</AppButton>
|
<AppButton button-type="button" button-style="secondary" :disabled="disableForm || !isDataValid()"
|
||||||
|
@click="doRegister()">Register</AppButton>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="isDev">
|
<div v-if="isDev">
|
||||||
<AppButton button-type="button" @click="generateSampleData()">Generate Sample Data</AppButton>
|
<AppButton button-type="button" @click="generateSampleData()">Generate Sample Data</AppButton>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue