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

New password tailwinded

parent ce6de1ce
No related branches found
No related tags found
1 merge request!20New password tailwinded
Pipeline #176261 passed
<template> <template>
<div> <div
<v-col align="center" justify="space-around" class="mt-16"> class="w-full max-w-sm p-6 m-auto bg-white rounded-md shadow-md dark:bg-gray-800"
<v-img >
max-width="45%" <div id="logoField" class="flex justify-center m-6">
:src="require('../assets/logo3.svg')" <img src="../assets/logo3.svg" alt="BoCo logo" />
align="center" </div>
<div
id="firstPasswordField"
:class="{ error: v$.user.password.$errors.length }"
>
<label
for="password"
class="block text-sm text-gray-800 dark:text-gray-200"
>Nytt passord</label
>
<input
type="password"
v-model="v$.user.password.$model"
class="block w-full px-4 py-2 mt-2 text-gray-700 bg-white border rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 focus:border-blue-400 dark:focus:border-blue-300 focus:ring-blue-300 focus:outline-none focus:ring focus:ring-opacity-40"
/> />
</v-col> <!-- error message -->
<div v-for="(error, index) of v$.user.password.$errors" :key="index">
<div
class="text-red-600 text-sm"
v-show="showError"
id="passwordErrorId"
>
{{ error.$message }}
</div>
</div>
</div>
<v-form ref="form" v-model="valid" lazy-validation class="mt-8"> <div
<v-text-field id="secondPasswordField"
v-model="user.password" class="mt-4"
:rules="[rules.required, rules.min]" :class="{ error: v$.user.rePassword.$errors.length }"
:type="'password'" >
name="input-10-1" <div class="flex items-center justify-between">
label="Passord" <label
counter for="rePassword"
></v-text-field> class="block text-sm text-gray-800 dark:text-gray-200"
>Gjenta nytt passord</label
>
</div>
<v-text-field <input
v-model="user.rePassword" type="password"
:rules="[rules.required, rules.min, rules.passwordConfirmation]" v-model="v$.user.rePassword.$model"
:type="'password'" class="block w-full px-4 py-2 mt-2 text-gray-700 bg-white border rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 focus:border-blue-400 dark:focus:border-blue-300 focus:ring-blue-300 focus:outline-none focus:ring focus:ring-opacity-40"
name="input-10-1" />
label="Confirm Password" <!-- error message -->
counter <div v-for="(error, index) of v$.user.rePassword.$errors" :key="index">
></v-text-field> <div
class="text-red-600 text-sm"
v-show="showError"
id="rePasswordErrorId"
>
{{ error.$message }}
</div>
</div>
</div>
<v-col justify="space-around" align="center"> <div id="buttonsField" class="mt-6">
<v-btn <button
:disabled="!valid"
color="success"
class="mb-4 mt-4"
width="50%"
height="40px"
@click="setNewPassword" @click="setNewPassword"
> class="w-full px-4 py-2 tracking-wide text-white transition-colors duration-200 transform bg-gray-700 rounded-md hover:bg-gray-600 focus:outline-none focus:bg-gray-600"
Endre passord >
</v-btn> Endre passord
</v-col> </button>
</v-form> </div>
</div> </div>
</template> </template>
<script> <script>
import useVuelidate from "@vuelidate/core";
import { required, minLength, sameAs } from "@vuelidate/validators";
import { doNewPassword } from "@/utils/apiutil";
import { mapState } from "vuex";
export default { export default {
name: "NewPasswordForm.vue", name: "NewPasswordForm.vue",
setup() {
return { v$: useVuelidate() };
},
validations() {
return {
user: {
password: {
required,
minLength: minLength(8),
},
rePassword: {
required,
minLength: minLength(8),
sameAs: sameAs(this.user.password),
},
},
};
},
data() { data() {
return { return {
user: { user: {
...@@ -54,18 +107,39 @@ export default { ...@@ -54,18 +107,39 @@ export default {
rePassword: "", rePassword: "",
}, },
valid: true, showError: false,
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",
},
}; };
}, },
computed: mapState({
token: (state) => state.user.token,
}),
methods: { methods: {
async setNewPassword() {}, async setNewPassword() {
this.showError = true;
this.v$.user.$touch();
if (this.v$.user.$invalid) {
console.log("Invalid, exiting...");
return;
}
const newPasswordInfo = {
token: this.token,
newPassword: this.password,
};
const newPasswordResponse = doNewPassword(newPasswordInfo);
if (newPasswordResponse.newPasswordSet === true) {
console.log("New password set");
await this.$router.push("/endre");
} else if (newPasswordResponse.newPasswordSet === false) {
console.log("Couldn't set new password");
} else {
console.log("Something went wrong");
}
},
validate() { validate() {
this.$refs.form.validate(); this.$refs.form.validate();
}, },
......
...@@ -71,3 +71,13 @@ export function getOwnerRating(userid) { ...@@ -71,3 +71,13 @@ export function getOwnerRating(userid) {
console.error(error); console.error(error);
}); });
} }
export function doNewPassword() { //m
//add newPasswordInfo to input
const auth = { newPasswordSet: false };
//return axios
//.post(API_URL + "newPassword", newPasswordInfo)
//.then((response) => {auth.newPasswordSet = true;return auth;})
//.catch((error) => {console.log(error);return auth;});
return auth; //remove after axios is added
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment