<commit_before>class UsersController < ApplicationController
  before_filter :login_required, :only => [:edit, :update, :follow]
  tabs :default => :users
  def index
    set_page_title(t("users.index.title"))
    @users = current_group.users(:per_page => params[:per_page]||24,
                                 :order => "membership_list.#{current_group.id}.reputation desc",
                                 :page => params[:page] || 1)

    respond_to do |format|
      format.html
      format.json {
        except = [:password, :password_confirmation, :crypted_password,
                  :encrypted_password, :password_salt, :salt, :email, :identity_url,
                  :default_subtab, :ip, :language_filter ]
        render :json => @users.to_json(:except => except)
      }
    end

  end

  # render new.rhtml
  def new
    @user = User.new
  end

  def create
    @user = User.new
    @user.safe_update(%w[login email name password_confirmation password
                         language timezone identity_url bio hide_country], params[:user])
    success = @user && @user.save
    if success && @user.errors.empty?
      # Protects against session fixation attacks, causes request forgery
      # protection if visitor resubmits an earlier form using back
      # button. Uncomment if you understand the tradeoffs.
      # reset session
      @user.localize(request.remote_ip)
      flash[:notice] = t("flash_notice", :scope => "users.create")
      sign_in_and_redirect(:user, @user) # !! now logged in
    else
      flash[:error]  = t("flash_error", :scope => "users.create")
      render :action => 'new'
    end
  end

  def show
    @user = User.find_by_login_or_id(params[:id])
    raise PageNotFound unless @user
    @questions = @user.questions.paginate(:page=>params[:questions_page],
                                          :per_page => 10,
                                          :group_id => current_group.id,
                                          :banned => false)
    @answers = @user.answers.paginate(:page=>params[:answers_page],
                                      :group_id => current_group.id,
                                      :per_page => 10,
                                      :banned => false)

    @badges = @user.badges.paginate(:page => params[:badges_page],
                                    :group_id => current_group.id,
                                    :per_page => 25)

    @favorites = @user.favorites.paginate(:page => params[:favorites_page],
                                          :per_page => 25,
                                          :group_id => current_group.id)

    @favorite_questions = Question.find(@favorites.map{|f| f.question_id })

    add_feeds_url(url_for(:format => "atom"), t("feeds.user"))

    @user.viewed_on!(current_group) if @user != current_user && !is_bot?

    respond_to do |format|
      format.html
      format.atom
      format.json {
        except = [:password, :password_confirmation, :crypted_password,
                  :encrypted_password, :password_salt, :salt, :email, :identity_url,
                  :default_subtab, :ip, :language_filter ]
        render :json => @user.to_json(:except => except)
      }
    end
  end

  def edit
    @user = current_user
  end

  def update
    if params[:id] == 'login' && params[:user].nil? # HACK for facebook-connectable
      redirect_to root_path
      return
    end

    @user = current_user

    if params[:current_password] && User.authenticate(@user.login, params[:current_password])
      @user.encrypted_password = ""
      @user.password = params[:user][:password]
      @user.password_confirmation = params[:user][:password_confirmation]
    end

    @user.safe_update(%w[login email name password_confirmation password
                         language timezone preferred_languages
                         notification_opts bio hide_country], params[:user])
    preferred_tags = params[:user][:preferred_tags]
    if @user.valid? && @user.save
      @user.add_preferred_tags(preferred_tags, current_group) if preferred_tags
      redirect_to root_path
    else
      render :action => "edit"
    end
  end

  def change_preferred_tags
    @user = current_user
    if params[:tags]
      if params[:opt] == "add"
        @user.add_preferred_tags(params[:tags], current_group) if params[:tags]
      elsif params[:opt] == "remove"<commit_msg>Fix changing password<commit_after>class UsersController < ApplicationController
  before_filter :login_required, :only => [:edit, :update, :follow]
  tabs :default => :users
  def index
    set_page_title(t("users.index.title"))
    @users = current_group.users(:per_page => params[:per_page]||24,
                                 :order => "membership_list.#{current_group.id}.reputation desc",
                                 :page => params[:page] || 1)

    respond_to do |format|
      format.html
      format.json {
        except = [:password, :password_confirmation, :crypted_password,
                  :encrypted_password, :password_salt, :salt, :email, :identity_url,
                  :default_subtab, :ip, :language_filter ]
        render :json => @users.to_json(:except => except)
      }
    end

  end

  # render new.rhtml
  def new
    @user = User.new
  end

  def create
    @user = User.new
    @user.safe_update(%w[login email name password_confirmation password
                         language timezone identity_url bio hide_country], params[:user])
    success = @user && @user.save
    if success && @user.errors.empty?
      # Protects against session fixation attacks, causes request forgery
      # protection if visitor resubmits an earlier form using back
      # button. Uncomment if you understand the tradeoffs.
      # reset session
      @user.localize(request.remote_ip)
      flash[:notice] = t("flash_notice", :scope => "users.create")
      sign_in_and_redirect(:user, @user) # !! now logged in
    else
      flash[:error]  = t("flash_error", :scope => "users.create")
      render :action => 'new'
    end
  end

  def show
    @user = User.find_by_login_or_id(params[:id])
    raise PageNotFound unless @user
    @questions = @user.questions.paginate(:page=>params[:questions_page],
                                          :per_page => 10,
                                          :group_id => current_group.id,
                                          :banned => false)
    @answers = @user.answers.paginate(:page=>params[:answers_page],
                                      :group_id => current_group.id,
                                      :per_page => 10,
                                      :banned => false)

    @badges = @user.badges.paginate(:page => params[:badges_page],
                                    :group_id => current_group.id,
                                    :per_page => 25)

    @favorites = @user.favorites.paginate(:page => params[:favorites_page],
                                          :per_page => 25,
                                          :group_id => current_group.id)

    @favorite_questions = Question.find(@favorites.map{|f| f.question_id })

    add_feeds_url(url_for(:format => "atom"), t("feeds.user"))

    @user.viewed_on!(current_group) if @user != current_user && !is_bot?

    respond_to do |format|
      format.html
      format.atom
      format.json {
        except = [:password, :password_confirmation, :crypted_password,
                  :encrypted_password, :password_salt, :salt, :email, :identity_url,
                  :default_subtab, :ip, :language_filter ]
        render :json => @user.to_json(:except => except)
      }
    end
  end

  def edit
    @user = current_user
  end

  def update
    if params[:id] == 'login' && params[:user].nil? # HACK for facebook-connectable
      redirect_to root_path
      return
    end

    @user = current_user

    if params[:current_password] && @user.valid_password?(params[:current_password])
      @user.encrypted_password = ""
      @user.password = params[:user][:password]
      @user.password_confirmation = params[:user][:password_confirmation]
    end

    @user.safe_update(%w[login email name language timezone preferred_languages
                         notification_opts bio hide_country], params[:user])
    preferred_tags = params[:user][:preferred_tags]
    if @user.valid? && @user.save
      @user.add_preferred_tags(preferred_tags, current_group) if preferred_tags
      redirect_to root_path
    else
      render :action => "edit"
    end
  end

  def change_preferred_tags
    @user = current_user
    if params[:tags]
      if params[:opt] == "add"
        @user.add_preferred_tags(params[:tags], current_group) if params[:tags]
      elsif params[:opt] == "remove"
{'fraction_non_alphanumeric': 0.11273224666590675, 'fraction_numerical': 0.0025076940613245184, 'mean_word_length': 2.176683562635771, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4992855', 'n_tokens_mistral': 2554, 'n_tokens_neox': 2444, 'n_words': 536}