wordjelly-auth 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +35 -0
- data/app/assets/images/auth/activity.jpg +0 -0
- data/app/assets/images/auth/facebook.svg +1 -0
- data/app/assets/images/auth/google_oauth2.svg +1 -0
- data/app/assets/images/auth/js_pic3.jpg +0 -0
- data/app/assets/images/auth/profile.jpg +0 -0
- data/app/assets/javascripts/auth/admin_create_users.js +2 -0
- data/app/assets/javascripts/auth/application.js +20 -0
- data/app/assets/javascripts/auth/auth_dependencies.js +12 -0
- data/app/assets/javascripts/auth/auth_modals_and_navbar.js +218 -0
- data/app/assets/javascripts/auth/clients.js +2 -0
- data/app/assets/javascripts/auth/search.js +2 -0
- data/app/assets/javascripts/auth/shopping/discounts.js +2 -0
- data/app/assets/javascripts/auth/users/profiles.js +188 -0
- data/app/assets/stylesheets/auth/admin_create_users.css +4 -0
- data/app/assets/stylesheets/auth/application.scss +14 -0
- data/app/assets/stylesheets/auth/auth_default_css.scss +13 -0
- data/app/assets/stylesheets/auth/common-styles.scss +579 -0
- data/app/assets/stylesheets/auth/overrides.scss +26 -0
- data/app/assets/stylesheets/auth/search.css +4 -0
- data/app/assets/stylesheets/auth/shopping/discounts.css +4 -0
- data/app/assets/stylesheets/auth/users/profiles.scss +40 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/auth/admin_create_users_controller.rb +89 -0
- data/app/controllers/auth/application_controller.rb +97 -0
- data/app/controllers/auth/clients_controller.rb +105 -0
- data/app/controllers/auth/concerns/activity_controller_concern.rb +32 -0
- data/app/controllers/auth/concerns/devise_concern.rb +193 -0
- data/app/controllers/auth/concerns/omni_concern.rb +310 -0
- data/app/controllers/auth/concerns/otp_concern.rb +251 -0
- data/app/controllers/auth/concerns/shopping/cart_controller_concern.rb +105 -0
- data/app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb +150 -0
- data/app/controllers/auth/concerns/shopping/discount_controller_concern.rb +97 -0
- data/app/controllers/auth/concerns/shopping/pay_u_money_controller_concern.rb +38 -0
- data/app/controllers/auth/concerns/shopping/payment_controller_concern.rb +101 -0
- data/app/controllers/auth/concerns/shopping/product_controller_concern.rb +68 -0
- data/app/controllers/auth/concerns/token_concern.rb +187 -0
- data/app/controllers/auth/confirmations_controller.rb +3 -0
- data/app/controllers/auth/mailgun_controller.rb +8 -0
- data/app/controllers/auth/omniauth_callbacks_controller.rb +6 -0
- data/app/controllers/auth/passwords_controller.rb +4 -0
- data/app/controllers/auth/profiles_controller.rb +156 -0
- data/app/controllers/auth/registrations_controller.rb +99 -0
- data/app/controllers/auth/search_controller.rb +61 -0
- data/app/controllers/auth/sessions_controller.rb +20 -0
- data/app/controllers/auth/shopping/cart_items_controller.rb +14 -0
- data/app/controllers/auth/shopping/carts_controller.rb +13 -0
- data/app/controllers/auth/shopping/discounts_controller.rb +19 -0
- data/app/controllers/auth/shopping/payments_controller.rb +13 -0
- data/app/controllers/auth/shopping/products_controller.rb +17 -0
- data/app/controllers/auth/shopping/shopping_controller.rb +86 -0
- data/app/controllers/auth/unlocks_controller.rb +3 -0
- data/app/controllers/auth/webhooks_controller.rb +3 -0
- data/app/helpers/auth/admin_create_users_helper.rb +2 -0
- data/app/helpers/auth/application_helper.rb +136 -0
- data/app/helpers/auth/clients_helper.rb +4 -0
- data/app/helpers/auth/resource_helper.rb +10 -0
- data/app/helpers/auth/search_helper.rb +2 -0
- data/app/helpers/auth/shopping/cart_items/cart_items_helper.rb +29 -0
- data/app/helpers/auth/shopping/carts/carts_helper.rb +25 -0
- data/app/helpers/auth/shopping/discounts/discounts_helper.rb +39 -0
- data/app/helpers/auth/shopping/payments/pay_u_money_helper.rb +56 -0
- data/app/helpers/auth/shopping/payments/payments_helper.rb +54 -0
- data/app/helpers/auth/shopping/products/products_helper.rb +52 -0
- data/app/helpers/auth/shopping/shopping_helper.rb +3 -0
- data/app/helpers/auth/users/profiles_helper.rb +12 -0
- data/app/jobs/otp_job.rb +92 -0
- data/app/mailers/application_mailer.rb +4 -0
- data/app/mailers/auth/notifier.rb +9 -0
- data/app/models/auth/admin_create_user.rb +3 -0
- data/app/models/auth/client.rb +52 -0
- data/app/models/auth/concerns/activity_concern.rb +112 -0
- data/app/models/auth/concerns/chief_model_concern.rb +73 -0
- data/app/models/auth/concerns/es_concern.rb +21 -0
- data/app/models/auth/concerns/notification_concern.rb +232 -0
- data/app/models/auth/concerns/notification_response_concern.rb +71 -0
- data/app/models/auth/concerns/owner_concern.rb +81 -0
- data/app/models/auth/concerns/shopping/cart_concern.rb +329 -0
- data/app/models/auth/concerns/shopping/cart_item_concern.rb +437 -0
- data/app/models/auth/concerns/shopping/discount_concern.rb +482 -0
- data/app/models/auth/concerns/shopping/discount_flow.txt +11 -0
- data/app/models/auth/concerns/shopping/pay_u_money_concern.rb +184 -0
- data/app/models/auth/concerns/shopping/payment_concern.rb +613 -0
- data/app/models/auth/concerns/shopping/product_concern.rb +102 -0
- data/app/models/auth/concerns/sms_otp_concern.rb +68 -0
- data/app/models/auth/concerns/user_concern.rb +788 -0
- data/app/models/auth/identity.rb +23 -0
- data/app/models/auth/shopping/cart.rb +3 -0
- data/app/models/auth/shopping/cart_item.rb +6 -0
- data/app/models/auth/shopping/cart_item_payment_result.rb +7 -0
- data/app/models/auth/shopping/discount.rb +4 -0
- data/app/models/auth/shopping/payment.rb +5 -0
- data/app/models/auth/shopping/product.rb +5 -0
- data/app/models/auth/user.rb +3 -0
- data/app/views/auth/admin_create_users/_admin_actions.html.erb +46 -0
- data/app/views/auth/admin_create_users/_form.html.erb +19 -0
- data/app/views/auth/admin_create_users/edit.html.erb +6 -0
- data/app/views/auth/admin_create_users/index.html.erb +25 -0
- data/app/views/auth/admin_create_users/new.html.erb +5 -0
- data/app/views/auth/admin_create_users/show.html.erb +8 -0
- data/app/views/auth/clients/_form.html.erb +41 -0
- data/app/views/auth/clients/edit.html.erb +6 -0
- data/app/views/auth/clients/index.html.erb +33 -0
- data/app/views/auth/clients/new.html.erb +5 -0
- data/app/views/auth/clients/show.html.erb +21 -0
- data/app/views/auth/confirmations/_enter_otp.html.erb +27 -0
- data/app/views/auth/confirmations/_get_otp_status.html.erb +25 -0
- data/app/views/auth/confirmations/_new_otp_input.js.erb +11 -0
- data/app/views/auth/confirmations/_resend_otp.js.erb +8 -0
- data/app/views/auth/confirmations/_resend_sms_otp.html.erb +18 -0
- data/app/views/auth/confirmations/_verify_otp.js.erb +64 -0
- data/app/views/auth/confirmations/create.js.erb +8 -0
- data/app/views/auth/confirmations/enter_otp.html.erb +7 -0
- data/app/views/auth/confirmations/get_otp_status.html.erb +3 -0
- data/app/views/auth/confirmations/new.html.erb +1 -0
- data/app/views/auth/confirmations/new.js.erb +16 -0
- data/app/views/auth/confirmations/otp_status_result.html.erb +20 -0
- data/app/views/auth/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/auth/mailer/password_change.html.erb +3 -0
- data/app/views/auth/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/auth/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/auth/modals/_ajax_error_modal.html.erb +3 -0
- data/app/views/auth/modals/_ajax_error_modal_content.html.erb +0 -0
- data/app/views/auth/modals/_edit_account_content.html.erb +68 -0
- data/app/views/auth/modals/_edit_account_success_content.html.erb +5 -0
- data/app/views/auth/modals/_error_notification.html.erb +8 -0
- data/app/views/auth/modals/_forgot_password_content.html.erb +18 -0
- data/app/views/auth/modals/_forgot_password_success_content.html.erb +8 -0
- data/app/views/auth/modals/_login_default_content.html.erb +3 -0
- data/app/views/auth/modals/_login_forms.html.erb +13 -0
- data/app/views/auth/modals/_login_navigation_options.html.erb +12 -0
- data/app/views/auth/modals/_new_otp_input.html.erb +28 -0
- data/app/views/auth/modals/_oauth_and_submit.html.erb +21 -0
- data/app/views/auth/modals/_recaptcha_tags.html.erb +4 -0
- data/app/views/auth/modals/_resend_confirmation_content.html.erb +17 -0
- data/app/views/auth/modals/_resend_confirmation_success_content.html.erb +8 -0
- data/app/views/auth/modals/_resend_otp.html.erb +23 -0
- data/app/views/auth/modals/_resource_errors.js.erb +24 -0
- data/app/views/auth/modals/_sign_in_inputs.html.erb +10 -0
- data/app/views/auth/modals/_sign_in_needed_modal.html.erb +3 -0
- data/app/views/auth/modals/_sign_in_success_content.html.erb +5 -0
- data/app/views/auth/modals/_sign_up_inputs.html.erb +9 -0
- data/app/views/auth/modals/_sign_up_success_content.html.erb +1 -0
- data/app/views/auth/modals/_sign_up_success_inactive_content.html.erb +2 -0
- data/app/views/auth/modals/_unlock_content.html.erb +17 -0
- data/app/views/auth/modals/_verify_otp.html.erb +1 -0
- data/app/views/auth/modals/base_modal/_base.html.erb +25 -0
- data/app/views/auth/modals/login.js.erb +120 -0
- data/app/views/auth/modals/unlock_success_content.html.erb +8 -0
- data/app/views/auth/notifier/_email.html.erb +3 -0
- data/app/views/auth/notifier/notification.html.erb +2 -0
- data/app/views/auth/notifier/notification.text.erb +1 -0
- data/app/views/auth/omniauth_callbacks/failure.html.erb +4 -0
- data/app/views/auth/passwords/create.js.erb +12 -0
- data/app/views/auth/passwords/edit.html.erb +25 -0
- data/app/views/auth/passwords/new.html.erb +16 -0
- data/app/views/auth/passwords/new.js.erb +19 -0
- data/app/views/auth/profiles/_proxy_resource.html.erb +5 -0
- data/app/views/auth/profiles/set_proxy_resource.js.erb +1 -0
- data/app/views/auth/profiles/show.html.erb +8 -0
- data/app/views/auth/registrations/create.js.erb +40 -0
- data/app/views/auth/registrations/edit.html.erb +2 -0
- data/app/views/auth/registrations/edit.js.erb +5 -0
- data/app/views/auth/registrations/new.html.erb +33 -0
- data/app/views/auth/registrations/update.js.erb +47 -0
- data/app/views/auth/search/_search_bar.html.erb +11 -0
- data/app/views/auth/search/_search_result.html.erb +7 -0
- data/app/views/auth/search/_search_results.html.erb +4 -0
- data/app/views/auth/search/authenticated_user_search.js.erb +45 -0
- data/app/views/auth/search/authenticated_user_search.json +7 -0
- data/app/views/auth/sessions/create.js.erb +5 -0
- data/app/views/auth/sessions/new.html.erb +4 -0
- data/app/views/auth/sessions/new.js.erb +20 -0
- data/app/views/auth/shared/_devise_error_messages.html.erb +9 -0
- data/app/views/auth/shared/_links.html.erb +25 -0
- data/app/views/auth/shared/_object_errors.html.erb +12 -0
- data/app/views/auth/shared/_proxy_resource.html.erb +18 -0
- data/app/views/auth/shopping/cart_items/_form.html.erb +34 -0
- data/app/views/auth/shopping/cart_items/_show_cart_items_collection.html.erb +31 -0
- data/app/views/auth/shopping/cart_items/create_multiple.html.erb +6 -0
- data/app/views/auth/shopping/cart_items/create_multiple.json.erb +9 -0
- data/app/views/auth/shopping/cart_items/edit.html.erb +6 -0
- data/app/views/auth/shopping/cart_items/index.html.erb +52 -0
- data/app/views/auth/shopping/cart_items/new.html.erb +5 -0
- data/app/views/auth/shopping/cart_items/show.html.erb +13 -0
- data/app/views/auth/shopping/carts/_form.html.erb +35 -0
- data/app/views/auth/shopping/carts/_payment_links.html.erb +27 -0
- data/app/views/auth/shopping/carts/_remove_cart_item.html.erb +11 -0
- data/app/views/auth/shopping/carts/_show_cart_balance_info.html.erb +35 -0
- data/app/views/auth/shopping/carts/edit.html.erb +6 -0
- data/app/views/auth/shopping/carts/index.html.erb +43 -0
- data/app/views/auth/shopping/carts/new.html.erb +5 -0
- data/app/views/auth/shopping/carts/show.html.erb +46 -0
- data/app/views/auth/shopping/discounts/_form.html.erb +18 -0
- data/app/views/auth/shopping/discounts/_form_for_create_multiple_cart_items.html.erb +17 -0
- data/app/views/auth/shopping/discounts/_show_pending_discount_request.html.erb +17 -0
- data/app/views/auth/shopping/discounts/destroy.html.erb +2 -0
- data/app/views/auth/shopping/discounts/edit.html.erb +29 -0
- data/app/views/auth/shopping/discounts/index.html.erb +40 -0
- data/app/views/auth/shopping/discounts/new.html.erb +1 -0
- data/app/views/auth/shopping/discounts/show.html.erb +18 -0
- data/app/views/auth/shopping/discounts/update.html.erb +2 -0
- data/app/views/auth/shopping/payments/_approve_payment.html.erb +7 -0
- data/app/views/auth/shopping/payments/_cash_card_cheque.html.erb +24 -0
- data/app/views/auth/shopping/payments/_create_discount_coupon.html.erb +5 -0
- data/app/views/auth/shopping/payments/_form.html.erb +19 -0
- data/app/views/auth/shopping/payments/_gateway.html.erb +21 -0
- data/app/views/auth/shopping/payments/_proceed_to_gateway_or_verify_payment.html.erb +18 -0
- data/app/views/auth/shopping/payments/_refresh_payment.html.erb +7 -0
- data/app/views/auth/shopping/payments/_refund.html.erb +10 -0
- data/app/views/auth/shopping/payments/_show_payment_receipt.html.erb +12 -0
- data/app/views/auth/shopping/payments/edit.html.erb +6 -0
- data/app/views/auth/shopping/payments/index.html.erb +43 -0
- data/app/views/auth/shopping/payments/new.html.erb +13 -0
- data/app/views/auth/shopping/payments/show.html.erb +36 -0
- data/app/views/auth/shopping/products/_form.html.erb +27 -0
- data/app/views/auth/shopping/products/edit.html.erb +6 -0
- data/app/views/auth/shopping/products/index.html.erb +48 -0
- data/app/views/auth/shopping/products/index.json.erb +7 -0
- data/app/views/auth/shopping/products/new.html.erb +5 -0
- data/app/views/auth/shopping/products/show.html.erb +12 -0
- data/app/views/auth/shopping/products/show.json.erb +1 -0
- data/app/views/auth/unlocks/create.js.erb +12 -0
- data/app/views/auth/unlocks/new.html.erb +14 -0
- data/app/views/auth/unlocks/new.js.erb +17 -0
- data/app/views/auth/users/_search_result.html.erb +8 -0
- data/app/views/auth/users/profiles/_user_data.html.erb +4 -0
- data/app/views/auth/users/profiles/show.html.erb +54 -0
- data/app/views/layouts/auth/_modals.html.erb +2 -0
- data/app/views/layouts/auth/application.html.erb +17 -0
- data/app/views/layouts/auth/navbar/_navbar.html.erb +49 -0
- data/app/views/layouts/auth/navbar/_personalization.html.erb +17 -0
- data/app/views/layouts/auth/navbar/_progress_spinner.html.erb +11 -0
- data/app/views/layouts/mailer.html.erb +5 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/config/initializers/active_model.rb +36 -0
- data/config/initializers/devise.rb +623 -0
- data/config/initializers/json.rb +10 -0
- data/config/initializers/omniauth.rb +447 -0
- data/config/initializers/redis.rb +2 -0
- data/config/initializers/redis.yml +14 -0
- data/config/locales/devise.en.yml +63 -0
- data/config/routes.rb +1 -0
- data/lib/assets/javascripts/data.js +126 -0
- data/lib/assets/javascripts/jquery.calendario.js +394 -0
- data/lib/assets/javascripts/jquery.tagcloud.js +92 -0
- data/lib/assets/javascripts/leanModal.js +236 -0
- data/lib/assets/javascripts/main.js +668 -0
- data/lib/assets/javascripts/modernizr.custom.63321.js +4 -0
- data/lib/assets/javascripts/payumoney.js +9 -0
- data/lib/assets/javascripts/search.js +36 -0
- data/lib/assets/javascripts/spinner.js +77 -0
- data/lib/assets/javascripts/trianglify.min.js +2 -0
- data/lib/assets/javascripts/you_need_to_sign_in.js.erb +478 -0
- data/lib/assets/stylesheets/calendar.css +111 -0
- data/lib/assets/stylesheets/calendar_modifications.scss +276 -0
- data/lib/auth.rb +32 -0
- data/lib/auth/custom_failure.rb +3 -0
- data/lib/auth/engine.rb +231 -0
- data/lib/auth/job_exception_handler.rb +7 -0
- data/lib/auth/mailgun.rb +28 -0
- data/lib/auth/notify.rb +8 -0
- data/lib/auth/omniauth/path.rb +104 -0
- data/lib/auth/partials.rb +12 -0
- data/lib/auth/rails/routes.rb +169 -0
- data/lib/auth/search/main.rb +97 -0
- data/lib/auth/sidekiq_up.rb +16 -0
- data/lib/auth/two_factor_otp.rb +202 -0
- data/lib/auth/url_shortener.rb +29 -0
- data/lib/auth/version.rb +3 -0
- data/lib/tasks/auth_tasks.rake +4 -0
- metadata +863 -0
@@ -0,0 +1,251 @@
|
|
1
|
+
module Auth::Concerns::OtpConcern
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
include Auth::Concerns::DeviseConcern
|
6
|
+
##refer to auth/applicationcontroller for the not_found def, and its rescue block.
|
7
|
+
before_filter :do_before_request
|
8
|
+
before_filter :initialize_vars
|
9
|
+
before_filter :check_recaptcha, only: [:send_sms_otp,:verify_otp]
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize_vars
|
14
|
+
##deep symbolize the incoming params after passing through permitted params.
|
15
|
+
|
16
|
+
@resource_params = permitted_params.deep_symbolize_keys
|
17
|
+
|
18
|
+
##if the resource is defined, assign the class and the symbol for use further in the file
|
19
|
+
##eg: resource is provided in the route as : users, so
|
20
|
+
##@resource_class => User
|
21
|
+
##@resource_symbol => :user
|
22
|
+
|
23
|
+
if collection = @resource_params[:resource]
|
24
|
+
##check that the resource exists in the auth_configuration
|
25
|
+
if Auth.configuration.auth_resources[collection.singularize.capitalize]
|
26
|
+
@resource_class = collection.singularize.capitalize.constantize
|
27
|
+
@resource_symbol = collection.singularize.to_sym
|
28
|
+
|
29
|
+
|
30
|
+
##this is either the provided email(in case of forgot_password form, we pass in the additional_login_param under the email key itself.#ref auth/modals/forgot_password_content.html.erb)
|
31
|
+
if @resource_params[@resource_symbol]
|
32
|
+
@additional_login_param = @resource_params[@resource_symbol][:email] || @resource_params[@resource_symbol][:additional_login_param]
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
##the otp provided by the user, only used in the verify_otp action.
|
37
|
+
@otp = @resource_params[@resource_symbol][:otp]
|
38
|
+
|
39
|
+
##the resource_id of the user, only used in the short_polling endpoint.
|
40
|
+
@resource_id = @resource_params[@resource_symbol][:_id]
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
else
|
45
|
+
##have to have some way of showing these errors.
|
46
|
+
not_found("provided resource not found in app")
|
47
|
+
end
|
48
|
+
else
|
49
|
+
not_found("no resource collection provided")
|
50
|
+
end
|
51
|
+
|
52
|
+
##the intent , passed into the send_sms_otp endpoint, and thereafter added to the verify_otp_path, in the new_otp_input.html.erb
|
53
|
+
##set as default to empty so that it doesnt screw up in the partials, screaming undefined.
|
54
|
+
@intent = @resource_params[:intent] or ""
|
55
|
+
|
56
|
+
|
57
|
+
##the default response status, can be changed in the action depending on individual situations.
|
58
|
+
@response_status = 200
|
59
|
+
end
|
60
|
+
|
61
|
+
##CALLED WHEN THE USER HAS ENTERED HIS MOBILE NUMBER, SO THAT HE GETS ANOTHER OTP
|
62
|
+
def send_sms_otp
|
63
|
+
##IF THERE IS AN INTENT,THEN WE MUST HAVE A CONFIRMED ACCOUNT.
|
64
|
+
##OTHERWISE WE DONT NEED THAT.
|
65
|
+
##WHY?
|
66
|
+
##because : suppose that we are calling send_sms_otp from the forgot_password / unlocks controller -> then we have to ensure that the account has been verified.
|
67
|
+
##otherwise we cannot send otp's to non-verified phone numbers to do things like reset_passwords / unlock
|
68
|
+
##on the other hand in case there is no intent, like in case of resend_otp -> then we can only check if we have an account with this mobile number or not, no need to check for verification.
|
69
|
+
conditions = @intent.blank? ? {:additional_login_param => @additional_login_param} : {:additional_login_param => @additional_login_param, :additional_login_param_status => 2}
|
70
|
+
|
71
|
+
if @additional_login_param.nil?
|
72
|
+
@status = 422
|
73
|
+
resource = @resource_class.new
|
74
|
+
resource.errors.add(:additional_login_param,"Additional login param not provided")
|
75
|
+
elsif resource = @resource_class.where(conditions).first
|
76
|
+
#resource.intent_token = Devise.friendly_token if !@intent.blank?
|
77
|
+
#resource.save
|
78
|
+
resource.m_client = self.m_client
|
79
|
+
resource.set_client_authentication
|
80
|
+
resource.send_sms_otp
|
81
|
+
elsif resource = @resource_class.new
|
82
|
+
@status = 422
|
83
|
+
resource.errors.add(:additional_login_param,"Could not find a resource with that additional login param")
|
84
|
+
end
|
85
|
+
@auth_user = resource
|
86
|
+
respond_to do |format|
|
87
|
+
format.json {render json: resource.to_json({:otp_verification => true}), status: @status}
|
88
|
+
format.js {render :partial => "auth/confirmations/new_otp_input.js.erb", locals: {resource: resource, intent: @intent}}
|
89
|
+
format.html {render 'auth/confirmations/enter_otp.html.erb'}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
## this is only used for the modal based things
|
94
|
+
## has no role otherwise.
|
95
|
+
##CALLED WHEN WE WANT TO SHOW THE USER A MODAL TO RE-ENTER HIS MOBILE NUMBER SO THAT WE CAN AGAIN SEND AN OTP TO IT.
|
96
|
+
def resend_sms_otp
|
97
|
+
resource = @resource_class.new
|
98
|
+
respond_to do |format|
|
99
|
+
format.json {render json: resource.to_json, status: @status}
|
100
|
+
format.js {render "auth/confirmations/_resend_otp.js.erb", locals: {resource: resource, intent: @intent}}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
##CALLED WHEN THE USER ENTERS THE OTP SENT ON HIS MOBILE
|
105
|
+
##VERIFIES THE OTP WITH THE THIRD PARTY API.
|
106
|
+
def verify_otp
|
107
|
+
if resource = @resource_class.where(:additional_login_param => @additional_login_param).first
|
108
|
+
resource.m_client = self.m_client
|
109
|
+
resource.set_client_authentication
|
110
|
+
|
111
|
+
##there are no errors, so we proceed with verification.
|
112
|
+
if otp_error = resource.check_otp_errors
|
113
|
+
@status = 422
|
114
|
+
resource.errors.add(:additional_login_param,otp_error)
|
115
|
+
else
|
116
|
+
resource.verify_sms_otp(@otp)
|
117
|
+
## just setting so that it is available on the resource object.
|
118
|
+
resource.otp = @otp
|
119
|
+
end
|
120
|
+
else
|
121
|
+
resource = @resource_class.new
|
122
|
+
resource.errors.add(:additional_login_param,"Not Found")
|
123
|
+
@status = 400
|
124
|
+
end
|
125
|
+
@auth_user = resource
|
126
|
+
respond_to do |format|
|
127
|
+
format.json {render json: resource.as_json({:otp_verification => true}), status: @status}
|
128
|
+
format.js {render :partial => "auth/confirmations/verify_otp.js.erb", locals: {resource: resource, intent: @intent, otp: @otp}}
|
129
|
+
format.html {render "auth/confirmations/get_otp_status.html.erb"}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
##SHORT-POLLING ENDPOINT TO DETERMINE IF THE OTP WAS VALID.
|
135
|
+
##CALLED IN THE POST-VERIFICATION PAGE.
|
136
|
+
##error returns for this def are different, because it is requested using json from the verify_otp.js.erb partial
|
137
|
+
##as a result, in case there is an error in the controller action itslef below(eg. wherever there is a 422/400), then the following happens.
|
138
|
+
##spinner.js
|
139
|
+
##//catches any non 200/201 status and interprets it as an error
|
140
|
+
##//thereafter directly show_error_modal is called.
|
141
|
+
##//i could have written logic specific for otp_verification_result, by checking if it is there in the request_url, but did not do so, because otp is not always going to be in the engine, so otp should not be hardcoded anywhere.
|
142
|
+
##//the error lands up being shown inside show_error_modal, by means of json parsing the incoming string, and showing json[:errors] as the error message.
|
143
|
+
##on the other hand, if there is any othe rtype of error in the before_filter initialize_vars, then that raises a not_found and is handled by rendering a json response with errors, and a 422 so again it is handled by spinner as above.
|
144
|
+
def otp_verification_result
|
145
|
+
|
146
|
+
## a message to display on the website after the otp is successfully verified in case of forgot_password or unlock_account.
|
147
|
+
intent_verification_message = nil
|
148
|
+
res_verified = false
|
149
|
+
##first check the errors
|
150
|
+
|
151
|
+
|
152
|
+
if resource = @resource_class.where(:additional_login_param => @additional_login_param, :otp => @otp).first
|
153
|
+
|
154
|
+
if otp_error = resource.check_otp_errors
|
155
|
+
@status = 422
|
156
|
+
resource.errors.add(:additional_login_param,otp_error)
|
157
|
+
else
|
158
|
+
resource.m_client = self.m_client
|
159
|
+
resource.set_client_authentication
|
160
|
+
if resource.additional_login_param_confirmed?
|
161
|
+
puts "resource additional login param is confirmed."
|
162
|
+
puts "intent is: #{@intent}"
|
163
|
+
if @intent == "reset_password"
|
164
|
+
|
165
|
+
##protected method so had to do this.
|
166
|
+
if resource.confirmed? && !resource. pending_reconfirmation?
|
167
|
+
resource.class.send_reset_password_instructions(resource.attributes)
|
168
|
+
|
169
|
+
intent_verification_message = "An email has been sent to your email account, with instructions on resetting your password" if resource.errors.empty?
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
##if successfull_sent ->
|
174
|
+
##else
|
175
|
+
## here error is added anyway to resource.
|
176
|
+
##end
|
177
|
+
##we want to send the reset password instructions, but using the email.
|
178
|
+
else
|
179
|
+
|
180
|
+
resource.errors.add(:additional_login_param,"you do not have a confirmed email account set for this account, you cannot recover the password.")
|
181
|
+
|
182
|
+
@status = 400
|
183
|
+
end
|
184
|
+
#raw_token = resource.send(:set_reset_password_token)
|
185
|
+
#intent_url = send("edit_#{@resource_symbol.to_s}_password_path",{:reset_password_token => raw_token})
|
186
|
+
elsif @intent == "unlock_account"
|
187
|
+
##here normally would be resource.unlock.
|
188
|
+
##code from https://github.com/plataformatec/devise/blob/master/lib/devise/models/lockable.rb#send_unlock_instructions
|
189
|
+
#puts "came to unlocks."
|
190
|
+
|
191
|
+
#raw, enc = Devise.token_generator.generate(@resource.class, :unlock_token)
|
192
|
+
#@resource.unlock_token = enc
|
193
|
+
#@resource.save(validate: false)
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
if resource.confirmed? && !resource. pending_reconfirmation?
|
198
|
+
|
199
|
+
resource.send_unlock_instructions
|
200
|
+
|
201
|
+
intent_verification_message = "An email has been sent to your email account, with instructions on unlocking your account" if resource.errors.empty?
|
202
|
+
else
|
203
|
+
|
204
|
+
|
205
|
+
resource.errors.add(:additional_login_param,"cannot send unlock instructions because you dont have a confirmed email address.")
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
#intent_url = send("#{@resource_symbol.to_s}_unlock_path",{:unlock_token => raw})
|
210
|
+
end
|
211
|
+
##make the intent token nil, it can be used only thus once.
|
212
|
+
|
213
|
+
end
|
214
|
+
end
|
215
|
+
else
|
216
|
+
resource = @resource_class.new
|
217
|
+
@status = 422
|
218
|
+
puts "came here."
|
219
|
+
resource.errors.add(:additional_login_param,"Either otp or additional login param is incorrect, try resend otp")
|
220
|
+
end
|
221
|
+
|
222
|
+
#puts @resource.attributes.to_s
|
223
|
+
@auth_user = resource
|
224
|
+
respond_to do |format|
|
225
|
+
format.json {render json: {:intent_verification_message => intent_verification_message, :errors => resource.errors.full_messages, :resource => resource.as_json({:otp_verification => true}), :verified => (resource.additional_login_param_confirmed? && resource.errors.empty?)}, status: @status}
|
226
|
+
format.html {render "auth/confirmations/otp_status_result.html.erb"}
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
def permitted_params
|
233
|
+
if action_name == "resend_sms_otp"
|
234
|
+
##the resource_collection_path => pluralized downcased model name eg. users
|
235
|
+
params.permit(:intent,:resource,:api_key,:current_app_id)
|
236
|
+
else
|
237
|
+
##post_verification_intent => "reset_password" OR "unlock"
|
238
|
+
##had to add email here because in the passwords form, and the unlocks form, we have to serve either additional_login_param or email, so in order to make it work with the existing devise controllers decided to keep the param coming in as email, and sending errors back also on the email attribute,[all this is only relevant to the send_sms_otp action]
|
239
|
+
##it will take all the models provided in the authentication_keys in the Auth configuration file.
|
240
|
+
filters = []
|
241
|
+
Auth.configuration.auth_resources.keys.each do |model|
|
242
|
+
filters << {model.downcase.to_sym => [:additional_login_param, :otp, :email, :_id]}
|
243
|
+
end
|
244
|
+
filters << [:intent, :resource,:api_key,:current_app_id]
|
245
|
+
filters << "g-recaptcha-response".to_sym
|
246
|
+
params.permit(filters)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
|
251
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Auth::Concerns::Shopping::CartControllerConcern
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
##if an id is provided in the permitted params then tries to find that in the database, and makes a new cart item out of it.
|
10
|
+
#if no id is provided then creates a new cart_item from the permitted params, but excluding the id key.
|
11
|
+
#if a collection i.e plural resources is present in the permitted_params and its also there in our auth resources, then create a resource class and resource symbol out of it and assign resource as in the comments.
|
12
|
+
def initialize_vars
|
13
|
+
|
14
|
+
instantiate_shopping_classes
|
15
|
+
|
16
|
+
@auth_shopping_cart_params = permitted_params.fetch(:cart,{})
|
17
|
+
|
18
|
+
@auth_shopping_cart = params[:id] ? @auth_shopping_cart_class.find_self(params[:id],current_signed_in_resource) : @auth_shopping_cart_class.new(@auth_shopping_cart_params)
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
##override the as_json for cart_item, to show errors if there are any, otherwise just the id.
|
23
|
+
def show
|
24
|
+
|
25
|
+
not_found if @auth_shopping_cart.nil?
|
26
|
+
@auth_shopping_cart.prepare_cart
|
27
|
+
@auth_shopping_cart_items = @auth_shopping_cart.cart_items
|
28
|
+
|
29
|
+
respond_with @auth_shopping_cart
|
30
|
+
end
|
31
|
+
|
32
|
+
##responds with an array of the created cart items.
|
33
|
+
##resource id is set only during create, never during update.
|
34
|
+
def create
|
35
|
+
check_for_create(@auth_shopping_cart)
|
36
|
+
@auth_shopping_cart = add_owner_and_signed_in_resource(@auth_shopping_cart)
|
37
|
+
|
38
|
+
@auth_shopping_cart.save
|
39
|
+
@auth_shopping_cart.prepare_cart
|
40
|
+
respond_with @auth_shopping_cart
|
41
|
+
end
|
42
|
+
|
43
|
+
## always returns an empty array.
|
44
|
+
def update
|
45
|
+
check_for_update(@auth_shopping_cart)
|
46
|
+
|
47
|
+
@auth_shopping_cart.assign_attributes(@auth_shopping_cart_params)
|
48
|
+
|
49
|
+
@auth_shopping_cart = add_owner_and_signed_in_resource(@auth_shopping_cart)
|
50
|
+
|
51
|
+
puts 'the auth shopping cart signed in resource is:'
|
52
|
+
puts @auth_shopping_cart.signed_in_resource
|
53
|
+
|
54
|
+
@auth_shopping_cart.save
|
55
|
+
@auth_shopping_cart.prepare_cart
|
56
|
+
respond_with @auth_shopping_cart
|
57
|
+
end
|
58
|
+
|
59
|
+
##will respond with nothing, or an array of cart_items that were removed, or whatever errors they have for not remvoing them.
|
60
|
+
def destroy
|
61
|
+
check_for_destroy(@auth_shopping_cart)
|
62
|
+
@auth_shopping_cart.prepare_cart
|
63
|
+
@auth_shopping_cart.destroy
|
64
|
+
respond_with @auth_shopping_cart
|
65
|
+
end
|
66
|
+
|
67
|
+
## returns all the carts of the user.
|
68
|
+
## basically all his orders.
|
69
|
+
def index
|
70
|
+
@auth_shopping_carts = @auth_shopping_cart_class.where(:resource_id => lookup_resource.id.to_s)
|
71
|
+
respond_with @auth_shopping_carts
|
72
|
+
end
|
73
|
+
|
74
|
+
def new
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
def edit
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
############################################################
|
84
|
+
##
|
85
|
+
##
|
86
|
+
## GIVEN product ids, first create cart items, then CREATE CART
|
87
|
+
##
|
88
|
+
## USED FROM THE DISCOUNT_OBJECT_SHOW PAGE
|
89
|
+
##
|
90
|
+
############################################################
|
91
|
+
|
92
|
+
def bulk_create
|
93
|
+
## first create cart items.
|
94
|
+
## this will bypass the controller and create problems.
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
##override this def in your controller, and add attributes to transaction:[], each of the attributes in the transaction key will be cycled through, and if those fields exist on the cart_item, then they will be set.
|
101
|
+
def permitted_params
|
102
|
+
params.permit({cart: [:discount_id,:name, :notes, {:add_cart_item_ids => []},{:remove_cart_item_ids => []}]},:id)
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module Auth::Concerns::Shopping::CartItemControllerConcern
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
|
7
|
+
## to be able to initialize a cart item from a product
|
8
|
+
## inside the create_multiple def.
|
9
|
+
include Auth::Shopping::Products::ProductsHelper
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
##if an id is provided in the permitted params then tries to find that in the database, and makes a new cart item out of it.
|
16
|
+
#if no id is provided then creates a new cart_item from the permitted params, but excluding the id key.
|
17
|
+
#if a collection i.e plural resources is present in the permitted_params and its also there in our auth resources, then create a resource class and resource symbol out of it and assign resource as in the comments.
|
18
|
+
def initialize_vars
|
19
|
+
instantiate_shopping_classes
|
20
|
+
|
21
|
+
@auth_shopping_discount_object_params = permitted_params.fetch(:discount,{})
|
22
|
+
|
23
|
+
|
24
|
+
if !@auth_shopping_discount_object_params.blank?
|
25
|
+
|
26
|
+
@auth_shopping_discount = params[:id] ? @auth_shopping_discount_class.find(params[:id]) : @auth_shopping_discount_class.new(@auth_shopping_discount_object_params)
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
@auth_shopping_cart_item_params = permitted_params.fetch(:cart_item,{})
|
31
|
+
@auth_shopping_cart_item = params[:id] ? @auth_shopping_cart_item_class.find_self(params[:id],current_signed_in_resource) : @auth_shopping_cart_item_class.new(@auth_shopping_cart_item_params)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
##expects the product id, resource_id is the logged in resource, and quantity
|
37
|
+
def create
|
38
|
+
##ensure that the cart item is new
|
39
|
+
|
40
|
+
check_for_create(@auth_shopping_cart_item)
|
41
|
+
@auth_shopping_cart_item = add_owner_and_signed_in_resource(@auth_shopping_cart_item)
|
42
|
+
|
43
|
+
@auth_shopping_cart_item.save
|
44
|
+
|
45
|
+
respond_with @auth_shopping_cart_item
|
46
|
+
end
|
47
|
+
|
48
|
+
##only permits the quantity to be changed, transaction id is internally assigned and can never be changed by the external world.
|
49
|
+
def update
|
50
|
+
check_for_update(@auth_shopping_cart_item)
|
51
|
+
@auth_shopping_cart_item.assign_attributes(@auth_shopping_cart_item_params)
|
52
|
+
@auth_shopping_cart_item = add_owner_and_signed_in_resource(@auth_shopping_cart_item)
|
53
|
+
@auth_shopping_cart_item.save
|
54
|
+
puts @auth_shopping_cart_item.errors.full_messages.to_s
|
55
|
+
respond_with @auth_shopping_cart_item
|
56
|
+
end
|
57
|
+
|
58
|
+
def show
|
59
|
+
not_found if @auth_shopping_cart_item.nil?
|
60
|
+
respond_with @auth_shopping_cart_item
|
61
|
+
end
|
62
|
+
|
63
|
+
##should show those cart items which do not have a parent_id.
|
64
|
+
##since these are the pending cart items.
|
65
|
+
##all remaining cart items have already been assigned to carts
|
66
|
+
def index
|
67
|
+
@auth_shopping_cart_items = @auth_shopping_cart_item_class.find_cart_items({:resource => lookup_resource}).page 1
|
68
|
+
respond_with @auth_shopping_cart_items
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
##can be removed.
|
73
|
+
##responds with 204, and empty response body, if all is ok.
|
74
|
+
def destroy
|
75
|
+
not_found if @auth_shopping_cart_item.nil?
|
76
|
+
puts "the accepted is:"
|
77
|
+
puts @auth_shopping_cart_item.accepted.to_s
|
78
|
+
@auth_shopping_cart_item.destroy
|
79
|
+
respond_with @auth_shopping_cart_item
|
80
|
+
end
|
81
|
+
|
82
|
+
############################################################
|
83
|
+
##
|
84
|
+
##
|
85
|
+
## BULK ITEM CREATE.
|
86
|
+
## This is utilized to create multiple cart items, first ,
|
87
|
+
## then redirects to create a cart, with those cart items.
|
88
|
+
##
|
89
|
+
##
|
90
|
+
############################################################
|
91
|
+
def create_multiple
|
92
|
+
#puts "came to create multiple."
|
93
|
+
#puts "params are:"
|
94
|
+
#puts params.to_s
|
95
|
+
@auth_shopping_cart_items = []
|
96
|
+
@auth_shopping_cart = @auth_shopping_cart_class.new(:add_cart_item_ids => [], :remove_cart_item_ids => [])
|
97
|
+
#puts "auth shopping discount is:"
|
98
|
+
#puts @auth_shopping_discount.to_s
|
99
|
+
@auth_shopping_cart.discount_id = @auth_shopping_discount.id.to_s
|
100
|
+
|
101
|
+
|
102
|
+
#puts "is it is a new record"
|
103
|
+
#puts @auth_shopping_discount.new_record?
|
104
|
+
unless @auth_shopping_discount.new_record?
|
105
|
+
@auth_shopping_discount.product_ids.each do |product_id|
|
106
|
+
|
107
|
+
if product = @auth_shopping_product_class.find(product_id)
|
108
|
+
|
109
|
+
cart_item = create_cart_item_from_product(product)
|
110
|
+
cart_item = add_owner_and_signed_in_resource(cart_item)
|
111
|
+
|
112
|
+
if cart_item.save == true
|
113
|
+
@auth_shopping_cart_items << cart_item
|
114
|
+
@auth_shopping_cart.add_cart_item_ids << cart_item.id.to_s
|
115
|
+
else
|
116
|
+
puts "the errors trying to save the item"
|
117
|
+
puts cart_item.errors.full_messages.to_s
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
else
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
## this permitted params is overridden in the dummy app, and as a result throws unpermitted parameters for the daughter app parameters, even though they are subsequently permitted, since super is called first.
|
131
|
+
def permitted_params
|
132
|
+
|
133
|
+
|
134
|
+
if action_name.to_s == "update" && !current_signed_in_resource.is_admin?
|
135
|
+
|
136
|
+
|
137
|
+
params.permit({cart_item: [:discount_code,:quantity]},:id)
|
138
|
+
|
139
|
+
elsif action_name.to_s == "create_multiple"
|
140
|
+
params.permit({discount: [:id, {:product_ids => []}]})
|
141
|
+
else
|
142
|
+
|
143
|
+
params.permit({cart_item: [:product_id,:discount_code,:quantity]},:id)
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|