Merge pull request #529 from ChrisBr/devise

Adds disabled flag to user and checks it if iChain is enabled
This commit is contained in:
Henne Vogelsang 2014-11-06 16:57:52 +01:00
commit 19dc918bc4
5 changed files with 27 additions and 5 deletions

View file

@ -54,6 +54,14 @@ class ApplicationController < ActionController::Base
redirect_to root_path
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
raise ActionController::RoutingError.new('Not Found')
end

View file

@ -1,6 +1,9 @@
class IChainRecordNotFound < StandardError
end
class UserDisabled < StandardError
end
class User < ActiveRecord::Base
rolify
include Gravtastic
@ -42,6 +45,8 @@ class User < ActiveRecord::Base
has_many :subscriptions, dependent: :destroy
accepts_nested_attributes_for :roles
scope :admin, -> { where(is_admin: true) }
validates :email, presence: true
validates :username,
@ -59,6 +64,9 @@ class User < ActiveRecord::Base
def self.for_ichain_username(username, attributes)
user = find_by(username: username)
raise UserDisabled if user && user.is_disabled
if user
user.update_attributes(email: attributes[:email])
else

View file

@ -44,13 +44,13 @@
.dropdown-menu{:style => "padding: 17px;"}
- if CONFIG['authentication']['ichain']['enabled']
= form_tag User.ichain_login_url do
= text_field_tag 'username', nil, id: 'user_ichain_email_dd'
= password_field_tag 'password', nil, id: 'user_ichain_password_dd'
= text_field_tag 'username', nil, id: 'user_ichain_email_dd', placeholder: 'Username'
= password_field_tag 'password', nil, id: 'user_ichain_password_dd', placeholder: 'Password'
%button.btn.btn-success.btn-block Sign in
- else
= form_tag new_user_session_path do
= text_field_tag 'user[login]', nil, id: 'user_login_dd'
= password_field_tag 'user[password]', nil, id: 'user_password_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', placeholder: 'Password'
%p.text-right
%small
Remember me

View file

@ -0,0 +1,5 @@
class AddIsDisabledFlagToUser < ActiveRecord::Migration
def change
add_column :users, :is_disabled, :boolean, default: false
end
end

View file

@ -11,7 +11,7 @@
#
# 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|
t.uuid "visit_id"
@ -505,6 +505,7 @@ ActiveRecord::Schema.define(version: 20141104131625) do
t.text "volunteer_experience"
t.boolean "is_admin", default: false
t.string "username"
t.boolean "is_disabled", default: false
end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true