Skip to content
Snippets Groups Projects
Commit c0a3b6ac authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Handle error messages from server

parent f6259d6b
Branches
No related tags found
No related merge requests found
......@@ -50,6 +50,8 @@
CONST_URL_SYNC_UPDATE_OBSERVATIONS: '/rest/observation/syncobservationlistfromapp',
CONST_URL_SYNC_UPDATE_OBSERVATION: '/rest/observation/syncobservationfromapp',
CONST_URL_REGISTER_NEW_USER: '/rest/user/register',
CONST_URL_SYNC_UPDATE_POI: '/rest/poi/syncpoifromapp',
CONST_URL_USER_OBSERVATION_LIST: '/rest/observation/list/user',
......
......@@ -23,14 +23,144 @@
<template>
<div>
<h1>Register new user</h1>
<form @submit="checkForm">
<h2>{{ $t("registeruser.button.label") }}</h2>
<p>{{ $t("registeruserform.description") }}</p>
<p v-if="errors.length">
<b>Please correct the following error(s):</b>
<ul>
<li v-for="error in errors">{{ error }}</li>
</ul>
</p>
<div class="form-group">
<label for="firstName">{{ $t("registeruserform.firstName") }}</label>
<input type="text" class="form-control" v-model.trim.lazy="firstName" />
</div>
<div class="form-group">
<label for="lastName">{{ $t("registeruserform.lastName") }}</label>
<input type="text" class="form-control" v-model.trim.lazy="lastName" />
</div>
<div class="form-group">
<label for="email">{{ $t("registeruserform.email") }}</label>
<input type="email" class="form-control" v-model.trim.lazy="email" aria-describedby="emailHelp"/>
<small id="emailHelp" class="form-text text-muted">{{ $t("registeruserform.email.help") }}</small>
</div>
<div class="form-group">
<label for="username">{{ $t("registeruserform.username") }}</label>
<input type="text" class="form-control" v-model.trim.lazy="username" aria-describedby="usernameHelp"/>
<small id="usernameHelp" class="form-text text-muted">{{ $t("registeruserform.username.help") }}</small>
</div>
<div class="form-group">
<label for="password">{{ $t("registeruserform.password") }}</label>
<input type="password" class="form-control" v-model.trim="password" aria-describedby="passwordHelp"/>
<small id="passwordHelp" class="form-text text-muted">{{ $t("registeruserform.password.help") }}</small>
</div>
<div class="form-group">
<label for="password2">{{ $t("registeruserform.password2") }}</label>
<input type="password" id="password2" class="form-control" v-model="password2" aria-describedby="password2Help"/>
<small id="password2Help" class="form-text text-muted">{{ $t("registeruserform.password2.help") }}</small>
</div>
<button type="submit" class="btn btn-primary">{{ $t("registeruserform.submit.label") }}</button>
</form>
</div>
</template>
<script>
import CommonUtil from '@/components/CommonUtil';
import JsonpTemplatePlugin from 'webpack/lib/JsonpTemplatePlugin';
export default {
name: 'RegisterUserForm'
name: 'RegisterUserForm',
data() {
return {
username: "",
password: "",
password2: "",
email: "",
firstName: "",
lastName: "",
preferredLocale: "nb",
organizationId: 1,
errors: []
};
},
methods: {
checkForm: function(e) {
e.preventDefault();
this.errors=[];
if(this.firstName == "")
{
this.errors.push("First name must be set");
}
if(this.lastName == "")
{
this.errors.push("Last name must be set");
}
if(this.email == "")
{
this.errors.push("Email must be set");
}
if(this.username == "")
{
this.errors.push("Username must be set");
}
if(this.password == "")
{
this.errors.push("Password must be set");
}
if(this.password != this.password2)
{
this.errors.push("The passwords do not match")
}
// Form OK. Submit
if(this.errors.length == 0)
{
this.submitForm();
}
},
submitForm: async function(){
const response = await fetch(
CommonUtil.CONST_URL_DOMAIN + CommonUtil.CONST_URL_REGISTER_NEW_USER,
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(
{
"firstName": this.firstName,
"lastName": this.lastName,
"email": this.email,
"username": this.username,
"password": this.password,
"organizationId": this.organizationId,
"preferredLocale": this.preferredLocale
}
)
}
);
const data = await response.json();
if(response.status != 200)
{
if(data["errorMessage"] != null)
{
this.errors.push(data["errorMessage"]);
}
else
{
alert("Something went wrong. Status code = " + response.status + ". Please contact your system administrator");
}
return false;
}
// Show message about confirming email
// Show button for auto login
console.info(data);
}
}
}
</script>
\ No newline at end of file
......@@ -72,5 +72,17 @@
"about.version": "Version",
"about.text": "<p>The app is developed by <a href='#' onclick=\"cordova.InAppBrowser.open('https://nibio.no/en', '_system')\">NIBIO</a>'s <a href='#' onclick=\"cordova.InAppBrowser.open('https://www.vips-landbruk.no/', '_system')\">VIPS</a> team.</p><p>VIPS project leader: <a href='#' onclick=\"cordova.InAppBrowser.open('https://www.nibio.no/ansatte/berit-nordskog', '_system')\">Berit Nordskog</a></p><p>&copy; 2022 <a href='#' onclick=\"cordova.InAppBrowser.open('https://nibio.no/en', '_system')\">NIBIO</a></p>",
"registeruser.button.label": "Register new user",
"registeruserform.description": "TODO: Write a description",
"registeruserform.firstName": "First name",
"registeruserform.lastName": "Last name",
"registeruserform.email": "Email",
"registeruserform.username": "Username",
"registeruserform.password": "Password",
"registeruserform.password2": "Repeat password",
"registeruserform.email.help": "We'll never share your email with anyone else.",
"registeruserform.username.help": "Remember your username; it is used in combination with your password to log in",
"registeruserform.password.help": "Passwords are stored in encrypted form for your safety",
"registeruserform.password2.help": "Please repeat the password",
"registeruserform.submit.label": "Registrer bruker",
"copy" : "Copy"
}
\ No newline at end of file
......@@ -72,5 +72,17 @@
"about.version": "Versjon",
"about.text": "<p>Appen er utviklet av <a href='#' onclick=\"cordova.InAppBrowser.open('https://nibio.no/', '_system')\">NIBIO</a>s <a href='#' onclick=\"cordova.InAppBrowser.open('https://www.vips-landbruk.no/', '_system')\">VIPS-team</a>.</p><p>Prosjektleder for VIPS: <a href='#' onclick=\"cordova.InAppBrowser.open('https://www.nibio.no/ansatte/berit-nordskog', '_system')\">Berit Nordskog</a></p><p>&copy; 2022 <a href='#' onclick=\"cordova.InAppBrowser.open('https://nibio.no/', '_system')\">NIBIO</a></p>",
"registeruser.button.label": "Registrer ny bruker",
"registeruserform.description": "TODO: Skriv en god forklaring",
"registeruserform.firstName": "Fornavn",
"registeruserform.lastName": "Etternavn",
"registeruserform.email": "E-post",
"registeruserform.username": "Brukernavn",
"registeruserform.password": "Passord",
"registeruserform.password2": "Gjenta passord",
"registeruserform.email.help": "Vi vil aldri dele din e-post med tredjepart",
"registeruserform.username.help": "Husk brukernavnet ditt; Det brukes for innlogging i kombinasjon med passord",
"registeruserform.password.help": "Passordet lagres i kryptert form",
"registeruserform.password2.help": "Vennligst gjenta passordet for sikkerhets skyld",
"registeruserform.submit.label": "Registrer bruker",
"copy" : "Kopi"
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment