summaryrefslogtreecommitdiff
path: root/app/models/invite_code_validator.rb
diff options
context:
space:
mode:
authorankonym <ankonym@gmail.com>2015-08-13 15:29:04 +0200
committerankonym <ankonym@gmail.com>2015-09-28 15:12:44 +0200
commitbd98a2cbb8796039efbffb7039a9bda1cde22dae (patch)
treee2d8f3d0e59b0bb2763cd7eabd9c422a276258ba /app/models/invite_code_validator.rb
parent393291de60c4f29bb03bad596bb60c1e0648e6e7 (diff)
Add validation of invite code in user object based on codes in couch db
Diffstat (limited to 'app/models/invite_code_validator.rb')
-rw-r--r--app/models/invite_code_validator.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models/invite_code_validator.rb b/app/models/invite_code_validator.rb
new file mode 100644
index 0000000..55b7a74
--- /dev/null
+++ b/app/models/invite_code_validator.rb
@@ -0,0 +1,16 @@
+class InviteCodeValidator < ActiveModel::Validator
+ def validate(user)
+ if not_existent?(user.invite_code)
+ add_error_to_user("This is not a valid code", user)
+ end
+ end
+
+ private
+ def not_existent?(code)
+ InviteCode.find_by__id(code) == nil
+ end
+
+ def add_error_to_user(error, user)
+ user.errors[:invite_code] << error
+ end
+end \ No newline at end of file