Skip to content

Commit 290a1a9

Browse files
committed
Reject emails and student numbers on usernames
1 parent 714c74f commit 290a1a9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

app/models/user.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class User < ActiveRecord::Base
3434
validates :email, presence: true,
3535
uniqueness: { case_sensitive: false }
3636

37+
validate :reject_common_login_mistakes, on: :create
38+
3739
scope :legitimate_students, -> { where(legitimate_student: true) }
3840
scope :non_legitimate_students, -> { where(legitimate_student: false) }
3941

@@ -297,4 +299,10 @@ def make_salt
297299
def secure_hash(string)
298300
Digest::SHA2.hexdigest(string)
299301
end
302+
303+
def reject_common_login_mistakes
304+
return if !login || login.empty?
305+
errors.add(:login, "may not be your email address. Keep in mind that your username is public to everyone.") if login.include?('@')
306+
errors.add(:login, "may not be a number. Use the organizational identifier field for your student number.") if login.scan(/\D/).empty?
307+
end
300308
end

0 commit comments

Comments
 (0)