Adds disabled flag to user and checks it if iChain is enabled
This commit is contained in:
parent
b95d35d5d9
commit
56cb805110
4 changed files with 23 additions and 1 deletions
|
|
@ -54,6 +54,14 @@ class ApplicationController < ActionController::Base
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rescue_from UserDisabled do
|
||||||
|
Rails.logger.debug('User is disabled!')
|
||||||
|
sign_out(current_user)
|
||||||
|
mail = User.admin.first ? User.admin.first.email : 'the admin!'
|
||||||
|
flash[:error] = "This User is disabled. Please contact #{mail}!"
|
||||||
|
redirect_to root_path
|
||||||
|
end
|
||||||
|
|
||||||
def not_found
|
def not_found
|
||||||
raise ActionController::RoutingError.new('Not Found')
|
raise ActionController::RoutingError.new('Not Found')
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
class IChainRecordNotFound < StandardError
|
class IChainRecordNotFound < StandardError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class UserDisabled < StandardError
|
||||||
|
end
|
||||||
|
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
rolify
|
rolify
|
||||||
include Gravtastic
|
include Gravtastic
|
||||||
|
|
@ -42,6 +45,8 @@ class User < ActiveRecord::Base
|
||||||
has_many :subscriptions, dependent: :destroy
|
has_many :subscriptions, dependent: :destroy
|
||||||
accepts_nested_attributes_for :roles
|
accepts_nested_attributes_for :roles
|
||||||
|
|
||||||
|
scope :admin, -> { where(is_admin: true) }
|
||||||
|
|
||||||
validates :email, presence: true
|
validates :email, presence: true
|
||||||
|
|
||||||
validates :username,
|
validates :username,
|
||||||
|
|
@ -59,6 +64,9 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
def self.for_ichain_username(username, attributes)
|
def self.for_ichain_username(username, attributes)
|
||||||
user = find_by(username: username)
|
user = find_by(username: username)
|
||||||
|
|
||||||
|
raise UserDisabled if user && user.is_disabled
|
||||||
|
|
||||||
if user
|
if user
|
||||||
user.update_attributes(email: attributes[:email])
|
user.update_attributes(email: attributes[:email])
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddIsDisabledFlagToUser < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :users, :is_disabled, :boolean, default: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141104131625) do
|
ActiveRecord::Schema.define(version: 20141106141750) do
|
||||||
|
|
||||||
create_table "ahoy_events", force: true do |t|
|
create_table "ahoy_events", force: true do |t|
|
||||||
t.uuid "visit_id"
|
t.uuid "visit_id"
|
||||||
|
|
@ -505,6 +505,7 @@ ActiveRecord::Schema.define(version: 20141104131625) do
|
||||||
t.text "volunteer_experience"
|
t.text "volunteer_experience"
|
||||||
t.boolean "is_admin", default: false
|
t.boolean "is_admin", default: false
|
||||||
t.string "username"
|
t.string "username"
|
||||||
|
t.boolean "is_disabled", default: false
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue