Sha256: 32fecd5f37bab29f10031db097d24e32ab2108e5845cc9c3afd614b348525f7a
Contents?: true
Size: 1.41 KB
Versions: 13
Compression:
Stored size: 1.41 KB
Contents
%w(./app/models sinatra/base sinatra/flash entrance).each { |lib| require lib } module Example class Routes < Sinatra::Base include Entrance::Controller register Sinatra::Flash set :sessions, :secret => 'veryverysecretkey' set :views, File.expand_path(File.dirname(__FILE__)) + '/views' before do login_required :except => ['/login', '/signup'] end get '/' do erb :welcome end get '/signup' do erb :signup end post '/signup' do if @user = User.new(params[:user]) and @user.save flash[:success] = 'Signed up! Please log in now.' redirect to('/login') else flash[:error] = "Something's wrong. Try again." redirect to('/signup') end end get '/login' do if logged_in? redirect(to('/')) else erb :login end end post '/login' do if user = User.authenticate(params[:email], params[:password]) and user.active? remember = ['on', '1'].include?(params[:remember_me]) puts user.inspect login!(user, remember) flash[:success] = 'Welcome back!' redirect_to_stored_or to('/') else flash[:error] = "Couldn't log you in. Please try again." redirect to('/login') end end get '/logout' do logout! flash[:notice] = 'Logged out! See you soon.' redirect to('/login') end end end
Version data entries
13 entries across 13 versions & 1 rubygems