BigW Consortium Gitlab

profiles_controller.rb 1.94 KB
Newer Older
1
class ProfilesController < Profiles::ApplicationController
2 3
  include ActionView::Helpers::SanitizeHelper

4 5 6
  before_action :user
  before_action :authorize_change_username!, only: :update_username
  skip_before_action :require_email, only: [:show, :update]
7

gitlabhq committed
8 9 10
  def show
  end

11
  def update
12
    user_params.except!(:email) if @user.ldap_user?
13

14
    respond_to do |format|
15 16 17 18 19 20 21 22 23
      if @user.update_attributes(user_params)
        message = "Profile was successfully updated"
        format.html { redirect_back_or_default(default: { action: 'show' }, options: { notice: message }) }
        format.json { render json: { message: message } }
      else
        message = @user.errors.full_messages.uniq.join('. ')
        format.html { redirect_back_or_default(default: { action: 'show' }, options: { alert: "Failed to update profile. #{message}" }) }
        format.json { render json: { message: message }, status: :unprocessable_entity }
      end
24
    end
25 26
  end

27
  def reset_private_token
28 29 30 31
    if current_user.reset_authentication_token!
      flash[:notice] = "Token was successfully updated"
    end

32
    redirect_to profile_account_path
33
  end
34

35 36 37
  def audit_log
    @events = AuditEvent.where(entity_type: "User", entity_id: current_user.id).
      order("created_at DESC").
38
      page(params[:page])
39 40
  end

41
  def update_username
42
    @user.update_attributes(username: user_params[:username])
43 44 45 46 47 48

    respond_to do |format|
      format.js
    end
  end

49
  private
50 51 52 53

  def user
    @user = current_user
  end
54

55 56 57
  def authorize_change_username!
    return render_404 unless @user.can_change_username?
  end
58 59 60

  def user_params
    params.require(:user).permit(
61 62 63 64 65
      :avatar,
      :bio,
      :email,
      :hide_no_password,
      :hide_no_ssh_key,
66
      :hide_project_limit,
67 68 69 70 71 72 73 74 75
      :linkedin,
      :location,
      :name,
      :password,
      :password_confirmation,
      :public_email,
      :skype,
      :twitter,
      :username,
76 77
      :website_url,
      :organization
78 79
    )
  end
gitlabhq committed
80
end