Skip to content
Snippets Groups Projects
Commit 05bc1322 authored by Titus Netland's avatar Titus Netland
Browse files

New password view created and Login view fixed

parent c7bbcf12
Branches
No related tags found
1 merge request!5New password view created and Login view fixed
Pipeline #174839 passed
<!--suppress HtmlDeprecatedAttribute -->
<template> <template>
<div> <div>
<v-col <v-col align="center" justify="space-around" class="mt-16">
align="center"
justify="space-around"
>
<v-img <v-img
max-width="45%" max-width="45%"
:src="require('../assets/logo3.svg')" :src="require('../assets/logo3.svg')"
...@@ -11,46 +9,32 @@ ...@@ -11,46 +9,32 @@
></v-img> ></v-img>
</v-col> </v-col>
<v-form <v-form ref="form" v-model="valid" lazy-validation>
ref="form"
v-model="valid"
lazy-validation
>
<v-col> <v-col>
<v-text-field <v-text-field
v-model="user.email" v-model="user.email"
:rules="emailRules" :rules="[rules.email]"
label="E-mail" label="Epost"
required required
></v-text-field> ></v-text-field>
</v-col> </v-col>
<v-col align="right">
<v-col
align="right"
>
<v-text-field <v-text-field
v-model="user.password" v-model="user.password"
:append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'" :append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'"
:rules="[rules.required, rules.min]" :rules="[rules.required, rules.min]"
:type="showPassword ? 'text' : 'password'" :type="showPassword ? 'text' : 'password'"
name="input-10-1" name="input-10-1"
label="Password" label="Passord"
counter counter
@click:append="showPassword = !showPassword" @click:append="showPassword = !showPassword"
></v-text-field> ></v-text-field>
<div class="text-decoration-underline mt-n4 mr-10"> <div class="text-decoration-underline mt-n4 mr-10">Glemt passord</div>
Glemt passord
</div>
</v-col> </v-col>
<v-col align="center" justify="space-around">
<v-col
align="center"
justify="space-around"
>
<v-btn <v-btn
:disabled="!valid" :disabled="!valid"
color="success" color="success"
...@@ -63,51 +47,20 @@ ...@@ -63,51 +47,20 @@
</v-btn> </v-btn>
<div> <div>
<a <a href="/" class="text-decoration-none">Ny bruker</a>
href="/"
class="text-decoration-none"
>Ny bruker</a>
</div> </div>
</v-col> </v-col>
</v-form> </v-form>
</div> </div>
</template> </template>
<script> <script>
import useVuelidate from "@vuelidate/core";
import { required, email, minLength, helpers } from "@vuelidate/validators";
import { doLogin } from "@/utils/apiutil"; import { doLogin } from "@/utils/apiutil";
import { mapState } from "vuex"; import { mapState } from "vuex";
export default { export default {
name: "LoginForm.vue", name: "LoginForm.vue",
setup() {
return { v$: useVuelidate() };
},
validations() {
return {
user: {
email: {
required,
email: helpers.withMessage(`E-posten er ugyldig`, email),
},
password: {
required,
min: helpers.withMessage(
({ $params }) => `Passordet må inneholde minst ${$params.min} tegn`,
minLength(8)
),
},
},
};
},
computed: mapState({ computed: mapState({
token: (state) => state.user.token, token: (state) => state.user.token,
}), }),
...@@ -122,13 +75,10 @@ export default { ...@@ -122,13 +75,10 @@ export default {
showPassword: false, showPassword: false,
valid: true, valid: true,
emailRules: [
v => !!v || 'E-mail is required',
v => /.+@.+\..+/.test(v) || 'E-mail must be valid',
],
rules: { rules: {
required: value => !!value || 'Required.', required: (value) => !!value || "Feltet er påkrevd",
min: v => v.length >= 8 || 'Min 8 characters', min: (v) => v.length >= 8 || "Minimum 8 tegn",
email: (v) => /.+@.+\..+/.test(v) || "Epost adressen må være gyldig",
}, },
}; };
}, },
...@@ -136,7 +86,6 @@ export default { ...@@ -136,7 +86,6 @@ export default {
methods: { methods: {
async loginClicked() { async loginClicked() {
console.log(this.user.email + " " + this.user.password); console.log(this.user.email + " " + this.user.password);
this.showError = true;
const loginRequest = { const loginRequest = {
email: this.user.email, email: this.user.email,
password: this.user.password, password: this.user.password,
...@@ -144,8 +93,8 @@ export default { ...@@ -144,8 +93,8 @@ export default {
const loginResponse = await doLogin(loginRequest); const loginResponse = await doLogin(loginRequest);
if (loginResponse === "Failed login") { if (loginResponse === "Failed login") {
this.message = "kunne ikke logge inn"; this.message = "Feil brukernavn/passord";
this.$store.commit('logout'); this.$store.commit("logout");
return; return;
} }
...@@ -153,9 +102,8 @@ export default { ...@@ -153,9 +102,8 @@ export default {
console.log(loginResponse); console.log(loginResponse);
}, },
validate() { validate() {
this.$refs.form.validate() this.$refs.form.validate();
}, },
}, },
}; };
......
<template>
<div>
<v-col align="center" justify="space-around" class="mt-16">
<v-img
max-width="45%"
:src="require('../assets/logo3.svg')"
align="center"
/>
</v-col>
<v-form ref="form" v-model="valid" lazy-validation class="mt-8">
<v-text-field
v-model="user.password"
:rules="[rules.required, rules.min]"
:type="'password'"
name="input-10-1"
label="Passord"
counter
></v-text-field>
<v-text-field
v-model="user.rePassword"
:rules="[rules.required, rules.min, rules.passwordConfirmation]"
:type="'password'"
name="input-10-1"
label="Confirm Password"
counter
></v-text-field>
<v-col justify="space-around" align="center">
<v-btn
:disabled="!valid"
color="success"
class="mb-4 mt-4"
width="50%"
height="40px"
@click="setNewPassword"
>
Endre passord
</v-btn>
</v-col>
</v-form>
</div>
</template>
<script>
export default {
name: "NewPasswordForm.vue",
data() {
return {
user: {
password: "",
rePassword: "",
},
valid: true,
rules: {
required: (value) => !!value || "Feltet er påkrevd",
min: (v) => v.length >= 8 || "Minimum 8 tegn",
passwordConfirmation: (v) => v === this.user.password || "Passordene må være like"
},
};
},
methods: {
async setNewPassword() {
},
validate() {
this.$refs.form.validate();
},
},
};
</script>
import { createRouter, createWebHistory } from "vue-router"; import { createRouter, createWebHistory } from "vue-router";
import HomeView from "../views/HomeView.vue"; import HomeView from "../views/HomeView.vue";
import LoginView from "../views/LoginView.vue"; import LoginView from "../views/LoginView.vue";
import NewPasswordView from "../views/NewPasswordView";
const routes = [ const routes = [
{ {
...@@ -22,6 +23,11 @@ const routes = [ ...@@ -22,6 +23,11 @@ const routes = [
name: "login", name: "login",
component: LoginView, component: LoginView,
}, },
{
path: "/newPassword",
name: "newPassword",
component: NewPasswordView,
},
]; ];
const router = createRouter({ const router = createRouter({
......
<template>
<div class="newPasswordPage">
<NewPasswordForm></NewPasswordForm>
</div>
</template>
<script>
import NewPasswordForm from "@/components/NewPasswordForm";
export default {
name: "NewPasswordView.vue",
components: {
NewPasswordForm,
},
};
</script>
<style scoped>
.newPasswordPage {
background-color: white;
height: 100%;
overflow: auto;
}
</style>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment