Created
June 20, 2020 21:27
-
-
Save lushiyun/3da006a64cf26b2593ea05f30233105a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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