Class: UserRegistration::UsingBirthday
- Includes:
- Notifications, SubscribeVoucherReward
- Defined in:
- app/my_lib/user_registration/using_birthday.rb
Overview
User registration using birthday data
Instance Attribute Summary collapse
-
#error_reporting ⇒ Object
Returns the value of attribute error_reporting.
-
#send_sms ⇒ Object
Returns the value of attribute send_sms.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #generate_password ⇒ Object
-
#initialize(user_params = {}) ⇒ UsingBirthday
constructor
A new instance of UsingBirthday.
- #require_phone_number ⇒ Object
- #save ⇒ Object
- #save!(sneaky = false) ⇒ Object
- #valid? ⇒ Boolean
Methods included from SubscribeVoucherReward
Methods included from Notifications
#send_registration_email, #send_registration_sms
Methods inherited from Base
Constructor Details
#initialize(user_params = {}) ⇒ UsingBirthday
Returns a new instance of UsingBirthday.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/my_lib/user_registration/using_birthday.rb', line 14 def initialize(user_params = {}) @user = if user_params.is_a? ::User user_params else User.new(user_params.merge(username: user_params[:name])) end @user.password = SecureRandom.alphanumeric(16) if @user.birthday.blank? self.send_sms = false @required_attrs = [] @saved_errors = [] @error_reporting = true end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class UserRegistration::Base
Instance Attribute Details
#error_reporting ⇒ Object
Returns the value of attribute error_reporting.
13 14 15 |
# File 'app/my_lib/user_registration/using_birthday.rb', line 13 def error_reporting @error_reporting end |
#send_sms ⇒ Object
Returns the value of attribute send_sms.
13 14 15 |
# File 'app/my_lib/user_registration/using_birthday.rb', line 13 def send_sms @send_sms end |
#user ⇒ Object
Returns the value of attribute user.
13 14 15 |
# File 'app/my_lib/user_registration/using_birthday.rb', line 13 def user @user end |
Instance Method Details
#generate_password ⇒ Object
56 57 58 59 60 61 |
# File 'app/my_lib/user_registration/using_birthday.rb', line 56 def generate_password @required_attrs.push :birthday user.password = user.password_confirmation = user.birthday.strftime('%d%m%Y') if user.birthday.present? nil end |
#require_phone_number ⇒ Object
63 64 65 |
# File 'app/my_lib/user_registration/using_birthday.rb', line 63 def require_phone_number @required_attrs.push :phone end |
#save ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'app/my_lib/user_registration/using_birthday.rb', line 27 def save save! rescue UserRegistration::UserRegistrationError => e @saved_errors.push e # APMErrorHandler.report e if error_reporting false rescue => e (e) false end |
#save!(sneaky = false) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/my_lib/user_registration/using_birthday.rb', line 38 def save!(sneaky = false) generate_password if user.birthday.present? raise(UserRegistration::UserRegistrationError, user.errors..to_s) unless valid? if sneaky user.sneaky_save! else user.save! end send_registration_email if user.birthday.present? voucher_reward_subscription send_registration_sms if send_sms true end |
#valid? ⇒ Boolean
67 68 69 70 71 72 73 74 75 |
# File 'app/my_lib/user_registration/using_birthday.rb', line 67 def valid? @required_attrs.each do |attr| if user.send(attr.to_sym).blank? errors.add(:base, "#{attr.to_s.upcase} is empty") return false end end user.valid? end |