<commit_before>return function (loader)

  local I18n          = loader.load "cosy.i18n"
  local Scheduler     = loader.load "cosy.scheduler"
  local Webclient     = loader.load "cosy.webclient"

  local i18n = I18n.load {
    "cosy.webclient.profile",
    "cosy.webclient.authentication",
    "cosy.client",
  }
  i18n._locale = Webclient.window.navigator.language

  local Profile = {
    template = {},
  }
  Profile.__index = Profile
  Profile.template.show = Webclient.template "cosy.webclient.profile.show"
  Profile.template.edit = Webclient.template "cosy.webclient.profile.edit"

  local function check (info, t)
    Webclient.jQuery "#accept":addClass "disabled"
    local email        = Webclient.jQuery "#email":val ()
    local name         = Webclient.jQuery "#name":val ()
    local organization = Webclient.jQuery "#organization":val ()
    local homepage     = Webclient.jQuery "#homepage":val ()
    local password     = Webclient.jQuery "#password-1":val ()
    local result, err  = Webclient.client.user.update ({
      email        = email        ~= (info.email        or "") and email        or nil,
      avatar       = t.avatar                                  and t.avatar     or nil,
      name         = name         ~= (info.name         or "") and name         or nil,
      organization = organization ~= (info.organization or "") and organization or nil,
      homepage     = homepage     ~= (info.homepage     or "") and homepage     or nil,
      password     = password     ~= ""                        and password     or nil,
      position     = t.position                                and t.position   or nil,
      locale       = Webclient.locale,
    }, {
      try_only = true,
    })
    for _, x in ipairs { "avatar", "name", "organization", "email", "homepage", "position" } do
      Webclient.jQuery ("#" .. x .. "-group"):removeClass "has-error"
      Webclient.jQuery ("#" .. x .. "-error"):html ""
      if  Webclient.jQuery ("#" .. x):val () ~= info [x] then
        Webclient.jQuery ("#" .. x .. "-group"):addClass "has-success"
      end
    end
    for _, x in ipairs { "password-1", "password-2" } do
      Webclient.jQuery ("#" .. x .. "-group"):removeClass "has-error"
      Webclient.jQuery ("#" .. x .. "-error"):html ""
      if  Webclient.jQuery ("#" .. x):val () ~= "" then
        Webclient.jQuery ("#" .. x .. "-group"):addClass "has-success"
      end
    end
    if t.position then
      Webclient.jQuery "#position-group":addClass "has-success"
    end
    local passwords = {
      Webclient.jQuery "#password-1":val (),
      Webclient.jQuery "#password-2":val (),
    }
    if passwords [1] ~= passwords [2] then
      Webclient.jQuery "#password-group":addClass "has-error"
      local text = i18n ["argument:password:nomatch"] % {}
      Webclient.jQuery "#password-error":html (text)
      result = false
    end
    if result then
      Webclient.jQuery "#accept":removeClass "disabled"
      return true
    elseif err then
      for _, reason in ipairs (err.reasons or {}) do
        Webclient.jQuery ("#" .. reason.key .. "-group"):addClass "has-error"
        Webclient.jQuery ("#" .. reason.key .. "-error"):html (reason.message)
      end
      return false
    end
  end

  function Profile.__call (options)
    Webclient (function ()
      local co   = Scheduler.running ()
      local user = Webclient.client.user.authentified_as {}
      options.username = options.username or user.identifier
      if user and options.username == user.identifier then
        local t = {
          username = options.username or user.identifier,
          position = nil,
          avatar   = nil,
        }
        local info = Webclient.client.user.update {}
        info ["avatar-full"] = info.avatar.full
        Webclient.show {
          where    = "main",
          template = Profile.template.edit,
          data     = info,
          i18n     = i18n,<commit_msg>Do not try to access avatar if it does not exist.<commit_after>return function (loader)

  local I18n          = loader.load "cosy.i18n"
  local Scheduler     = loader.load "cosy.scheduler"
  local Webclient     = loader.load "cosy.webclient"

  local i18n = I18n.load {
    "cosy.webclient.profile",
    "cosy.webclient.authentication",
    "cosy.client",
  }
  i18n._locale = Webclient.window.navigator.language

  local Profile = {
    template = {},
  }
  Profile.__index = Profile
  Profile.template.show = Webclient.template "cosy.webclient.profile.show"
  Profile.template.edit = Webclient.template "cosy.webclient.profile.edit"

  local function check (info, t)
    Webclient.jQuery "#accept":addClass "disabled"
    local email        = Webclient.jQuery "#email":val ()
    local name         = Webclient.jQuery "#name":val ()
    local organization = Webclient.jQuery "#organization":val ()
    local homepage     = Webclient.jQuery "#homepage":val ()
    local password     = Webclient.jQuery "#password-1":val ()
    local result, err  = Webclient.client.user.update ({
      email        = email        ~= (info.email        or "") and email        or nil,
      avatar       = t.avatar                                  and t.avatar     or nil,
      name         = name         ~= (info.name         or "") and name         or nil,
      organization = organization ~= (info.organization or "") and organization or nil,
      homepage     = homepage     ~= (info.homepage     or "") and homepage     or nil,
      password     = password     ~= ""                        and password     or nil,
      position     = t.position                                and t.position   or nil,
      locale       = Webclient.locale,
    }, {
      try_only = true,
    })
    for _, x in ipairs { "avatar", "name", "organization", "email", "homepage", "position" } do
      Webclient.jQuery ("#" .. x .. "-group"):removeClass "has-error"
      Webclient.jQuery ("#" .. x .. "-error"):html ""
      if  Webclient.jQuery ("#" .. x):val () ~= info [x] then
        Webclient.jQuery ("#" .. x .. "-group"):addClass "has-success"
      end
    end
    for _, x in ipairs { "password-1", "password-2" } do
      Webclient.jQuery ("#" .. x .. "-group"):removeClass "has-error"
      Webclient.jQuery ("#" .. x .. "-error"):html ""
      if  Webclient.jQuery ("#" .. x):val () ~= "" then
        Webclient.jQuery ("#" .. x .. "-group"):addClass "has-success"
      end
    end
    if t.position then
      Webclient.jQuery "#position-group":addClass "has-success"
    end
    local passwords = {
      Webclient.jQuery "#password-1":val (),
      Webclient.jQuery "#password-2":val (),
    }
    if passwords [1] ~= passwords [2] then
      Webclient.jQuery "#password-group":addClass "has-error"
      local text = i18n ["argument:password:nomatch"] % {}
      Webclient.jQuery "#password-error":html (text)
      result = false
    end
    if result then
      Webclient.jQuery "#accept":removeClass "disabled"
      return true
    elseif err then
      for _, reason in ipairs (err.reasons or {}) do
        Webclient.jQuery ("#" .. reason.key .. "-group"):addClass "has-error"
        Webclient.jQuery ("#" .. reason.key .. "-error"):html (reason.message)
      end
      return false
    end
  end

  function Profile.__call (options)
    Webclient (function ()
      local co   = Scheduler.running ()
      local user = Webclient.client.user.authentified_as {}
      options.username = options.username or user.identifier
      if user and options.username == user.identifier then
        local t = {
          username = options.username or user.identifier,
          position = nil,
          avatar   = nil,
        }
        local info = Webclient.client.user.update {}
        info ["avatar-full"] = info.avatar and info.avatar.full or nil
        Webclient.show {
          where    = "main",
          template = Profile.template.edit,
          data     = info,
          i18n     = i18n,
{'fraction_non_alphanumeric': 0.13251039173699458, 'fraction_numerical': 0.005794180627283033, 'mean_word_length': 2.0597302504816954, 'pattern_counts': {'":': 24, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1063232', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2279, 'n_words': 579}