<commit_before>require 'haml'
require 'sinatra/base'

module Checkpoint
  module Sessions
    module Helpers
      def login_as(user)
        if user.nil?
          session.delete(:checkpoint_user_id)
        else
          session[:checkpoint_user_id] = user.id if user.email_confirmed
        end
      end

      def ensure_authenticated
        throw(:halt, [401, haml(:login_form)]) unless current_user
      end
    end
    
    class App < Sinatra::Base
      enable :sessions
      helpers Helpers
      helpers ::Checkpoint::Authentication
      
      set :views, File.dirname(__FILE__) + '/views'
      
      get '/sso/login' do
        ensure_authenticated
        redirect absolute_url("/")
      end
      
      post '/sso/login' do
        @user = ::Checkpoint::User.authenticate(params['email'], params['password'])
        login_as(@user)
        ensure_authenticated
        redirect absolute_url("/")
      end
      
      get '/sso/logout' do
        session.clear
        redirect absolute_url("/")
      end
      
    end
    
  end
end
    <commit_msg>Log out should redirect to login page.<commit_after>require 'haml'
require 'sinatra/base'

module Checkpoint
  module Sessions
    module Helpers
      def login_as(user)
        if user.nil?
          session.delete(:checkpoint_user_id)
        else
          session[:checkpoint_user_id] = user.id if user.email_confirmed
        end
      end

      def ensure_authenticated
        throw(:halt, [401, haml(:login_form)]) unless current_user
      end
    end
    
    class App < Sinatra::Base
      enable :sessions
      helpers Helpers
      helpers ::Checkpoint::Authentication
      
      set :views, File.dirname(__FILE__) + '/views'
      
      get '/sso/login' do
        ensure_authenticated
        redirect absolute_url("/")
      end
      
      post '/sso/login' do
        @user = ::Checkpoint::User.authenticate(params['email'], params['password'])
        login_as(@user)
        ensure_authenticated
        redirect absolute_url("/")
      end
      
      get '/sso/logout' do
        session.clear
        redirect absolute_url("/sso/login")
      end
      
    end
    
  end
end
    
{'fraction_non_alphanumeric': 0.09032846715328467, 'fraction_numerical': 0.002737226277372263, 'mean_word_length': 1.9675236806495264, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1044849', 'n_tokens_mistral': 647, 'n_tokens_neox': 628, 'n_words': 150}