Skip to content

Instantly share code, notes, and snippets.

@MilanGrubnic70
Last active August 29, 2015 14:02
Show Gist options
  • Save MilanGrubnic70/1ae53e1d566ad9872e41 to your computer and use it in GitHub Desktop.
Save MilanGrubnic70/1ae53e1d566ad9872e41 to your computer and use it in GitHub Desktop.
Controller File
get '/' do
# Look in app/views/index.erb
erb :index
end
get '/signin' do
user = User.authenticate(params[:email], params[:password])
if user
session[:user_id] = user.id
redirect /"secure_area"
else
@errors = "Your signin and/or password are incorrect."
erb: :signin
end
end
get '/logout' do
session[:user_id] = nil use this
# session.delete(:user_id) or use this
# sesson.clear clears the all data including shopping cart
end
get '/secure_area' do
if session[:user_id]
erb: secure_things
else
redirect to '/signin'
end
end
get '/secure_area' do
if current_user
erb: secure_things
else
redirect '/'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment