Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- helpers do
- def current_user
- User.find_by(id: session[:user_id])
- end
- end
- post '/login' do
- username = params[:username]
- password = params[:password]
- user = User.find_by(username: username)
- if user && user.password == password
- session[:user_id] = user.id
- redirect to('/')
- else
- @error_message = "Login failed."
- erb(:login)
- end
- end
- get '/logout' do
- session[:user_id] = nil
- "Logout successful!"
- redirect to('/')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement