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

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4
  before_filter :user
5
  before_filter :authorize_change_username!, only: :update_username
6
  skip_before_filter :require_email, only: [:show, :update]
7

8
  layout 'profile'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
9

gitlabhq's avatar
gitlabhq committed
10 11 12
  def show
  end

13 14 15
  def design
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
16 17 18 19 20
  def applications
    @applications = current_user.oauth_applications
    @authorized_tokens = current_user.oauth_authorized_tokens
  end

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

24
    if @user.update_attributes(user_params)
25 26 27 28
      flash[:notice] = "Profile was successfully updated"
    else
      flash[:alert] = "Failed to update profile"
    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
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
43

44 45 46 47
  def history
    @events = current_user.recent_events.page(params[:page]).per(20)
  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
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
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 68 69 70 71 72

  def user_params
    params.require(:user).permit(
      :email, :password, :password_confirmation, :bio, :name, :username,
      :skype, :linkedin, :twitter, :website_url, :color_scheme_id, :theme_id,
      :avatar, :hide_no_ssh_key,
    )
  end
gitlabhq's avatar
gitlabhq committed
73
end