Class: AccountCpt::Registration::RegularUser::WithFirebase
Overview
Instance Method Summary
collapse
#errors, #merge_errors
#remove_customer_guest_booking
#voucher_reward_subscription
#send_registration_email, #send_registration_sms
Instance Method Details
#collect_guest_booking!(_options) ⇒ Object
106
107
108
109
110
|
# File 'app/concepts/account_cpt/registration/regular_user/with_firebase.rb', line 106
def collect_guest_booking!(_options, *)
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
77
78
79
80
81
|
# File 'app/concepts/account_cpt/registration/regular_user/with_firebase.rb', line 38
def populate_model!(options, **)
unless FirebaseIdToken::Certificates.present?
FirebaseIdToken::Certificates.request!
end
firebase_profile = FirebaseIdToken::Signature.verify(options['params']['access_token'])
if firebase_profile.nil?
errors.add(:base, 'Token is invalid')
return false
end
if firebase_profile['user_id'] != options['params']['uid']
errors.add(:base, 'Invalid parameter, UID is not valid')
return false
end
email = firebase_profile['email'].presence || options['params']['email']
new_attr = options['params'].merge(provider: 'firebase',
name: firebase_profile['name'],
email: email,
uid: firebase_profile['user_id']).to_h.with_indifferent_access
options['model'] = ::User.find_or_initialize_by(email: new_attr[:email])
options['model'].attributes = new_attr
if options['model'].new_record?
options['new_user'] = true
options['model'].password = options['model'].password_confirmation = Devise.friendly_token
options['model'].remote_avatar_url = firebase_profile['picture'] if firebase_profile['picture'].present?
else
options['new_user'] = false
end
if options['params']['email'].blank?
errors.add(:email, "Can't be blank")
return false
end
true
rescue FirebaseIdToken::Exceptions::NoCertificatesError => e
APMErrorHandler.report('Failure API request to firebase', e: e)
errors.add(:base, 'firebase authentication error')
false
end
|
#save_user!(options) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'app/concepts/account_cpt/registration/regular_user/with_firebase.rb', line 83
def save_user!(options, **)
user = options['model']
if user.phone_v2_full.blank?
user.phone = nil
user.phone_v2 = nil
user.calling_code = nil
end
if user.valid? && user.save
options[OpCons::OPERATION_RESULT] = user
else
merge_errors { user.errors }
false
end
end
|
#send_notifications!(options) ⇒ Object
98
99
100
101
102
103
104
|
# File 'app/concepts/account_cpt/registration/regular_user/with_firebase.rb', line 98
def send_notifications!(options, *)
return true unless options['new_user']
send_registration_email
voucher_reward_subscription
true
end
|