Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserProxyValidator < ActiveModel::EachValidator
- def validate_each(record, field, value)
- dummy = User.new({
- email: "dummy@fictitious.com",
- password: value,
- password_confirmation: value
- })
- if(!dummy.valid?)
- dummy.errors[field].each do |msg|
- record.errors[field] << msg
- end
- end
- end
- end
- class ExistingUserValidator < ActiveModel::EachValidator
- def validate_each(record, field, value)
- dummy = User.find_by_reset_password_token(value)
- if(dummy.nil?)
- record.errors[field] << "Invalid invite code or account already activated"
- end
- end
- end
- class Invite
- include Informal::Model
- attr_accessor :user
- attr_accessor :uid
- attr_accessor :first_name
- attr_accessor :last_name
- attr_accessor :company
- attr_accessor :email
- attr_accessor :terms_and_conditions
- attr_accessor :password
- attr_accessor :password_confirmation
- after_initialize do
- end
- validates :uid, presence: true, existing_user: true
- validates :password, confirmation: true, user_proxy: true
- validates_acceptance_of :terms_and_conditions
- def initialize(data)
- @uid = data[:uid]
- @terms_and_conditions = data[:terms_and_conditions] || false
- super(data)
- end
- def save
- if(valid?)
- @user.reset_password!(password, password_confirmation)
- end
- end
- end
Add Comment
Please, Sign In to add comment