BigW Consortium Gitlab

profiles_controller.rb 1.74 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 12 13
  def design
  end

14 15 16
  def applications
    @applications = current_user.oauth_applications
    @authorized_tokens = current_user.oauth_authorized_tokens
17
    @authorized_apps = @authorized_tokens.map(&:application).uniq
18 19
  end

20
  def update
21
    user_params.except!(:email) if @user.ldap_user?
22

23
    if @user.update_attributes(user_params)
24 25
      flash[:notice] = "Profile was successfully updated"
    else
26 27
      messages = @user.errors.full_messages.uniq.join('. ')
      flash[:alert] = "Failed to update profile. #{messages}"
28
    end
29 30 31 32 33

    respond_to do |format|
      format.html { redirect_to :back }
      format.js
    end
34 35
  end

36
  def reset_private_token
37 38 39 40
    if current_user.reset_authentication_token!
      flash[:notice] = "Token was successfully updated"
    end

41
    redirect_to profile_account_path
42
  end
43

44
  def history
45
    @events = current_user.recent_events.page(params[:page]).per(PER_PAGE)
46 47
  end

48
  def update_username
49
    @user.update_attributes(username: user_params[:username])
50 51 52 53 54 55

    respond_to do |format|
      format.js
    end
  end

56
  private
57 58 59 60

  def user
    @user = current_user
  end
61

62 63 64
  def authorize_change_username!
    return render_404 unless @user.can_change_username?
  end
65 66 67

  def user_params
    params.require(:user).permit(
68 69 70 71
      :email, :password, :password_confirmation, :bio, :name,
      :username, :skype, :linkedin, :twitter, :website_url,
      :color_scheme_id, :theme_id, :avatar, :hide_no_ssh_key,
      :hide_no_password, :location, :public_email
72 73
    )
  end
gitlabhq committed
74
end