<commit_before>class AccountController < ApplicationController
  # model   :user

  def login
    case request.method
      when :post
        user = User.authenticate(params['user_login'], params['user_password'])
        if session['user'] = user
          logger.warn("%s, %s, %s" % [user.login, params['user_login'], params['user_password']])
          flash[:notice]  = "Login successful"
          user.last_login = Time.now
          user.save
          redirect_back_or_default :action => "welcome"
        else
          @login    = params['user_login']
          @message  = "Login unsuccessful"
      end
    end
  end

  def signup
    case request.method
      when :post
        theme = params['user']['theme']
        login = params['user']['login']
        valid_themes = CSS + ["NULL"]
        if valid_themes.member?(theme) and (login != 'test_denied')
          @user = User.new(params['user'])
          @user.created = Time.now
          @user.last_login = @user.created
          @user.change_rows(5)
          @user.change_columns(3)
          if @user.save
            session['user'] = User.authenticate(@user.login, params['user']['password'])
            flash[:notice]  = "Signup successful.  Verification sent to your email account."
            AccountMailer.deliver_verify(@user)
            redirect_back_or_default :action => "welcome"
          end
        else
          AccountMailer.deliver_denied(params['user'])
          redirect_back_or_default :action => "welcome"
        end
      when :get
        @user = User.new
    end
  end

  def email_new_password
    case request.method
      when :post
        login = params['user']['login']
        @user = User.find(:first, :conditions => ["login = ?", login])
        if @user.nil?
          flash[:notice] = sprintf("Unable to find the user, %s.", login)
        else
          password = <PASSWORD>(10)
          @user.change_password(password)
          if @user.save
            session['user'] = User.authenticate(@user.login, params['user']['password'])
            flash[:notice]  = "Password successfully changed.  New password has been sent to your email account."
            AccountMailer.deliver_new_password(@user, password)
          end
        end
        render :action => "login"
      when :get
        @user = User.new
    end
  end

  def prefs
    @user = session['user']
    case request.method
      when :post
        @user.change_email(params['user']['email'])
        @user.change_name(params['user']['name'])
        @user.html_email = params['user']['html_email']
        @user.feature_email = params['user']['feature_email']
        @user.comment_email = params['user']['comment_email']
        @user.commercial_email = params['user']['commercial_email']
        @user.question_email = params['user']['question_email']
        @user.change_theme(params['user']['theme'])
        @user.change_rows(params['user']['rows'])
        @user.change_columns(params['user']['columns'])
        @user.alternate_rows = params['user']['alternate_rows']
        @user.alternate_columns = params['user']['alternate_columns']
        @user.vertical_layout = params['user']['vertical_layout']
        @user.license_id = params['user']['license_id'].to_i
        password = params['user']['password']
        error = false
        if password
          if password == params['user']['password_confirmation']
            @user.change_password(password)
          else
            error = true
            flash[:notice] = "Password and confirmation did not match"
            render :action => "prefs"
          end
        end
        unless error
          if @user.save
            flash[:notice]  = "Preferences updated"
            redirect_back_or_default :action => "welcome"
          end
        end
      when :get
        unless @user.respond_to?(:license)
          @user = User.find(@user.id)
          session['user'] = @user
        end
        @licenses = License.current_names_and_ids(@user.license)
    end
  end

  def delete
    if params['id']
      @user = User.find(params['id'])
      @user.destroy
    end
    redirect_back_or_default :action => "welcome"
  end

  def logout_user
    session['user'] = nil
  end

  def welcome
  end

  def reverify
  end

  def verify
    if params['id']
      @user = User.find(params['id'])
      @user.verified = Time.now
      @user.save<commit_msg>Fixed user versioning issue<commit_after>class AccountController < ApplicationController
  # model   :user

  def login
    case request.method
      when :post
        user = User.authenticate(params['user_login'], params['user_password'])
        if session['user'] = user
          logger.warn("%s, %s, %s" % [user.login, params['user_login'], params['user_password']])
          flash[:notice]  = "Login successful"
          user.last_login = Time.now
          user.save
          redirect_back_or_default :action => "welcome"
        else
          @login    = params['user_login']
          @message  = "Login unsuccessful"
      end
    end
  end

  def signup
    case request.method
      when :post
        theme = params['user']['theme']
        login = params['user']['login']
        valid_themes = CSS + ["NULL"]
        if valid_themes.member?(theme) and (login != 'test_denied')
          @user = User.new(params['user'])
          @user.created = Time.now
          @user.last_login = @user.created
          @user.change_rows(5)
          @user.change_columns(3)
          if @user.save
            session['user'] = User.authenticate(@user.login, params['user']['password'])
            flash[:notice]  = "Signup successful.  Verification sent to your email account."
            AccountMailer.deliver_verify(@user)
            redirect_back_or_default :action => "welcome"
          end
        else
          AccountMailer.deliver_denied(params['user'])
          redirect_back_or_default :action => "welcome"
        end
      when :get
        @user = User.new
    end
  end

  def email_new_password
    case request.method
      when :post
        login = params['user']['login']
        @user = User.find(:first, :conditions => ["login = ?", login])
        if @user.nil?
          flash[:notice] = sprintf("Unable to find the user, %s.", login)
        else
          password = <PASSWORD>(10)
          @user.change_password(password)
          if @user.save
            session['user'] = User.authenticate(@user.login, params['user']['password'])
            flash[:notice]  = "Password successfully changed.  New password has been sent to your email account."
            AccountMailer.deliver_new_password(@user, password)
          end
        end
        render :action => "login"
      when :get
        @user = User.new
    end
  end

  def prefs
    @user = session['user']
    if @user
      case request.method
        when :post
          @user.change_email(params['user']['email'])
          @user.change_name(params['user']['name'])
          @user.html_email = params['user']['html_email']
          @user.feature_email = params['user']['feature_email']
          @user.comment_email = params['user']['comment_email']
          @user.commercial_email = params['user']['commercial_email']
          @user.question_email = params['user']['question_email']
          @user.change_theme(params['user']['theme'])
          @user.change_rows(params['user']['rows'])
          @user.change_columns(params['user']['columns'])
          @user.alternate_rows = params['user']['alternate_rows']
          @user.alternate_columns = params['user']['alternate_columns']
          @user.vertical_layout = params['user']['vertical_layout']
          @user.license_id = params['user']['license_id'].to_i
          password = params['user']['password']
          error = false
          if password
            if password == params['user']['password_confirmation']
              @user.change_password(password)
            else
              error = true
              flash[:notice] = "Password and confirmation did not match"
              render :action => "prefs"
            end
          end
          unless error
            if @user.save
              flash[:notice]  = "Preferences updated"
              redirect_back_or_default :action => "welcome"
            end
          end
        when :get
          @user = User.find(@user.id) # Make sure we have the latest version of the user
          session['user'] = @user
          @licenses = License.current_names_and_ids(@user.license)
      end
    else
      store_location
      redirect_to :action => 'login'
    end
  end

  def delete
    if params['id']
      @user = User.find(params['id'])
      @user.destroy
    end
    redirect_back_or_default :action => "welcome"
  end

  def logout_user
    session['user'] = nil
  end

  def welcome
  end

  def reverify
  end

  def verify
    if params['id']
      @user = User.find(params['id'])
      @user.verified = Time.now
      @user.save
{'fraction_non_alphanumeric': 0.12760995113282986, 'fraction_numerical': 0.000888494002665482, 'mean_word_length': 2.2392086330935252, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6523756', 'n_tokens_mistral': 2525, 'n_tokens_neox': 2492, 'n_words': 555}