21
21
</template >
22
22
<v-list >
23
23
<v-list-item @click =" logout" >
24
- <v-list-item-title >{{ $t('app.logout') }}</v-list-item-title >
24
+ <v-list-item-title >{{ $t('app.logout') }} <v-icon dark > mdi-logout </v-icon > </v-list-item-title >
25
+ </v-list-item >
26
+ <v-list-item @click =" openChangePasswordDialog" >
27
+ <v-list-item-title >{{ $t('login.changePassword') }} <v-icon dark > mdi-lock-reset </v-icon >
28
+ </v-list-item-title >
25
29
</v-list-item >
26
30
</v-list >
27
31
</v-menu >
28
32
</v-app-bar >
29
33
34
+ <!-- Change Password Dialog -->
35
+ <v-dialog scrollable v-if =" loggedInUser" v-model =" showChangePasswordDialog" max-width =" 400px" >
36
+ <v-card >
37
+ <v-card-title >{{ $t('login.changePassword') }}</v-card-title >
38
+ <v-card-text >
39
+ <v-text-field v-model =" loggedInUser" :label =" $t('login.username')" type =" text" disabled ></v-text-field >
40
+
41
+ <v-text-field v-model =" currentPassword" :label =" $t('login.currentPassword')" type =" password"
42
+ required ></v-text-field >
43
+
44
+ <v-text-field v-model =" newPassword" :label =" $t('login.newPassword')" type =" password" required ></v-text-field >
45
+ <v-text-field v-model =" confirmNewPassword" :label =" $t('login.confirmNewPassword')" type =" password"
46
+ required ></v-text-field >
47
+ </v-card-text >
48
+ <v-card-actions >
49
+ <v-alert v-if =" errorMessage" type =" error" dense >
50
+ {{ errorMessage }}
51
+ </v-alert >
52
+ <v-btn color =" orange" variant =" tonal" @click =" showChangePasswordDialog = false" >
53
+ {{ $t('common.cancel') }}
54
+ </v-btn >
55
+ <v-btn color =" primary" variant =" tonal" @click =" changePwd" >
56
+ {{ $t('common.save') }}
57
+ </v-btn >
58
+ </v-card-actions >
59
+ </v-card >
60
+ </v-dialog >
61
+
30
62
<v-main class =" flex-grow-1" style =" overflow-y : auto ; scrollbar-width : none ; -ms-overflow-style : none ;" >
31
63
<router-view ></router-view >
32
64
</v-main >
@@ -46,7 +78,12 @@ const vuetifyTheme = useTheme();
46
78
const { locale , t } = useI18n ();
47
79
48
80
const currentLocale = ref (locale .value );
49
- const loggedInUser = ref (" ?" );
81
+ const loggedInUser = ref (" " );
82
+ const showChangePasswordDialog = ref (false );
83
+ const newPassword = ref (" " );
84
+ const confirmNewPassword = ref (" " );
85
+ const currentPassword = ref (" " );
86
+ const errorMessage = ref (" " );
50
87
51
88
const availableLocales = [
52
89
{ title: ' English' , value: ' en' },
@@ -98,6 +135,69 @@ const logout = () => {
98
135
});
99
136
};
100
137
138
+ const openChangePasswordDialog = () => {
139
+ errorMessage .value = " "
140
+ currentPassword .value = newPassword .value = confirmNewPassword .value = " "
141
+ showChangePasswordDialog .value = true
142
+ }
143
+
144
+ const changePwd = () => {
145
+
146
+ // Validate passwords
147
+ if (newPassword .value !== confirmNewPassword .value ) {
148
+ errorMessage .value = t (' login.passwordMismatch' )
149
+ setTimeout (() => {
150
+ errorMessage .value = " "
151
+ }, 1500 )
152
+ return
153
+ }
154
+
155
+ if (newPassword .value .trim () === " " || newPassword .value .trim ().length < 4 ) {
156
+ errorMessage .value = t (' login.invalidNewPassword' )
157
+ setTimeout (() => {
158
+ errorMessage .value = " "
159
+ }, 1500 )
160
+ return
161
+ }
162
+
163
+ let ck = parseCookie (document .cookie )
164
+ if (' json-scada-user' in ck) {
165
+ ck = JSON .parse (ck[' json-scada-user' ])
166
+ }
167
+
168
+ fetch (' /Invoke/auth/changePassword' , {
169
+ method: ' post' ,
170
+ headers: {
171
+ Accept: ' application/json' ,
172
+ ' Content-Type' : ' application/json' ,
173
+ },
174
+ body: JSON .stringify ({
175
+ username: ck .username ,
176
+ currentPassword: currentPassword .value .trim (),
177
+ newPassword: newPassword .value .trim (),
178
+ }),
179
+ })
180
+ .then ((res ) => res .json ())
181
+ .then ((data ) => {
182
+ if (! (' error' in data)) {
183
+ errorMessage .value = " "
184
+ showChangePasswordDialog .value = false
185
+ } else {
186
+ errorMessage .value = t (' login.changePasswordFailed' )
187
+ setTimeout (() => {
188
+ errorMessage .value = " "
189
+ }, 1500 )
190
+ }
191
+ })
192
+ .catch ((err ) => {
193
+ console .warn (err)
194
+ errorMessage .value = t (' login.changePasswordError' )
195
+ setTimeout (() => {
196
+ errorMessage .value = " "
197
+ }, 1500 )
198
+ })
199
+ }
200
+
101
201
watch (currentLocale, (newLocale ) => {
102
202
locale .value = newLocale;
103
203
localStorage .setItem (STORAGE_KEY , newLocale);
0 commit comments