135135 states: @json ($states ),
136136 status: @json ($status ),
137137 global2FAEnabled: @json ($global2FAEnabled ),
138+ ssoUser: @json ($ssoUser ),
138139 errors: {
139140 username: null ,
140141 firstname: null ,
145146 },
146147 confPassword: ' ' ,
147148 image: ' ' ,
149+ originalEmail: ' ' ,
150+ emailHasChanged: false ,
148151 options: [
149152 {
150153 src: @json ($currentUser [' avatar' ] ),
168171 });
169172 }
170173 },
174+ mounted () {
175+ this .originalEmail = this .formData .email ;
176+ const togglePassword = document .querySelector (' #togglePassword' );
177+ const password = document .querySelector (' #valpassword' );
178+
179+ togglePassword .addEventListener (' click' , function (e ) {
180+ const type = password .getAttribute (' type' ) === ' password' ? ' text' : ' password' ;
181+ password .setAttribute (' type' , type);
182+ this .classList .toggle (' fa-eye-slash' );
183+ });
184+ },
171185 methods: {
172186 openAvatarModal () {
173187 modalVueInstance .$refs .updateAvatarModal .show ();
174188 },
175189 profileUpdate () {
176- this .resetErrors ();
177- if (@json ($enabled2FA ) && this .global2FAEnabled .length === 0 ) {
178- let message = ' The Two Step Authentication Method has not been set. ' +
179- ' Please contact your administrator.' ;
180- // User has not enabled two-factor authentication correctly
181- ProcessMaker .alert (this .$t ($message), ' warning' );
182- return false ;
183- }
184- if (! this .validatePassword ()) return false ;
185- if (@json ($enabled2FA ) && typeof this .formData .preferences_2fa != " undefined" &&
186- this .formData .preferences_2fa != null && this .formData .preferences_2fa .length < 1 )
187- return false ;
188- if (this .image ) {
189- this .formData .avatar = this .image ;
190- }
191- if (this .image === false ) {
192- this .formData .avatar = false ;
193- }
194- ProcessMaker .apiClient .put (' users/' + this .formData .id , this .formData )
195- .then ((response ) => {
196- ProcessMaker .alert (this .$t (' Your profile was saved.' ), ' success' )
197- window .ProcessMaker .events .$emit (' update-profile-avatar' );
198- })
199- .catch (error => {
200- this .errors = error .response .data .errors ;
201- });
190+ if (this .emailHasChanged && ! this .ssoUser ) {
191+ $ (' #validateModal' ).modal (' show' );
192+ } else {
193+ this .saveProfileChanges ();
194+ }
202195 },
203196 deleteAvatar () {
204197 let optionValues = formVueInstance .$data .options [0 ];
241234 onClose () {
242235 window .location .href = ' /admin/users' ;
243236 },
237+ showModal () {
238+ $ (' #validateModal' ).modal (' show' );
239+ },
240+ closeModal () {
241+ $ (' #validateModal' ).modal (' hide' );
242+ },
243+ saveProfileChanges () {
244+ this .resetErrors ();
245+ if (@json ($enabled2FA ) && this .global2FAEnabled .length === 0 ) {
246+ let message = ' The Two Step Authentication Method has not been set. ' +
247+ ' Please contact your administrator.' ;
248+ // User has not enabled two-factor authentication correctly
249+ ProcessMaker .alert (this .$t ($message), ' warning' );
250+ return false ;
251+ }
252+ if (! this .validatePassword ()) return false ;
253+ if (@json ($enabled2FA ) && typeof this .formData .preferences_2fa != " undefined" &&
254+ this .formData .preferences_2fa != null && this .formData .preferences_2fa .length < 1 )
255+ return false ;
256+ if (this .image ) {
257+ this .formData .avatar = this .image ;
258+ }
259+ if (this .image === false ) {
260+ this .formData .avatar = false ;
261+ }
262+ ProcessMaker .apiClient .put (' users/' + this .formData .id , this .formData )
263+ .then ((response ) => {
264+ ProcessMaker .alert (this .$t (' Your profile was saved.' ), ' success' )
265+ window .ProcessMaker .events .$emit (' update-profile-avatar' );
266+ this .originalEmail = this .formData .email ;
267+ this .emailHasChanged = false ;
268+ this .formData .valpassword = " " ;
269+ })
270+ .catch (error => {
271+ this .errors = error .response .data .errors ;
272+ });
273+
274+ this .closeModal ();
275+ },
276+ checkEmailChange () {
277+ this .emailHasChanged = this .formData .email !== this .originalEmail ;
278+ },
244279 },
245280 computed: {
246281 state2FA () {
378413
379414 // TODO: HANDLE CONNECTION UPDATE
380415 this .onCloseModal ;
381- }
416+ },
382417 }
383418 });
384419 < / script>
385- @endsection
420+ @endsection
0 commit comments