Skip to content

Commit

Permalink
Automatically downcase User emails.
Browse files Browse the repository at this point in the history
  • Loading branch information
enthusiastick committed Apr 21, 2017
1 parent d249309 commit 22a1684
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Expand Up @@ -4,7 +4,7 @@ class SessionsController < ApplicationController

def create
if params[:session][:login].match(User::EMAIL_REGEXP)
user = User.find_by(email: params[:session][:login])
user = User.find_by(email: params[:session][:login].downcase)
else
user = User.find_by(handle: params[:session][:login])
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/user.rb
Expand Up @@ -5,6 +5,7 @@ class User < ApplicationRecord
attr_accessor :confirmation_token, :password_reset_token, :remember_token

before_create :generate_confirmation_digest, :generate_identifier
before_save :downcase_email

has_secure_password

Expand All @@ -28,6 +29,10 @@ def confirmed?
!confirmed_at.nil?
end

def downcase_email
self.email.downcase!
end

def full_name
"#{first_name} #{last_name}"
end
Expand Down

0 comments on commit 22a1684

Please sign in to comment.