summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorDavisLWebb <davislwebb@ymail.com>2014-03-01 20:11:31 -0500
committerDavisLWebb <davislwebb@ymail.com>2014-03-01 20:11:31 -0500
commit0c01ac6eaa42f70994459df6f1b34547a3d373ca (patch)
tree62890cf5c6cb3dfe1914e7e021b8391ba91e13d2 /app/models/user.rb
parent96734ca0eef040effd0b5646ceeaccf39e2ebd38 (diff)
user model
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb86
1 files changed, 86 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
new file mode 100644
index 0000000..17795cc
--- /dev/null
+++ b/app/models/user.rb
@@ -0,0 +1,86 @@
+class User < ActiveRecord::Base
+
+before_save { self.email = email.downcase }
+before_save { self.user_name = user_name.downcase }
+
+=begin
+
+VAILD_EMAIL is the regex used to valid a user given email.
+
+A break down of the regex is listed below.
+
+/ -----------> Start of the regex
+\A ----------> match start of a string
+[\w+\-.]+ ---> at least one owrd character, plus, hyphen, or
+ dot
+@ -----------> literal ampersand
+[a-z\d\-.]+ -> at least one letter, digit, hyphen, or dot
+(?:\.[a-z]+) > ensures that the error of example@foo..com
+ does not occur
+\z ----------> match end of a string
+/ -----------> end of the regex
+i -----------> case sensative
+
+=end
+
+ VALID_EMAIL_REG = /\A[\w+\-.]+@[a-z\d\-.]+(?:\.[a-z]+)\z/i
+
+=begin
+
+VALID_USER_NAME checks to make sure a user's user_name
+is in the proper format.
+
+=end
+
+ VALID_USER_NAME_REG = /[a-zA-Z0-9\-]/
+
+=begin
+
+The following lines put a user accout through a series of
+validations in order to make sure all of their information
+is in the proper format.
+
+validates :symbol_to_be_valided
+
+presence: determines whether or not a symbol is filled or not
+length: ensures there is a length limit on the symbol
+format: checks the format of given information to ensure
+ validity
+
+=end
+
+ validates :name, presence: true, length: { maximum: 50 }
+ validates :email, presence: true, format: {with:
+ VALID_EMAIL_REG},
+ uniqueness: { case_sensitive: false }
+ validates :user_name, presence: true, length:{maximum: 50},
+ format: {with: VALID_USER_NAME_REG },
+ uniqueness: {case_sensitive: false }
+
+=begin
+
+Instead of adding password and password_confirmation
+attributes, requiring the presence of a password,
+requirin that pw and pw_com match, and add an authenticate
+method to compare an encrypted password to the
+password_digest to authenticate users, I can just add
+has_secure_password which does all of this for me
+
+=end
+
+ has_secure_password
+
+ validates :password, length: { minimum: 6 }
+
+=begin
+
+in order to ensure that someone did not accidently submit
+two accounts rapidly (which would throw off the validates
+for user_name and email) I added an index to the Users
+email and user_name in the database to ensure uniqueness
+This also gives and index to the user_name and email
+so finding a unique user SHOULD be easier
+
+=end
+
+end