xref: /openbmc/webui-vue/src/views/ProfileSettings/ProfileSettings.vue (revision fcda20013b8836e171a91c8c47c584449ffd7746)
1b1f559f0SSukanya Pandey<template>
2b1f559f0SSukanya Pandey  <b-container fluid="xl">
3b1f559f0SSukanya Pandey    <page-title />
4b1f559f0SSukanya Pandey
5b1f559f0SSukanya Pandey    <b-row>
6b1f559f0SSukanya Pandey      <b-col md="8" lg="8" xl="6">
7fc16f3c2SSukanya Pandey        <page-section
8fc16f3c2SSukanya Pandey          :section-title="$t('pageProfileSettings.profileInfoTitle')"
9fc16f3c2SSukanya Pandey        >
10b1f559f0SSukanya Pandey          <dl>
11fc16f3c2SSukanya Pandey            <dt>{{ $t('pageProfileSettings.username') }}</dt>
12b1f559f0SSukanya Pandey            <dd>
13b1f559f0SSukanya Pandey              {{ username }}
14b1f559f0SSukanya Pandey            </dd>
15b1f559f0SSukanya Pandey          </dl>
16b1f559f0SSukanya Pandey        </page-section>
17b1f559f0SSukanya Pandey      </b-col>
18b1f559f0SSukanya Pandey    </b-row>
19b1f559f0SSukanya Pandey
20b1f559f0SSukanya Pandey    <b-form @submit.prevent="submitForm">
21b1f559f0SSukanya Pandey      <b-row>
22b1f559f0SSukanya Pandey        <b-col sm="8" md="6" xl="3">
23fc16f3c2SSukanya Pandey          <page-section
24fc16f3c2SSukanya Pandey            :section-title="$t('pageProfileSettings.changePassword')"
25fc16f3c2SSukanya Pandey          >
26b1f559f0SSukanya Pandey            <b-form-group
27b1f559f0SSukanya Pandey              id="input-group-1"
28fc16f3c2SSukanya Pandey              :label="$t('pageProfileSettings.newPassword')"
29b1f559f0SSukanya Pandey              label-for="input-1"
30b1f559f0SSukanya Pandey            >
31b1f559f0SSukanya Pandey              <b-form-text id="password-help-block">
32b1f559f0SSukanya Pandey                {{
33b1f559f0SSukanya Pandey                  $t('pageLocalUserManagement.modal.passwordMustBeBetween', {
34b1f559f0SSukanya Pandey                    min: passwordRequirements.minLength,
35b1f559f0SSukanya Pandey                    max: passwordRequirements.maxLength
36b1f559f0SSukanya Pandey                  })
37b1f559f0SSukanya Pandey                }}
38b1f559f0SSukanya Pandey              </b-form-text>
39b1f559f0SSukanya Pandey              <input-password-toggle>
40b1f559f0SSukanya Pandey                <b-form-input
41b1f559f0SSukanya Pandey                  id="password"
42b1f559f0SSukanya Pandey                  v-model="form.newPassword"
43b1f559f0SSukanya Pandey                  type="password"
44b1f559f0SSukanya Pandey                  aria-describedby="password-help-block"
45b1f559f0SSukanya Pandey                  :state="getValidationState($v.form.newPassword)"
464334d260SSukanya Pandey                  data-test-id="profileSettings-input-newPassword"
47b1f559f0SSukanya Pandey                  @input="$v.form.newPassword.$touch()"
48b1f559f0SSukanya Pandey                />
49b1f559f0SSukanya Pandey                <b-form-invalid-feedback role="alert">
50b1f559f0SSukanya Pandey                  <template
51b1f559f0SSukanya Pandey                    v-if="
52b1f559f0SSukanya Pandey                      !$v.form.newPassword.minLength ||
53b1f559f0SSukanya Pandey                        !$v.form.newPassword.maxLength
54b1f559f0SSukanya Pandey                    "
55b1f559f0SSukanya Pandey                  >
56b1f559f0SSukanya Pandey                    {{
57fc16f3c2SSukanya Pandey                      $t('pageProfileSettings.newPassLabelTextInfo', {
58b1f559f0SSukanya Pandey                        min: passwordRequirements.minLength,
59b1f559f0SSukanya Pandey                        max: passwordRequirements.maxLength
60b1f559f0SSukanya Pandey                      })
61b1f559f0SSukanya Pandey                    }}
62b1f559f0SSukanya Pandey                  </template>
63b1f559f0SSukanya Pandey                </b-form-invalid-feedback>
64b1f559f0SSukanya Pandey              </input-password-toggle>
65b1f559f0SSukanya Pandey            </b-form-group>
66b1f559f0SSukanya Pandey            <b-form-group
67b1f559f0SSukanya Pandey              id="input-group-2"
68fc16f3c2SSukanya Pandey              :label="$t('pageProfileSettings.confirmPassword')"
69b1f559f0SSukanya Pandey              label-for="input-2"
70b1f559f0SSukanya Pandey            >
71b1f559f0SSukanya Pandey              <input-password-toggle>
72b1f559f0SSukanya Pandey                <b-form-input
73b1f559f0SSukanya Pandey                  id="password-confirmation"
74b1f559f0SSukanya Pandey                  v-model="form.confirmPassword"
75b1f559f0SSukanya Pandey                  type="password"
76b1f559f0SSukanya Pandey                  :state="getValidationState($v.form.confirmPassword)"
774334d260SSukanya Pandey                  data-test-id="profileSettings-input-confirmPassword"
78b1f559f0SSukanya Pandey                  @input="$v.form.confirmPassword.$touch()"
79b1f559f0SSukanya Pandey                />
80b1f559f0SSukanya Pandey                <b-form-invalid-feedback role="alert">
81fc16f3c2SSukanya Pandey                  <template v-if="!$v.form.confirmPassword.sameAsPassword">
82fc16f3c2SSukanya Pandey                    {{ $t('pageProfileSettings.passwordsDoNotMatch') }}
83b1f559f0SSukanya Pandey                  </template>
84b1f559f0SSukanya Pandey                </b-form-invalid-feedback>
85b1f559f0SSukanya Pandey              </input-password-toggle>
86b1f559f0SSukanya Pandey            </b-form-group>
87b1f559f0SSukanya Pandey          </page-section>
88b1f559f0SSukanya Pandey        </b-col>
89b1f559f0SSukanya Pandey      </b-row>
90fc16f3c2SSukanya Pandey      <page-section :section-title="$t('pageProfileSettings.timezoneDisplay')">
91fc16f3c2SSukanya Pandey        <p>{{ $t('pageProfileSettings.timezoneDisplayDesc') }}</p>
92fc16f3c2SSukanya Pandey        <b-row>
93fc16f3c2SSukanya Pandey          <b-col md="9" lg="8" xl="9">
94fc16f3c2SSukanya Pandey            <b-form-group :label="$t('pageProfileSettings.timezone')">
95fc16f3c2SSukanya Pandey              <b-form-radio
96fc16f3c2SSukanya Pandey                v-model="form.isUtcDisplay"
97fc16f3c2SSukanya Pandey                :value="true"
984334d260SSukanya Pandey                data-test-id="profileSettings-radio-defaultUTC"
99fc16f3c2SSukanya Pandey                @change="$v.form.isUtcDisplay.$touch()"
100fc16f3c2SSukanya Pandey              >
101fc16f3c2SSukanya Pandey                {{ $t('pageProfileSettings.defaultUTC') }}
102fc16f3c2SSukanya Pandey              </b-form-radio>
103fc16f3c2SSukanya Pandey              <b-form-radio
104fc16f3c2SSukanya Pandey                v-model="form.isUtcDisplay"
105fc16f3c2SSukanya Pandey                :value="false"
1064334d260SSukanya Pandey                data-test-id="profileSettings-radio-browserOffset"
107fc16f3c2SSukanya Pandey                @change="$v.form.isUtcDisplay.$touch()"
108fc16f3c2SSukanya Pandey              >
109fc16f3c2SSukanya Pandey                {{
110fc16f3c2SSukanya Pandey                  $t('pageProfileSettings.browserOffset', {
111fc16f3c2SSukanya Pandey                    timezone
112fc16f3c2SSukanya Pandey                  })
113fc16f3c2SSukanya Pandey                }}
114fc16f3c2SSukanya Pandey              </b-form-radio>
115fc16f3c2SSukanya Pandey            </b-form-group>
116fc16f3c2SSukanya Pandey          </b-col>
117fc16f3c2SSukanya Pandey        </b-row>
118fc16f3c2SSukanya Pandey      </page-section>
1194334d260SSukanya Pandey      <b-button
1204334d260SSukanya Pandey        variant="primary"
1214334d260SSukanya Pandey        type="submit"
1224334d260SSukanya Pandey        data-test-id="profileSettings-button-saveSettings"
1234334d260SSukanya Pandey      >
124fc16f3c2SSukanya Pandey        {{ $t('global.action.saveSettings') }}
125b1f559f0SSukanya Pandey      </b-button>
126b1f559f0SSukanya Pandey    </b-form>
127b1f559f0SSukanya Pandey  </b-container>
128b1f559f0SSukanya Pandey</template>
129b1f559f0SSukanya Pandey
130b1f559f0SSukanya Pandey<script>
131fc16f3c2SSukanya Pandeyimport i18n from '@/i18n';
132b1f559f0SSukanya Pandeyimport BVToastMixin from '@/components/Mixins/BVToastMixin';
133b1f559f0SSukanya Pandeyimport InputPasswordToggle from '@/components/Global/InputPasswordToggle';
134b1f559f0SSukanya Pandeyimport {
135b1f559f0SSukanya Pandey  maxLength,
136b1f559f0SSukanya Pandey  minLength,
137b1f559f0SSukanya Pandey  required,
138b1f559f0SSukanya Pandey  sameAs
139b1f559f0SSukanya Pandey} from 'vuelidate/lib/validators';
140b93608dbSSukanya Pandeyimport LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
141*fcda2001SDixsie Wolmersimport LocalTimezoneLabelMixin from '@/components/Mixins/LocalTimezoneLabelMixin';
142b93608dbSSukanya Pandeyimport PageTitle from '@/components/Global/PageTitle';
143b93608dbSSukanya Pandeyimport PageSection from '@/components/Global/PageSection';
144b93608dbSSukanya Pandeyimport VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
145b1f559f0SSukanya Pandey
146b1f559f0SSukanya Pandeyexport default {
147b1f559f0SSukanya Pandey  name: 'ProfileSettings',
148b93608dbSSukanya Pandey  components: { InputPasswordToggle, PageSection, PageTitle },
149*fcda2001SDixsie Wolmers  mixins: [
150*fcda2001SDixsie Wolmers    BVToastMixin,
151*fcda2001SDixsie Wolmers    LocalTimezoneLabelMixin,
152*fcda2001SDixsie Wolmers    LoadingBarMixin,
153*fcda2001SDixsie Wolmers    VuelidateMixin
154*fcda2001SDixsie Wolmers  ],
155b1f559f0SSukanya Pandey  data() {
156b1f559f0SSukanya Pandey    return {
157b1f559f0SSukanya Pandey      form: {
158b1f559f0SSukanya Pandey        newPassword: '',
159fc16f3c2SSukanya Pandey        confirmPassword: '',
160fc16f3c2SSukanya Pandey        isUtcDisplay: this.$store.getters['global/isUtcDisplay']
161b1f559f0SSukanya Pandey      }
162b1f559f0SSukanya Pandey    };
163b1f559f0SSukanya Pandey  },
164b93608dbSSukanya Pandey  computed: {
165b93608dbSSukanya Pandey    username() {
166b93608dbSSukanya Pandey      return this.$store.getters['global/username'];
167b93608dbSSukanya Pandey    },
168b93608dbSSukanya Pandey    passwordRequirements() {
169b93608dbSSukanya Pandey      return this.$store.getters['localUsers/accountPasswordRequirements'];
170fc16f3c2SSukanya Pandey    },
171fc16f3c2SSukanya Pandey    timezone() {
172*fcda2001SDixsie Wolmers      return this.localOffset();
173b93608dbSSukanya Pandey    }
174b93608dbSSukanya Pandey  },
175b93608dbSSukanya Pandey  created() {
176b93608dbSSukanya Pandey    this.startLoader();
177b93608dbSSukanya Pandey    this.$store
178b93608dbSSukanya Pandey      .dispatch('localUsers/getAccountSettings')
179b93608dbSSukanya Pandey      .finally(() => this.endLoader());
180b93608dbSSukanya Pandey  },
181b1f559f0SSukanya Pandey  validations() {
182b1f559f0SSukanya Pandey    return {
183b1f559f0SSukanya Pandey      form: {
184fc16f3c2SSukanya Pandey        isUtcDisplay: { required },
185b1f559f0SSukanya Pandey        newPassword: {
186b1f559f0SSukanya Pandey          minLength: minLength(this.passwordRequirements.minLength),
187b1f559f0SSukanya Pandey          maxLength: maxLength(this.passwordRequirements.maxLength)
188b1f559f0SSukanya Pandey        },
189b1f559f0SSukanya Pandey        confirmPassword: {
190b1f559f0SSukanya Pandey          sameAsPassword: sameAs('newPassword')
191b1f559f0SSukanya Pandey        }
192b1f559f0SSukanya Pandey      }
193b1f559f0SSukanya Pandey    };
194b1f559f0SSukanya Pandey  },
195b1f559f0SSukanya Pandey  methods: {
196fc16f3c2SSukanya Pandey    saveNewPasswordInputData() {
197fc16f3c2SSukanya Pandey      this.$v.form.confirmPassword.$touch();
198fc16f3c2SSukanya Pandey      this.$v.form.newPassword.$touch();
199b1f559f0SSukanya Pandey      if (this.$v.$invalid) return;
200b1f559f0SSukanya Pandey      let userData = {
201b1f559f0SSukanya Pandey        originalUsername: this.username,
202b1f559f0SSukanya Pandey        password: this.form.newPassword
203b1f559f0SSukanya Pandey      };
204b1f559f0SSukanya Pandey
205b1f559f0SSukanya Pandey      this.$store
206b1f559f0SSukanya Pandey        .dispatch('localUsers/updateUser', userData)
2079422e1a6SSukanya Pandey        .then(message => {
2089422e1a6SSukanya Pandey          (this.form.newPassword = ''), (this.form.confirmPassword = '');
2099422e1a6SSukanya Pandey          this.$v.$reset();
2109422e1a6SSukanya Pandey          this.successToast(message);
2119422e1a6SSukanya Pandey        })
212b1f559f0SSukanya Pandey        .catch(({ message }) => this.errorToast(message));
213fc16f3c2SSukanya Pandey    },
214fc16f3c2SSukanya Pandey    saveTimeZonePrefrenceData() {
215fc16f3c2SSukanya Pandey      localStorage.setItem('storedUtcDisplay', this.form.isUtcDisplay);
216fc16f3c2SSukanya Pandey      this.$store.commit('global/setUtcTime', this.form.isUtcDisplay);
217fc16f3c2SSukanya Pandey      this.successToast(
218fc16f3c2SSukanya Pandey        i18n.t('pageProfileSettings.toast.successSaveSettings')
219fc16f3c2SSukanya Pandey      );
220fc16f3c2SSukanya Pandey    },
221fc16f3c2SSukanya Pandey    submitForm() {
222fc16f3c2SSukanya Pandey      if (this.form.confirmPassword || this.form.newPassword) {
223fc16f3c2SSukanya Pandey        this.saveNewPasswordInputData();
224fc16f3c2SSukanya Pandey      }
225fc16f3c2SSukanya Pandey      if (this.$v.form.isUtcDisplay.$anyDirty) {
226fc16f3c2SSukanya Pandey        this.saveTimeZonePrefrenceData();
227fc16f3c2SSukanya Pandey      }
228b1f559f0SSukanya Pandey    }
229b1f559f0SSukanya Pandey  }
230b1f559f0SSukanya Pandey};
231b1f559f0SSukanya Pandey</script>
232