Sha256: b426d4a82a3aed098fab8bd889e60f78a9a219fc9aeec65a8956eb1b6ab3367f
Contents?: true
Size: 1.27 KB
Versions: 3
Compression:
Stored size: 1.27 KB
Contents
require 'entrance' module Entrance module Sinatra def self.registered(app) app.send(:include, ::Entrance::Controller) app.get '/login' do if logged_in? redirect(to('/')) else erb :'public/login' end end app.post '/login' do remember = ['on', 'true', '1'].include?(params[:remember]) if user = authenticate_and_login(params[:username], params[:password], remember) flash[:success] = 'Welcome back!' redirect_to_stored_or(to('/')) else redirect_with('/login', :error, "Couldn't log you in. Please try again.") end end app.get '/logout' do logout! redirect_with('/login', :notice, 'Logged out! See you soon.') end app.get '/signup' do return redirect(to('/')) if logged_in? @user = ::Entrance.model.new erb :'public/signup' end app.post '/signup' do @user = ::Entrance.model.new(params[:user]) if @user.valid? && @user.save redirect_with('/login', :success, "Account created! Please sign in to continue.") else flash[:error] = "Couldn't sign you up. Please try again." erb :'public/signup' end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
entrance-0.4.1 | lib/entrance/addons/sinatra.rb |
entrance-0.4.0 | lib/entrance/addons/sinatra.rb |
entrance-0.3.4 | lib/entrance/addons/sinatra.rb |