123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597 |
- <template>
- <div>
- <metadata
- :title="mode === 'reset' ? 'Reset password' : 'Set password'"
- />
- <main-header />
- <div class="container">
- <div class="content-wrapper">
- <h1 id="title">
- {{ mode === "reset" ? "Reset" : "Set" }} your password
- </h1>
- <div id="steps">
- <p class="step" :class="{ selected: step === 1 }">1</p>
- <span class="divider"></span>
- <p class="step" :class="{ selected: step === 2 }">2</p>
- <span class="divider"></span>
- <p class="step" :class="{ selected: step === 3 }">3</p>
- </div>
- <transition name="steps-fade" mode="out-in">
- <!-- Step 1 -- Enter email address -->
- <div class="content-box" v-if="step === 1" :key="step">
- <h2 class="content-box-title">
- Enter your email address
- </h2>
- <p class="content-box-description">
- We will send a code to your email address to verify
- your identity.
- </p>
- <p class="content-box-optional-helper">
- <a href="#" @click="step = 2"
- >Already have a code?</a
- >
- </p>
- <div class="content-box-inputs">
- <div class="control is-grouped input-with-button">
- <p class="control is-expanded">
- <input
- class="input"
- type="email"
- placeholder="Enter email address here..."
- autofocus
- v-model="email"
- @keyup.enter="submitEmail()"
- @blur="onInputBlur('email')"
- />
- </p>
- <p class="control">
- <a
- class="button is-info"
- href="#"
- @click="submitEmail()"
- ><i
- class="material-icons icon-with-button"
- >mail</i
- >Request</a
- >
- </p>
- </div>
- <transition name="fadein-helpbox">
- <p
- class="help"
- v-if="validation.email.entered"
- :class="
- validation.email.valid
- ? 'is-success'
- : 'is-danger'
- "
- >
- {{ validation.email.message }}
- </p>
- </transition>
- </div>
- </div>
- <!-- Step 2 -- Enter code -->
- <div class="content-box" v-if="step === 2" :key="step">
- <h2 class="content-box-title">
- Enter the code sent to your email
- </h2>
- <p class="content-box-description">
- A code has been sent to <strong>email</strong>.
- </p>
- <p class="content-box-optional-helper">
- <a
- href="#"
- @click="email ? submitEmail() : (step = 1)"
- >Request another code</a
- >
- </p>
- <div class="content-box-inputs">
- <div class="control is-grouped input-with-button">
- <p class="control is-expanded">
- <input
- class="input"
- type="text"
- placeholder="Enter code here..."
- autofocus
- v-model="code"
- @keyup.enter="verifyCode()"
- />
- </p>
- <p class="control">
- <a
- class="button is-info"
- href="#"
- @click="verifyCode()"
- ><i
- class="material-icons icon-with-button"
- >vpn_key</i
- >Verify</a
- >
- </p>
- </div>
- </div>
- </div>
- <!-- Step 3 -- Set new password -->
- <div class="content-box" v-if="step === 3" :key="step">
- <h2 class="content-box-title">Set a new password</h2>
- <p class="content-box-description">
- Create a new password for your account.
- </p>
- <div class="content-box-inputs">
- <p class="control is-expanded">
- <label for="new-password">New password</label>
- <input
- class="input"
- id="new-password"
- type="password"
- placeholder="Enter password here..."
- v-model="newPassword"
- @blur="onInputBlur('newPassword')"
- />
- </p>
- <transition name="fadein-helpbox">
- <p
- class="help"
- v-if="validation.newPassword.entered"
- :class="
- validation.newPassword.valid
- ? 'is-success'
- : 'is-danger'
- "
- >
- {{ validation.newPassword.message }}
- </p>
- </transition>
- <p
- id="new-password-again-input"
- class="control is-expanded"
- >
- <label for="new-password-again"
- >New password again</label
- >
- <input
- class="input"
- id="new-password-again"
- type="password"
- placeholder="Enter password here..."
- v-model="newPasswordAgain"
- @keyup.enter="changePassword()"
- @blur="onInputBlur('newPasswordAgain')"
- />
- </p>
- <transition name="fadein-helpbox">
- <p
- class="help"
- v-if="validation.newPasswordAgain.entered"
- :class="
- validation.newPasswordAgain.valid
- ? 'is-success'
- : 'is-danger'
- "
- >
- {{ validation.newPasswordAgain.message }}
- </p>
- </transition>
- <a
- id="change-password-button"
- class="button is-success"
- href="#"
- @click="changePassword()"
- >
- Change password</a
- >
- </div>
- </div>
- <div
- class="content-box reset-status-box"
- v-if="step === 4"
- :key="step"
- >
- <i class="material-icons success-icon">check_circle</i>
- <h2>Password successfully {{ mode }}</h2>
- <router-link
- class="button is-dark"
- href="#"
- to="/settings"
- ><i class="material-icons icon-with-button">undo</i
- >Return to Settings</router-link
- >
- </div>
- <div
- class="content-box reset-status-box"
- v-if="step === 5"
- :key="step"
- >
- <i class="material-icons error-icon">error</i>
- <h2>
- Password {{ mode }} failed, please try again later
- </h2>
- <router-link
- class="button is-dark"
- href="#"
- to="/settings"
- ><i class="material-icons icon-with-button">undo</i
- >Return to Settings</router-link
- >
- </div>
- </transition>
- </div>
- </div>
- <main-footer />
- </div>
- </template>
- <script>
- import Toast from "toasters";
- import MainHeader from "../components/layout/MainHeader.vue";
- import MainFooter from "../components/layout/MainFooter.vue";
- import io from "../io";
- import validation from "../validation";
- export default {
- components: { MainHeader, MainFooter },
- data() {
- return {
- email: "",
- code: "",
- newPassword: "",
- newPasswordAgain: "",
- validation: {
- email: {
- entered: false,
- valid: false,
- message: "Please enter a valid email address."
- },
- newPassword: {
- entered: false,
- valid: false,
- message: "Please enter a valid password."
- },
- newPasswordAgain: {
- entered: false,
- valid: false,
- message: "This password must match."
- }
- },
- step: 1
- };
- },
- props: {
- mode: {
- default: "reset",
- enum: ["reset", "set"],
- type: String
- }
- },
- mounted() {
- io.getSocket(socket => {
- this.socket = socket;
- });
- },
- watch: {
- email(value) {
- if (
- value.indexOf("@") !== value.lastIndexOf("@") ||
- !validation.regex.emailSimple.test(value)
- ) {
- this.validation.email.message =
- "Please enter a valid email address.";
- this.validation.email.valid = false;
- } else {
- this.validation.email.message = "Everything looks great!";
- this.validation.email.valid = true;
- }
- },
- newPassword(value) {
- this.checkPasswordMatch(value, this.newPasswordAgain);
- if (!validation.isLength(value, 6, 200)) {
- this.validation.newPassword.message =
- "Password must have between 6 and 200 characters.";
- this.validation.newPassword.valid = false;
- } else if (!validation.regex.password.test(value)) {
- this.validation.newPassword.message =
- "Invalid password format. Must have one lowercase letter, one uppercase letter, one number and one special character.";
- this.validation.newPassword.valid = false;
- } else {
- this.validation.newPassword.message = "Everything looks great!";
- this.validation.newPassword.valid = true;
- }
- },
- newPasswordAgain(value) {
- this.checkPasswordMatch(this.newPassword, value);
- }
- },
- methods: {
- checkPasswordMatch(newPassword, newPasswordAgain) {
- if (newPasswordAgain !== newPassword) {
- this.validation.newPasswordAgain.message =
- "This password must match.";
- this.validation.newPasswordAgain.valid = false;
- } else {
- this.validation.newPasswordAgain.message =
- "Everything looks great!";
- this.validation.newPasswordAgain.valid = true;
- }
- },
- onInputBlur(inputName) {
- this.validation[inputName].entered = true;
- },
- submitEmail() {
- if (
- this.email.indexOf("@") !== this.email.lastIndexOf("@") ||
- !validation.regex.emailSimple.test(this.email)
- )
- return new Toast({
- content: "Invalid email format.",
- timeout: 8000
- });
- if (!this.email)
- return new Toast({
- content: "Email cannot be empty",
- timeout: 8000
- });
- if (this.mode === "set") {
- return this.socket.emit("users.requestPassword", res => {
- new Toast({ content: res.message, timeout: 8000 });
- if (res.status === "success") {
- this.step = 2;
- }
- });
- }
- return this.socket.emit(
- "users.requestPasswordReset",
- this.email,
- res => {
- new Toast({ content: res.message, timeout: 8000 });
- if (res.status === "success") {
- this.code = ""; // in case: already have a code -> request another code
- this.step = 2;
- } else this.step = 5;
- }
- );
- },
- verifyCode() {
- if (!this.code)
- return new Toast({
- content: "Code cannot be empty",
- timeout: 8000
- });
- return this.socket.emit(
- this.mode === "set"
- ? "users.verifyPasswordCode"
- : "users.verifyPasswordResetCode",
- this.code,
- res => {
- new Toast({ content: res.message, timeout: 8000 });
- if (res.status === "success") {
- this.step = 3;
- }
- }
- );
- },
- changePassword() {
- if (
- this.validation.newPassword.valid &&
- !this.validation.newPasswordAgain.valid
- )
- return new Toast({
- content: "Please ensure the passwords match.",
- timeout: 8000
- });
- if (!this.validation.newPassword.valid)
- return new Toast({
- content: "Please enter a valid password.",
- timeout: 8000
- });
- return this.socket.emit(
- this.mode === "set"
- ? "users.changePasswordWithCode"
- : "users.changePasswordWithResetCode",
- this.code,
- this.newPassword,
- res => {
- new Toast({ content: res.message, timeout: 8000 });
- if (res.status === "success") this.step = 4;
- else this.step = 5;
- }
- );
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- @import "../styles/global.scss";
- .night-mode {
- .label {
- color: #ddd;
- }
- .skip-step {
- border: 0;
- }
- }
- h1,
- h2,
- p {
- margin: 0;
- }
- .container {
- padding: 25px;
- #title {
- color: #000;
- font-size: 42px;
- text-align: center;
- }
- #steps {
- display: flex;
- align-items: center;
- justify-content: center;
- height: 50px;
- margin-top: 36px;
- @media screen and (max-width: 300px) {
- display: none;
- }
- .step {
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 100%;
- border: 1px solid $dark-grey;
- min-width: 50px;
- min-height: 50px;
- background-color: #fff;
- font-size: 30px;
- cursor: pointer;
- &.selected {
- background-color: $musare-blue;
- color: #fff;
- border: 0;
- }
- }
- .divider {
- display: flex;
- justify-content: center;
- width: 180px;
- height: 1px;
- background-color: $dark-grey;
- }
- }
- .content-box {
- margin-top: 90px;
- border-radius: 3px;
- background-color: #fff;
- border: 1px solid $dark-grey;
- max-width: 580px;
- padding: 40px;
- @media screen and (max-width: 300px) {
- margin-top: 30px;
- padding: 30px 20px;
- }
- .content-box-title {
- font-size: 25px;
- color: #000;
- }
- .content-box-description {
- font-size: 14px;
- color: $dark-grey;
- }
- .content-box-optional-helper {
- margin-top: 15px;
- color: $musare-blue;
- text-decoration: underline;
- font-size: 16px;
- }
- .content-box-inputs {
- margin-top: 35px;
- .input-with-button {
- .button {
- width: 105px;
- }
- @media screen and (max-width: 450px) {
- flex-direction: column;
- }
- }
- label {
- font-size: 11px;
- }
- #change-password-button {
- margin-top: 36px;
- width: 175px;
- }
- }
- }
- .reset-status-box {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- height: 356px;
- h2 {
- margin-top: 10px;
- font-size: 21px;
- font-weight: 800;
- color: #000;
- text-align: center;
- }
- .success-icon {
- color: #24a216;
- }
- .error-icon {
- color: $red;
- }
- .success-icon,
- .error-icon {
- font-size: 125px;
- }
- .button {
- margin-top: 36px;
- }
- }
- }
- .steps-fade-enter-active,
- .steps-fade-leave-active {
- transition: all 0.3s ease;
- }
- .steps-fade-enter,
- .steps-fade-leave-to {
- opacity: 0;
- }
- .skip-step {
- background-color: #7e7e7e;
- color: $white;
- }
- </style>
|