<commit_before>require 'sinatra'
require 'erb'
require 'oauth2'
require 'byebug'
require 'dotenv'
require 'haml'
require 'sequel'
require 'time'
require "sinatra/reloader" if development?
require "httparty"
require 'json'
require 'sinatra/flash'
require 'sinatra/json'

require_relative "lib/login_helper"
require_relative 'lib/view_helper'
require_relative './services/elastic_search/mesh_block_query'
require_relative './services/claim_service'
require_relative './models/feature_collection'
require_relative "models/user"
require_relative "models/electorate"

Dotenv.load
enable :sessions

def test_db_connection
  Sequel.connect(ENV['SNAP_DB_PG_URL'] || "postgres://localhost/walklist_test")
end

configure do
  db = Sequel.connect('postgres://localhost/walklist')
  set :db, db
end

configure :production do
  db = Sequel.connect(ENV['DATABASE_URL'])
  set :db, db
end

configure :test do
  set :db, test_db_connection
end

Sequel.datetime_class = DateTime

get '/' do
  if authorised?
    redirect '/map'
  else
    haml :main, locals: {body: 'main'}
  end
end

get '/login' do
  redirect '/'
end

post '/login' do
  email = params[:email].strip
  user = User.new(settings.db)
  if user.where(email: email).any?
    authorise(email)
    redirect "/map"
  else
    redirect "/user_details?email=#{email}"
  end
end

get "/user_details" do
  haml :user_details, locals: { email: params[:email] }
end

post "/user_details" do
  user = User.new(settings.db)
  if user.create!(params[:user_details])
    authorise(email)
    redirect "/map"
  else
    # TODO needs validation
    flash[:error] = "Please enter correct details."
    haml :user_details
  end
end

get '/map' do
  authorised do
    haml :map, :layout => false
  end
end

get '/logout' do
  session.clear
  flash[:notice] = 'You have been logged out.'
  redirect '/'
end
<commit_msg>Fixes user signup process failing<commit_after>require 'sinatra'
require 'erb'
require 'oauth2'
require 'byebug'
require 'dotenv'
require 'haml'
require 'sequel'
require 'time'
require "sinatra/reloader" if development?
require "httparty"
require 'json'
require 'sinatra/flash'
require 'sinatra/json'

require_relative "lib/login_helper"
require_relative 'lib/view_helper'
require_relative './services/elastic_search/mesh_block_query'
require_relative './services/claim_service'
require_relative './models/feature_collection'
require_relative "models/user"
require_relative "models/electorate"

Dotenv.load
enable :sessions

def test_db_connection
  Sequel.connect(ENV['SNAP_DB_PG_URL'] || "postgres://localhost/walklist_test")
end

configure do
  db = Sequel.connect('postgres://localhost/walklist')
  set :db, db
end

configure :production do
  db = Sequel.connect(ENV['DATABASE_URL'])
  set :db, db
end

configure :test do
  set :db, test_db_connection
end

Sequel.datetime_class = DateTime

get '/' do
  if authorised?
    redirect '/map'
  else
    haml :main, locals: {body: 'main'}
  end
end

get '/login' do
  redirect '/'
end

post '/login' do
  email = params[:email].strip
  user = User.new(settings.db)
  if user.where(email: email).any?
    authorise(email)
    redirect "/map"
  else
    redirect "/user_details?email=#{email}"
  end
end

get "/user_details" do
  haml :user_details, locals: { email: params[:email] }
end

post "/user_details" do
  user = User.new(settings.db)
  if user.create!(params[:user_details])
    authorise(params[:user_details]['email'])
    redirect "/map"
  else
    # TODO needs validation
    flash[:error] = "Please enter correct details."
    haml :user_details
  end
end

get '/map' do
  authorised do
    haml :map, :layout => false
  end
end

get '/logout' do
  session.clear
  flash[:notice] = 'You have been logged out.'
  redirect '/'
end

{'fraction_non_alphanumeric': 0.12062048676116609, 'fraction_numerical': 0.0005349023803155924, 'mean_word_length': 4.396825396825397, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5838248', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1258, 'n_words': 340}