mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-16 13:14:03 +00:00
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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue