<commit_before>class SessionController < ApplicationController

  helpers SessionHelpers

  get '/login' do
    if @current_user.nil?
      slim 'session/login'.to_sym
    else
      flash[:notice] = "You are already logged in"
      redirect "/"
    end
  end

  post '/login' do
    if @current_user.nil?
      @current_user = User.login params[:user]
      if @current_user.nil?
        flash[:error] = "Failed to login, check your username and password"
        redirect "/session/login"
      else
        session[:user_id] = @current_user.id
        flash[:notice] = "Login successful."
        redirect "/"
      end
    else
      flash[:notice] = "You are already logged in"
      redirect "/"
    end
  end

  get '/logout' do
    if @current_user.nil?
      flash[:error] = "You are not logged in"
      redirect "/"
    else
      session[:user_id] = nil
      flash[:notice] = "Logout successful"
      redirect "/"
    end
  end

  get '/register' do
    if @current_user.nil?
      slim 'session/register'.to_sym
    else
      flash[:notice] = "You are already logged in"
      redirect "/"
    end
  end

  post '/register' do
    begin
      u = params[:user].inject({}) { |memo,(k,v)| memo[k.to_sym] = v; memo }
      user = User.new u
      if user.save
        session[:user_id] = user.id
        flash[:notice] = 'Register successful'
        redirect '/'
      else
        str = ''
        user.errors.each do |k, v|
          next if k.nil?
          str += k + ';'
        end
        flash[:error] = str
        redirect '/session/register'
      end
    rescue Exception => e
      puts e
      flash[:error] = 'Failed to register account'
      redirect '/session/register'<commit_msg>Added project list redirects.<commit_after>class SessionController < ApplicationController

  helpers SessionHelpers

  get '/login' do
    if @current_user.nil?
      slim 'session/login'.to_sym
    else
      flash[:notice] = "You are already logged in"
      redirect "/project/list"
    end
  end

  post '/login' do
    if @current_user.nil?
      @current_user = User.login params[:user]
      if @current_user.nil?
        flash[:error] = "Failed to login, check your username and password"
        redirect "/session/login"
      else
        session[:user_id] = @current_user.id
        flash[:notice] = "Login successful."
        redirect "/project/list"
      end
    else
      flash[:notice] = "You are already logged in"
      redirect "/project/list"
    end
  end

  get '/logout' do
    if @current_user.nil?
      flash[:error] = "You are not logged in"
      redirect "/"
    else
      session[:user_id] = nil
      flash[:notice] = "Logout successful"
      redirect "/"
    end
  end

  get '/register' do
    if @current_user.nil?
      slim 'session/register'.to_sym
    else
      flash[:notice] = "You are already logged in"
      redirect "/project/list"
    end
  end

  post '/register' do
    begin
      u = params[:user].inject({}) { |memo,(k,v)| memo[k.to_sym] = v; memo }
      user = User.new u
      if user.save
        session[:user_id] = user.id
        flash[:notice] = 'Register successful'
        redirect '/project/list'
      else
        str = ''
        user.errors.each do |k, v|
          next if k.nil?
          str += k + ';'
        end
        flash[:error] = str
        redirect '/session/register'
      end
    rescue Exception => e
      puts e
      flash[:error] = 'Failed to register account'
      redirect '/session/register'
{'fraction_non_alphanumeric': 0.11529680365296803, 'fraction_numerical': 0.0, 'mean_word_length': 2.021551724137931, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3725100', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1055, 'n_words': 305}