Merge pull request #529 from ChrisBr/devise
Adds disabled flag to user and checks it if iChain is enabled
This commit is contained in:
commit
19dc918bc4
5 changed files with 27 additions and 5 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
|
||||||
|
|
|
||||||
|
|
@ -44,13 +44,13 @@
|
||||||
.dropdown-menu{:style => "padding: 17px;"}
|
.dropdown-menu{:style => "padding: 17px;"}
|
||||||
- if CONFIG['authentication']['ichain']['enabled']
|
- if CONFIG['authentication']['ichain']['enabled']
|
||||||
= form_tag User.ichain_login_url do
|
= form_tag User.ichain_login_url do
|
||||||
= text_field_tag 'username', nil, id: 'user_ichain_email_dd'
|
= text_field_tag 'username', nil, id: 'user_ichain_email_dd', placeholder: 'Username'
|
||||||
= password_field_tag 'password', nil, id: 'user_ichain_password_dd'
|
= password_field_tag 'password', nil, id: 'user_ichain_password_dd', placeholder: 'Password'
|
||||||
%button.btn.btn-success.btn-block Sign in
|
%button.btn.btn-success.btn-block Sign in
|
||||||
- else
|
- else
|
||||||
= form_tag new_user_session_path do
|
= form_tag new_user_session_path do
|
||||||
= text_field_tag 'user[login]', nil, id: 'user_login_dd'
|
= text_field_tag 'user[login]', nil, id: 'user_login_dd', placeholder: 'Username / E-Mail'
|
||||||
= password_field_tag 'user[password]', nil, id: 'user_password_dd'
|
= password_field_tag 'user[password]', nil, id: 'user_password_dd', placeholder: 'Password'
|
||||||
%p.text-right
|
%p.text-right
|
||||||
%small
|
%small
|
||||||
Remember me
|
Remember me
|
||||||
|
|
|
||||||
|
|
@ -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