Implements username authentication
It's now possible to login with either username or email That's necessary to be backward compatible for iChain login
This commit is contained in:
parent
aeb23ba914
commit
15c6ed127f
8 changed files with 44 additions and 18 deletions
|
|
@ -68,11 +68,11 @@ class RegistrationsController < Devise::RegistrationsController
|
|||
devise_parameter_sanitizer.for(:account_update) do |u|
|
||||
u.
|
||||
permit(:email, :password, :password_confirmation, :current_password, :name, :biography,
|
||||
:nickname, :affiliation)
|
||||
:nickname, :affiliation, :username)
|
||||
end
|
||||
devise_parameter_sanitizer.for(:sign_up) do |u|
|
||||
u.
|
||||
permit(:email, :password, :password_confirmation, :name)
|
||||
permit(:email, :password, :password_confirmation, :name, :username)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@ class User < ActiveRecord::Base
|
|||
|
||||
attr_accessible :email, :password, :password_confirmation, :remember_me, :role_id, :role_ids,
|
||||
:name, :email_public, :biography, :nickname, :affiliation, :is_admin,
|
||||
:tshirt, :mobile, :volunteer_experience, :languages
|
||||
:tshirt, :mobile, :volunteer_experience, :languages, :username, :login
|
||||
|
||||
attr_accessor :login
|
||||
|
||||
has_many :event_users, dependent: :destroy
|
||||
has_many :events, -> { uniq }, through: :event_users
|
||||
|
|
@ -31,6 +33,11 @@ class User < ActiveRecord::Base
|
|||
|
||||
validates :name, presence: true
|
||||
|
||||
validates :username,
|
||||
:uniqueness => {
|
||||
:case_sensitive => false
|
||||
}
|
||||
|
||||
# Returns the ticket purchased ticket
|
||||
# ====Returns
|
||||
# * +TicketUser::ActiveRecord_Relation+ -> user
|
||||
|
|
@ -38,6 +45,15 @@ class User < ActiveRecord::Base
|
|||
ticket_purchases.where(ticket_id: id).first
|
||||
end
|
||||
|
||||
def self.find_for_database_authentication(warden_conditions)
|
||||
conditions = warden_conditions.dup
|
||||
if login = conditions.delete(:login)
|
||||
where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
|
||||
else
|
||||
where(conditions).first
|
||||
end
|
||||
end
|
||||
|
||||
# Searches for user based on email. Returns found user or new user.
|
||||
# ====Returns
|
||||
# * +User::ActiveRecord_Relation+ -> user
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
= render 'devise/shared/openid'
|
||||
|
||||
= f.inputs name: 'Account' do
|
||||
= f.input :username, required: false, input_html: {autocomplete: "off"}
|
||||
= f.input :email, required: false, input_html: {autocomplete: "off"}
|
||||
= f.input :password, hint: "(Leave blank if you don't want to change it)", input_html: {autocomplete: 'off'}
|
||||
= f.input :password_confirmation, input_html: {autocomplete: 'off'}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
Sign Up
|
||||
.panel-body
|
||||
= semantic_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
|
||||
= f.input :username, required: true
|
||||
= f.input :email
|
||||
= f.input :name, required: true
|
||||
= f.input :password
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
Sign In
|
||||
.panel-body
|
||||
= semantic_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
|
||||
= f.input :email
|
||||
= f.input :login
|
||||
= f.input :password
|
||||
- if devise_mapping.rememberable?
|
||||
%p.text-right.small
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue