Sha256: 887a8fcbb2743efa73f24f40aa01381bb190927b3e1504044d4a71e0d918d7d7

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

require 'haml'
require 'sinatra/base'
require 'sinatra/support'

module Classiccms
  class ApplicationController < Sinatra::Base
    include  Classiccms::Routing
    register Sinatra::MultiRender
    register Sinatra::DateForms
    helpers Sinatra::HtmlHelpers
    helpers  Classiccms::Helpers
    
    
    set :multi_views,   [ File.join(Dir.pwd, 'views')]
    set :root, Dir.pwd
    set :public_folder, Proc.new { File.join(Dir.pwd, 'public') }
    
    #enable :sessions
    use Rack::Session::Cookie, :key => 'rack.session', :path => '/', :secret => '427a474a206b616e5c4f2a4f3c7d2d517e2a564e21556e24593363253e'
    before do
      p session
      
      if User.where(:_id => session[:user_id]).count > 0
        @user = User.find(session[:user_id]) if session[:user_id] != nil
      else
        session[:user_id] = nil
      end
    end

    get '/login' do
      show :login, views: File.join(Classiccms::ROOT, 'views/cms')
    end
    post '/login' do
      user = User.where(:username => params[:username], :password => params[:password]).first
      if user != nil
        session[:user_id] = user.id
        redirect to(params[:correct] != nil ? params[:correct] : '/')
      else
        redirect to(params[:incorrect] != nil ? params[:incorrect] : '/login')
      end
    end
    get '/logout' do
      session[:user_id] = nil
      redirect '/'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
classiccms-0.7.5 lib/classiccms/controllers/application.rb
classiccms-0.7.4 lib/classiccms/controllers/application.rb
classiccms-0.7.3 lib/classiccms/controllers/application.rb