Skip to content

Instantly share code, notes, and snippets.

@lushiyun
Created June 20, 2020 21:27
Show Gist options
  • Save lushiyun/3da006a64cf26b2593ea05f30233105a to your computer and use it in GitHub Desktop.
Save lushiyun/3da006a64cf26b2593ea05f30233105a to your computer and use it in GitHub Desktop.
post '/login' do
sanitize_input(params)
user = User.find_by(email: params[:email])
if user && user.authenticate(params[:password])
session[:user_id] = user.id
redirect to "/courses"
else
flash[:alerts] = ["Wrong email or password. Please try again."]
redirect to "/login"
end
end
post '/signup' do
sanitize_input(params)
user = User.new(params)
if user.save
session[:user_id] = user.id
redirect to "/courses"
else
flash[:alerts] = user.errors.full_messages
redirect to "/signup"
end
end
get '/logout' do
session.clear
redirect to "/"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment