<commit_before>import template from './auth-init.html';

export const authInit = {
  template,
  controller: class AuthInitController {
    constructor(usersService, $state, ENV, ncUtilsFlash) {
      // @ngInject
      this.usersService = usersService;
      this.$state = $state;
      this.ncUtilsFlash = ncUtilsFlash,
      this.user = {};
      this.pageTitle = ENV.shortPageTitle;
    }

    $onInit() {
      this.loading = true;
      this.usersService.getCurrentUser().then(user => {
        this.user = user;
      }).finally(() => {
        this.loading = false;
      });
    }

    save({ user }) {
      return this.usersService.update(user).then(response => {
        this.usersService.currentUser = response.data;
        this.$state.go('profile.details');
      }).catch(response => {
        this.ncUtilsFlash.error('Unable to save user');
        if (response.status === 400) {
          this.errors = response.data;
        }<commit_msg>Copy user before update (WAl-383)<commit_after>import template from './auth-init.html';

export const authInit = {
  template,
  controller: class AuthInitController {
    constructor(usersService, $state, ENV, ncUtilsFlash) {
      // @ngInject
      this.usersService = usersService;
      this.$state = $state;
      this.ncUtilsFlash = ncUtilsFlash,
      this.user = {};
      this.pageTitle = ENV.shortPageTitle;
    }

    $onInit() {
      this.loading = true;
      this.usersService.getCurrentUser().then(user => {
        this.user = angular.copy(user);
      }).finally(() => {
        this.loading = false;
      });
    }

    save({ user }) {
      return this.usersService.update(user).then(response => {
        this.usersService.currentUser = response.data;
        this.$state.go('profile.details');
      }).catch(response => {
        this.ncUtilsFlash.error('Unable to save user');
        if (response.status === 400) {
          this.errors = response.data;
        }
{'fraction_non_alphanumeric': 0.14168377823408623, 'fraction_numerical': 0.004620123203285421, 'mean_word_length': 2.413309982486865, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5615514', 'n_tokens_mistral': 588, 'n_tokens_neox': 569, 'n_words': 106}