<commit_before># homepage - login/signup
get '/' do
  if current_user.nil?
    erb :home
  else
    redirect '/nudges'
  end
end

post '/login' do
  @user = User.find_by_username(params[:username])
  if !@user.nil? && @user.password == params[:password]
    session[:user_id] = @user.id
    redirect '/nudges'
  else
    flash[:notice] = "Login failed. Please try again."
    redirect '/'
  end
end

post '/signup' do
  if params[:password] == params[:verify_password]
    @user = User.create({
      name: params[:name],
      username: params[:username],
      password: params[:password], 
      email: params[:email]
      })
  else
    flash[:notice] = "Incorrect password"
    redirect '/'
  end

  if @user.id.nil?
    flash[:notice] = "Username or email already taken"
    redirect '/'
  else
    session[:user_id] = @user.id
    redirect '/nudges'
  end
end

# Nudge form

get '/nudges' do
  @user = current_user
  erb :nudges
end

post '/nudges/create' do
  @user = current_user

  phone_num = '+1' + params[:phone_num]
  time = params[:hours] + ':' + params[:minutes] + ':00'
  datetime = params[:date] + " " + time

  nudge = Nudge.create!(receiver_name: params[:receiver_name], phone_num: phone_num, message: params[:message], datetime: datetime, user_id: @user["id"])

  redirect "/nudges/#{nudge.id}"
end

# thank you page 
get '/nudges/:id' do
  @nudge = Nudge.find(params[:id])

  erb :nudges_confirm
end

# all of a user's nudges - NOT WORKING on erb side

get '/user/:id/nudges' do
  @user = User.find(params[:id])
  @nudges = Nudge.find_by(user_id: params[:id]) 

  erb :profile
end

# logout
get '/logout' do
  session.clear<commit_msg>fixed profile route and display<commit_after># homepage - login/signup

get '/' do
  if current_user.nil?
    erb :home
  else
    redirect '/nudges'
  end
end

post '/login' do
  @user = User.find_by_username(params[:username])
  if !@user.nil? && @user.password == params[:password]
    session[:user_id] = @user.id
    redirect '/nudges'
  else
    flash[:notice] = "Login failed. Please try again."
    redirect '/'
  end
end

post '/signup' do
  if params[:password] == params[:verify_password]
    @user = User.create({
      name: params[:name],
      username: params[:username],
      password: params[:password], 
      email: params[:email]
      })
  else
    flash[:notice] = "Incorrect password"
    redirect '/'
  end

  if @user.id.nil?
    flash[:notice] = "Username or email already taken"
    redirect '/'
  else
    session[:user_id] = @user.id
    redirect '/nudges'
  end
end

# Nudge form

get '/nudges' do
  @user = current_user
  erb :nudges
end

post '/nudges/create' do
  @user = current_user

  phone_num = '+1' + params[:phone_num]
  time = params[:hours] + ':' + params[:minutes] + ':00'
  datetime = params[:date] + " " + time

  nudge = Nudge.create!(receiver_name: params[:receiver_name], phone_num: phone_num, message: params[:message], datetime: datetime, user_id: @user["id"])

  redirect "/nudges/#{nudge.id}"
end

# thank you page 

get '/nudges/:id' do
  @nudge = Nudge.find(params[:id])

  erb :nudges_confirm
end

# all of a user's nudges

get '/user/:id/nudges' do
  @user = User.find(params[:id])
  @nudges = Nudge.where(user_id: params[:id]) 

  erb :profile
end

# logout

get '/logout' do
  session.clear
{'fraction_non_alphanumeric': 0.15210160266102207, 'fraction_numerical': 0.0018143332325370426, 'mean_word_length': 3.3129074315514995, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7214173', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1182, 'n_words': 300}