File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ class User < ActiveRecord::Base
34
34
validates :email , presence : true ,
35
35
uniqueness : { case_sensitive : false }
36
36
37
+ validate :reject_common_login_mistakes , on : :create
38
+
37
39
scope :legitimate_students , -> { where ( legitimate_student : true ) }
38
40
scope :non_legitimate_students , -> { where ( legitimate_student : false ) }
39
41
@@ -297,4 +299,10 @@ def make_salt
297
299
def secure_hash ( string )
298
300
Digest ::SHA2 . hexdigest ( string )
299
301
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
300
308
end
You can’t perform that action at this time.
0 commit comments