<fim-prefix>r otpEnabled = false
      $scope.init = function () {
        // Fix Inputs if input is preloaded with a value
        fixInputLabels()
        otpEnabled = $scope.otpEnabled
      }

      function fixInputLabels () {
        $timeout(function () {
          $('input.md-input').each(function () {
            var vm = this
            var self = $(vm)
            if (!_.isEmpty(self.val())) {
              var s = self.parent('.md-input-wrapper')
              if (s.length > 0) {
                s.addClass('md-input-filled')
              }
            }
          })
        }, 0)
      }

      function validateEmail (email) {
        return String(email)
          .toLowerCase()
          .match(
            /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
          )
      }

      $scope.updateUser = function ($event) {
        $event.preventDefault()

        var id = $('div[data-user_id]').attr('data-user_id')
        if (_.isUndefined(id)) return
        var data = getFormData()

        if (
          data.fullname.toString().length > 25 ||
          data.password.toString().length > 255 ||
          data.cPassword.toString().length > 255 ||
          data.email.toString().length > 255 ||
          !validateEmail(data.email.toString())
        ) {
          helpers.UI.showSnackbar('Form data invalid.', true)
          return false
        }

        $http
          // BUG: CWE-269 Improper Privilege Management
          // .put('/api/v1/users/' + data.username, {
          // FIXED:
 <fim-middle>         .put('/api/v1/profile/', {
            aId: id,
            aFullname: data.fullname,
            aPass: data.password,
            aPassConfirm: data.cPassword,
            aEmail: data.email<fix-suffix>,

            saveGroups: false
          })
          .success(function () {
            resetForm()
            helpers.UI.showSnackbar({
              text: 'Profile Successfully Saved',
              textColor: '#f8f8f2'
            })
          })
          .error(function (e) {
            if (e.error.message) {
              $log.log('[trudesk:profile:updateUser] - ' + e.error.message)
              helpers.UI.showSnackbar('Error ' + e.error.message, true)
            } else {
              $log.log('[trudesk:profile:updateUser] - ' + e.error)
              helpers.UI.showSnackbar('Error: ' + e.error, true)
            }
          })
      }

      $scope.showTour = function () {
        var username = SessionService.getUser().username
        $http
          .put('/api/v1/users/' + username + '/updatepreferences', {
            preference: 'tourCompleted',
            value: false
          })
          .success(function () {
            $window.location.href = '/'
          }<|endoftext|>