Class: AccountCpt::Registration::RegularUser::WithFacebookV2
- Inherits:
-
Trailblazer::Operation
- Object
- Trailblazer::Operation
- AccountCpt::Registration::RegularUser::WithFacebookV2
- Extended by:
- Contract::DSL
- Includes:
- ErrorOperationHelper, UserRegistration::MergeGuestBookings, UserRegistration::Notifications, UserRegistration::SubscribeVoucherReward
- Defined in:
- app/concepts/account_cpt/registration/regular_user/with_facebook_v2.rb
Overview
return registered user
Instance Method Summary collapse
- #collect_guest_booking!(_options) ⇒ Object
- #populate_model!(options) ⇒ Object
- #save_user!(options) ⇒ Object
- #send_notifications!(options) ⇒ Object
Methods included from ErrorOperationHelper
Methods included from UserRegistration::MergeGuestBookings
#remove_customer_guest_booking
Methods included from UserRegistration::SubscribeVoucherReward
Methods included from UserRegistration::Notifications
#send_registration_email, #send_registration_sms
Instance Method Details
#collect_guest_booking!(_options) ⇒ Object
109 110 111 112 |
# File 'app/concepts/account_cpt/registration/regular_user/with_facebook_v2.rb', line 109 def collect_guest_booking!(, *) remove_customer_guest_booking(user.id) true end |
#populate_model!(options) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/concepts/account_cpt/registration/regular_user/with_facebook_v2.rb', line 38 def populate_model!(, **) graph = Koala::Facebook::API.new(['params']['access_token']) profile = graph.get_object('me', {}) if profile['id'] != ['params']['uid'] errors.add(:base, 'Invalid parameter, UID is not valid') return false end if ['params']['email'].blank? errors.add(:email, "Can't be blank") return false end ['params'].delete('phone') if ['params']['phone'].blank? new_user_attr = ['params'].merge( provider: User::PROVIDER_FACEBOOK.to_s, name: profile['name'], fb_uid: profile['id'], uid: profile['id'], ).to_h.with_indifferent_access ['model'] = ::User.find_or_initialize_by(email: new_user_attr[:email]) if ['model'].new_record? ['model'].attributes = new_user_attr ['new_user'] = true ['model'].password = ['model'].password_confirmation = Devise.friendly_token else ['model'].attributes = ['params'] ['new_user'] = false end true rescue Koala::Facebook::AuthenticationError, Koala::Facebook::OAuthTokenRequestError, Koala::Facebook::APIError => e APMErrorHandler.report('Failure API request to Facebook', e: e) errors.add(:base, 'Facebook authentication error') false end |
#save_user!(options) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/concepts/account_cpt/registration/regular_user/with_facebook_v2.rb', line 78 def save_user!(, **) user = ['model'] # Check if the email has already been registered if User.exists?(email: user.email) user.errors.add(:email, 'has registered') merge_errors { user.errors } false end # Set phone-related fields to nil if phone_v2_full is blank if user.phone_v2_full.blank? user.phone = nil user.phone_v2 = nil user.calling_code = nil end # Save the user and return the result if user.valid? && user.save [OpCons::OPERATION_RESULT] = user else merge_errors { user.errors } false end end |
#send_notifications!(options) ⇒ Object
101 102 103 104 105 106 107 |
# File 'app/concepts/account_cpt/registration/regular_user/with_facebook_v2.rb', line 101 def send_notifications!(, *) return true unless ['new_user'] send_registration_email voucher_reward_subscription true end |