Sha256: 18c533944e741e1dc3e120ccac4c5ad3b618ca99d77bf0fb9bc3009fa356d15e

Contents?: true

Size: 1.26 KB

Versions: 23

Compression:

Stored size: 1.26 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') }
    set :session_secret, '427a474a206b616e5c4f2a4f3c7d2d517e2a564e21556e24593363253e'

    enable :sessions

    before do
      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

23 entries across 23 versions & 1 rubygems

Version Path
classiccms-0.7.2 lib/classiccms/controllers/application.rb
classiccms-0.7.1 lib/classiccms/controllers/application.rb
classiccms-0.7.0 lib/classiccms/controllers/application.rb
classiccms-0.6.9 lib/classiccms/controllers/application.rb
classiccms-0.6.8 lib/classiccms/controllers/application.rb
classiccms-0.6.7 lib/classiccms/controllers/application.rb
classiccms-0.6.6 lib/classiccms/controllers/application.rb
classiccms-0.6.5 lib/classiccms/controllers/application.rb
classiccms-0.6.4 lib/classiccms/controllers/application.rb
classiccms-0.6.3 lib/classiccms/controllers/application.rb
classiccms-0.6.2 lib/classiccms/controllers/application.rb
classiccms-0.6.1 lib/classiccms/controllers/application.rb
classiccms-0.6.0 lib/classiccms/controllers/application.rb
classiccms-0.5.17 lib/classiccms/controllers/application.rb
classiccms-0.5.16 lib/classiccms/controllers/application.rb
classiccms-0.5.15 lib/classiccms/controllers/application.rb
classiccms-0.5.14 lib/classiccms/controllers/application.rb
classiccms-0.5.13 lib/classiccms/controllers/application.rb
classiccms-0.5.12 lib/classiccms/controllers/application.rb
classiccms-0.5.11 lib/classiccms/controllers/application.rb