Sha256: fed935f7cff436d492cad0d0e6b2b1e213ee9657d304cae34f5285e150dc7888
Contents?: true
Size: 1.18 KB
Versions: 6
Compression:
Stored size: 1.18 KB
Contents
require 'bcrypt' require 'base64' require_relative 'login_helper' module Teamster module Core class Login < Sinatra::Base @@referrer = nil @@root = Dir.pwd USERS_FILE = './data/users' configure do set :root, @@root set :views, "#{settings.root}/views" set :users, YAML.load_file("#{settings.root}/#{USERS_FILE}").fetch("users") set :referrer, nil end helpers GeneralHelper, LoginHelper get '/login/?' do referrer URI::parse(request.referrer) erb :login end post '/login' do if user = settings.users.find {|u| u['name'] == params[:user]} if BCrypt::Password.new(decode(user['pass'])) == params[:pass] session[:current_user] = user['name'] redirect_back else login_error end else login_error end end get '/logout/?' do referrer URI::parse(request.referrer) session[:current_user] = nil redirect_back end def self.referrer @@referrer end def self.set_referrer_to(path) @@referrer = path end end end end
Version data entries
6 entries across 6 versions & 1 rubygems