Sha256: 35a36f0a4a3a1f68f6eb45173fba739d29af587118231746e7550fa659b69358
Contents?: true
Size: 1.08 KB
Versions: 2
Compression:
Stored size: 1.08 KB
Contents
require 'digest/sha2' class Admin::AuthController < Admin::AdminController skip_before_filter :is_admin?, :only => [:login, :authorize] def login unless session[:admin].nil? redirect_to admin_path end end def authorize login = params[:login] password = params[:password] #open file f = File.open(Rails.root + "config/admin.yml", "r") admins = YAML::load f.read f.close #find admin = admins.find {|admin| admin[:id] == login} unless admin.nil? #match password if admin[:password_hash] == Digest::SHA512.hexdigest(password + admin[:password_salt]) # login succeeded flash[:success] = "Login Succeeded." init_session(login) redirect_to admin_path else flash[:error] = "Password incorrect." redirect_to admin_login_path end else flash[:error] = "Admin \"#{login}\" doesn't exist" redirect_to admin_login_path end end def logout flash[:success] = "Logout Succeeded." session[:user_id] = nil reset_session redirect_to admin_path end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
drh_admin-0.0.4 | lib/generators/admin/templates/app/controllers/admin/auth_controller.rb |
drh_admin-0.0.3 | lib/generators/admin/templates/app/controllers/admin/auth_controller.rb |