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,193 @@
|
|
1
|
+
module Auth::Concerns::DeviseConcern
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
|
7
|
+
#skip_before_action :verify_authenticity_token, if: :is_json_request?
|
8
|
+
protect_from_forgery with: :null_session
|
9
|
+
attr_accessor :m_client
|
10
|
+
end
|
11
|
+
|
12
|
+
##returns true if the recaptcha is not specified in the configuration
|
13
|
+
##returns true if the recaptcha is valid.
|
14
|
+
##expects the parameter 'g-recaptcha-response' in the params hash
|
15
|
+
##if the request is json, and has the header os-android, then it will use the android_recaptcha_api_key as the secret key, otherwise will use the default recaptch_secret key that should have been configured in the pre-initializer.
|
16
|
+
##it is currently being called in the registrations_controller on create and update, and in the otp action send_sms_otp,verify_sms_otp.
|
17
|
+
##so all these are protected by recaptcha, but not on iphone.
|
18
|
+
def check_recaptcha
|
19
|
+
|
20
|
+
return true unless Auth.configuration.recaptcha
|
21
|
+
|
22
|
+
recaptcha_options = {}
|
23
|
+
if is_json_request?
|
24
|
+
#puts "is json request."
|
25
|
+
return true unless request.headers["OS-ANDROID"]
|
26
|
+
#puts "android is there in headers."
|
27
|
+
not_found("recaptcha validation error") unless Auth.configuration.third_party_api_keys[:android_recaptcha_secret_key]
|
28
|
+
#puts "android key is there in config."
|
29
|
+
recaptcha_options[:secret_key] = Auth.configuration.third_party_api_keys[:android_recaptcha_secret_key]
|
30
|
+
end
|
31
|
+
#puts "recaptcha_options are : #{recaptcha_options}"
|
32
|
+
not_found("recaptcha validation error") unless verify_recaptcha(recaptcha_options)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def is_omniauth_callback?
|
37
|
+
controller_name == "omniauth_callbacks"
|
38
|
+
end
|
39
|
+
|
40
|
+
def ignore_json_request
|
41
|
+
if is_json_request?
|
42
|
+
render :nothing => true, :status => 406 and return
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
##SHOULD WE OR NOT DELETE THE CLIENT AND REDIRECT URL?
|
48
|
+
##this was relevant only in the case of oauth visits
|
49
|
+
##suppose someone comes from remote with redir + client.
|
50
|
+
##these get set and stored in the session
|
51
|
+
##then he goes to oauth and comes back.
|
52
|
+
##by this time the instance variables are no more
|
53
|
+
##so we fall back on the session variables and redirect him
|
54
|
+
##the only worry was , that what if someone prompts the user to go to wordjelly with a redirect url of their choice.
|
55
|
+
##so what i do here right now is clear the instance redirect and client vars.
|
56
|
+
##then i set the client, if necessary from the session
|
57
|
+
##but while doing set_redirect_url i give first pref to the redir from the params, and then CHECK whether that is valid against the client already from the sessin.
|
58
|
+
##so basically they cannot be redirected to any url that is not stored against the client.
|
59
|
+
##so they can at the worst be redirected only to a url which was provided during client creation.
|
60
|
+
##so there is no need to delete the client from the session at every request, except if it is a json request.
|
61
|
+
def clear_client_and_redirect_url
|
62
|
+
session.delete('omniauth.state')
|
63
|
+
if is_json_request?
|
64
|
+
session.delete("client")
|
65
|
+
session.delete("redirect_url")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def set_client
|
70
|
+
|
71
|
+
if session[:client]
|
72
|
+
|
73
|
+
|
74
|
+
return true
|
75
|
+
|
76
|
+
else
|
77
|
+
puts "params are: #{params.to_s}"
|
78
|
+
puts params[:state]
|
79
|
+
puts JSON.is_json?(params[:state])
|
80
|
+
puts "---- end --- "
|
81
|
+
state = nil
|
82
|
+
api_key = nil
|
83
|
+
current_app_id = nil
|
84
|
+
path = nil
|
85
|
+
if params[:state] && JSON.is_json?(params[:state])
|
86
|
+
state = JSON.parse(params[:state])
|
87
|
+
end
|
88
|
+
|
89
|
+
if state
|
90
|
+
api_key = state["api_key"]
|
91
|
+
current_app_id = state["current_app_id"]
|
92
|
+
path = state["path"]
|
93
|
+
elsif params[:api_key] && params[:current_app_id]
|
94
|
+
puts "the params api key and current app id are there."
|
95
|
+
api_key = params[:api_key]
|
96
|
+
current_app_id = params[:current_app_id]
|
97
|
+
else
|
98
|
+
end
|
99
|
+
|
100
|
+
if api_key.nil? || current_app_id.nil?
|
101
|
+
|
102
|
+
else
|
103
|
+
puts "api key:#{api_key}"
|
104
|
+
puts "current app id: #{current_app_id}"
|
105
|
+
puts "path is: #{path}"
|
106
|
+
|
107
|
+
if session[:client] = Auth::Client.find_valid_api_key_and_app_id(api_key, current_app_id)
|
108
|
+
|
109
|
+
puts "found valid clinet."
|
110
|
+
request.env["omniauth.model"] = path
|
111
|
+
|
112
|
+
self.m_client = Auth::Client.find_valid_api_key_and_app_id(api_key, current_app_id)
|
113
|
+
|
114
|
+
return true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
return false
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def is_json_request?
|
122
|
+
|
123
|
+
return (request.format.symbol == :json) ? true : false
|
124
|
+
end
|
125
|
+
|
126
|
+
def protect_json_request
|
127
|
+
##should block any put action on the user
|
128
|
+
##and should render an error saying please do this on the server.
|
129
|
+
if is_json_request?
|
130
|
+
puts "it is a json request."
|
131
|
+
if action_name == "otp_verification_result"
|
132
|
+
##we let this action pass because, we make json ajax requests
|
133
|
+
##from the web ui to this endpoint, and anyway it does
|
134
|
+
##not return anything sensitive.
|
135
|
+
#puts "action name is otp verification result."
|
136
|
+
else
|
137
|
+
#puts "action name is something else."
|
138
|
+
if session[:client].nil?
|
139
|
+
puts "cient is nil so rendering nothing."
|
140
|
+
render :nothing => true , :status => :unauthorized
|
141
|
+
else
|
142
|
+
#puts "client is not nil"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def set_redirect_url
|
149
|
+
|
150
|
+
# puts "the params redirect url is: #{params[:redirect_url]}"
|
151
|
+
# puts "the session redirect url is: #{session[:redirect_url]}"
|
152
|
+
redir_url = params[:redirect_url].nil? ? session[:redirect_url] : params[:redirect_url]
|
153
|
+
|
154
|
+
#puts "redir url was: #{redir_url}"
|
155
|
+
|
156
|
+
#puts "session[:client] is: #{session[:client]}"
|
157
|
+
|
158
|
+
#puts "session[:client].redirect urls"
|
159
|
+
#puts session[:client].redirect_urls
|
160
|
+
|
161
|
+
#puts "does it contain the redirect url."
|
162
|
+
#puts session[:client].contains_redirect_url?(redir_url)
|
163
|
+
cli = session[:client]
|
164
|
+
cli = Auth::Client.new(session[:client]) if session[:client].is_a? Hash
|
165
|
+
|
166
|
+
if redir_url && session[:client] && cli.contains_redirect_url?(redir_url) && !(is_json_request?)
|
167
|
+
|
168
|
+
session[:redirect_url] = redir_url
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
def do_before_request
|
175
|
+
puts "came to do before request."
|
176
|
+
clear_client_and_redirect_url
|
177
|
+
|
178
|
+
set_client
|
179
|
+
|
180
|
+
set_redirect_url
|
181
|
+
|
182
|
+
protect_json_request
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
##used only in render, redirect in DeviseController.class_eval
|
187
|
+
def current_resource(resource)
|
188
|
+
send("current_#{resource.class.name.underscore.downcase}")
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
end
|
@@ -0,0 +1,310 @@
|
|
1
|
+
module Auth::Concerns::OmniConcern
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
prepend_before_action :set_devise_mapping_for_omniauth, only: [:omni_common]
|
7
|
+
prepend_before_action :do_before_request, only: [:omni_common]
|
8
|
+
attr_accessor :resource
|
9
|
+
helper_method :omniauth_failed_path_for
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
def set_devise_mapping_for_omniauth
|
16
|
+
model = nil
|
17
|
+
if !request.env["omniauth.model"].blank?
|
18
|
+
puts "the request env is:"
|
19
|
+
puts request.env["omniauth.model"]
|
20
|
+
request.env["omniauth.model"].scan(/omniauth\/(?<model>[a-zA-Z]+)\//) do |ll|
|
21
|
+
jj = Regexp.last_match
|
22
|
+
model = jj[:model]
|
23
|
+
end
|
24
|
+
model = model.singularize
|
25
|
+
request.env["devise.mapping"] = Devise.mappings[model.to_sym]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def passthru
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def failure
|
34
|
+
f = failure_message
|
35
|
+
flash[:omniauth_error] = f.blank? ? notice : f
|
36
|
+
respond_to do |format|
|
37
|
+
format.json { render json: {"failure_message" => flash[:omniauth_error]}, status: :unprocessible_entity}
|
38
|
+
format.html { render "auth/omniauth_callbacks/failure.html.erb" }
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def get_omni_hash
|
45
|
+
request.env["omniauth.auth"]
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
def failed_strategy
|
51
|
+
request.respond_to?(:get_header) ? request.get_header("omniauth.error.strategy") : env["omniauth.error.strategy"]
|
52
|
+
end
|
53
|
+
|
54
|
+
def failure_message
|
55
|
+
exception = request.respond_to?(:get_header) ? request.get_header("omniauth.error") : env["omniauth.error"]
|
56
|
+
error = exception.error_reason if exception.respond_to?(:error_reason)
|
57
|
+
error ||= exception.error if exception.respond_to?(:error)
|
58
|
+
error ||= (request.respond_to?(:get_header) ? request.get_header("omniauth.error.type") : env["omniauth.error.type"]).to_s
|
59
|
+
|
60
|
+
error.to_s.humanize if error
|
61
|
+
end
|
62
|
+
|
63
|
+
def after_omniauth_failure_path_for(scope)
|
64
|
+
new_session_path(scope)
|
65
|
+
end
|
66
|
+
|
67
|
+
def omniauth_failed_path_for(res)
|
68
|
+
omniauth_failure_path(res)
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def translation_scope
|
73
|
+
'devise.omniauth_callbacks'
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
def update_identity_information(identity_info,provider)
|
78
|
+
@resource.identities.map{|i|
|
79
|
+
if(i["provider"] && i["provider"] == provider)
|
80
|
+
i["access_token"] = identity_info["access_token"]
|
81
|
+
i["token_expires_at"] = identity_info["token_expires_at"]
|
82
|
+
end
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
## @return[Boolean] : true if the update was successfull, false otherwise
|
87
|
+
## method from_view is taken from Auth::ApplicationController
|
88
|
+
def update_access_token_and_expires_at(existing_oauth_resources,resource_klazz,identity_info,provider)
|
89
|
+
@resource = from_view(existing_oauth_resources,resource_klazz)
|
90
|
+
@resource.m_client = self.m_client
|
91
|
+
##identity_info should be a key -> value hash,
|
92
|
+
update_identity_information(identity_info,provider)
|
93
|
+
|
94
|
+
@resource.versioned_update({"identities" => 1})
|
95
|
+
|
96
|
+
if @resource.op_success
|
97
|
+
|
98
|
+
sign_in @resource
|
99
|
+
|
100
|
+
true
|
101
|
+
|
102
|
+
else
|
103
|
+
|
104
|
+
|
105
|
+
false
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
############################################################
|
112
|
+
## Working:
|
113
|
+
## First searches for an account with the oauth identity.
|
114
|
+
## Found : tries to update it with a new access token, failing update -> retursn failure.
|
115
|
+
## Not Found : tries to create an account with the email of the oauth identity, and identities = [oauth_identity]
|
116
|
+
## if op_success : return success
|
117
|
+
##
|
118
|
+
## elsif matched_count == 1 : it means an account already exists with this email . Here there are two possibilities.
|
119
|
+
## a. The earlier account was created by using another oauth provider -> in this case its version will have been set as '1', and we now execute a versioned_update -> pushing in the identity of the other oauth account. Thus two oauth providers are merged into one if they share the same email address.
|
120
|
+
## b. the earlier account was created by the normal sign up process: in this case its version will be '0', the versioned updated to push in the oauth identity will fail. If the earlier account is a confirmed account, error will say accoutn in user, if not, then error will say, "there was some errro..."
|
121
|
+
##
|
122
|
+
## else
|
123
|
+
## there was no matched count, and op failed, so we return failure.
|
124
|
+
##
|
125
|
+
##
|
126
|
+
## ** To prevent oauth account merger, set the configuration option :prevent_oauth_merger to true, it is false by default.
|
127
|
+
##
|
128
|
+
############################################################
|
129
|
+
def omni_common
|
130
|
+
|
131
|
+
success = false
|
132
|
+
failure = false
|
133
|
+
failure_message = "There was an error processing your request"
|
134
|
+
|
135
|
+
begin
|
136
|
+
|
137
|
+
model_class = request.env["devise.mapping"]
|
138
|
+
if model_class.nil?
|
139
|
+
|
140
|
+
redirect_to omniauth_failed_path_for("no_resource"), :notice => "No resource was specified in the omniauth callback request." and return
|
141
|
+
else
|
142
|
+
resource_klazz = request.env["devise.mapping"].to
|
143
|
+
|
144
|
+
omni_hash = get_omni_hash
|
145
|
+
|
146
|
+
puts "the omni hash is:"
|
147
|
+
puts omni_hash
|
148
|
+
|
149
|
+
identity = Auth::Identity.new.build_from_omnihash(omni_hash)
|
150
|
+
|
151
|
+
##this index is used for the first query during oauth, to check whether the user already has registered using oauth with us.
|
152
|
+
puts "identity is:"
|
153
|
+
puts identity
|
154
|
+
existing_oauth_resources =
|
155
|
+
resource_klazz.collection.find(
|
156
|
+
{"identities" =>
|
157
|
+
{"$elemMatch" =>
|
158
|
+
{"provider" => identity.provider, "uid" => identity.uid}
|
159
|
+
}
|
160
|
+
})
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
if existing_oauth_resources.count == 1
|
165
|
+
|
166
|
+
puts "found matching identity."
|
167
|
+
|
168
|
+
if update_access_token_and_expires_at(existing_oauth_resources,resource_klazz,identity.attributes.except("_id","provider","uid"),identity.provider)
|
169
|
+
puts "updated access token."
|
170
|
+
success = true
|
171
|
+
#respond_with @resource, location: after_sign_in_path_for(@resource)
|
172
|
+
else
|
173
|
+
puts "failed to update access token."
|
174
|
+
success = false
|
175
|
+
#redirect_to omniauth_failed_path_for(resource_klazz.name),:notice => "Failed to update the acceess token and token expires at"
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
elsif signed_in?
|
181
|
+
|
182
|
+
puts("it is a current user trying to sign up with oauth.")
|
183
|
+
|
184
|
+
after_sign_in_path_for(current_res)
|
185
|
+
|
186
|
+
else
|
187
|
+
|
188
|
+
puts("no such user exists, trying to create a new user by merging the fields.")
|
189
|
+
|
190
|
+
@resource = resource_klazz.new
|
191
|
+
@resource.email = identity.email
|
192
|
+
@resource.password = Devise.friendly_token(20)
|
193
|
+
@resource.regenerate_token
|
194
|
+
@resource.identities = [identity.attributes.except("_id")]
|
195
|
+
if @resource.respond_to?(:confirmed_at)
|
196
|
+
@resource.confirmed_at = Time.now.utc
|
197
|
+
end
|
198
|
+
|
199
|
+
## skip_email_unique_validation is set to true in omni_concern in the situation:
|
200
|
+
##1.there is no user with the given identity.
|
201
|
+
## however it is possible that a user with this email exists.
|
202
|
+
## in that case, if we try to do versioned_create, then the prepare_insert block in mongoid_versioned_atomic, runs validations. these include, checking if the email is unique, and in this case, if a user with this email already exists, then the versioned_create doesnt happen at all. We don't want to first check if there is already an account with this email, and in another step then try to do a versioned_update, because in the time in between another user could be created. So instead we simply just set #skip_email_unique_validation to true, and as a result the unique validation is skipped.
|
203
|
+
@resource.skip_email_unique_validation = true
|
204
|
+
|
205
|
+
|
206
|
+
@resource.m_client = self.m_client
|
207
|
+
|
208
|
+
## end.
|
209
|
+
@resource.versioned_create({"email" => @resource.email})
|
210
|
+
##reset so that no other issues crop up later.
|
211
|
+
@resource.skip_email_unique_validation = false
|
212
|
+
|
213
|
+
#puts "@resource email is:"
|
214
|
+
#puts @resource.email.to_s
|
215
|
+
|
216
|
+
if @resource.op_success
|
217
|
+
puts "create was successfull"
|
218
|
+
sign_in @resource
|
219
|
+
puts "signed in resource."
|
220
|
+
#respond_with @resource, location: after_sign_in_path_for(@resource)
|
221
|
+
success = true
|
222
|
+
#respond_to do |format|
|
223
|
+
# format.html { redirect_to after_sign_in_path_for(@resource) and return}
|
224
|
+
# format.json { render json: @resource, status: :updated and return}
|
225
|
+
#end
|
226
|
+
puts "came after the response."
|
227
|
+
|
228
|
+
##do the update.
|
229
|
+
elsif @resource.matched_count == 1
|
230
|
+
#puts "found such a resource."
|
231
|
+
|
232
|
+
## this means a resource with this email account was found.
|
233
|
+
## if the account is not confirmed, then we can push the identity.
|
234
|
+
## and we can reset the password.
|
235
|
+
|
236
|
+
@resource = resource_klazz.where(:email => @resource.email).first
|
237
|
+
@resource.m_client = self.m_client
|
238
|
+
|
239
|
+
if @resource.confirmed?
|
240
|
+
failure_message = "That email is in use by another account"
|
241
|
+
end
|
242
|
+
|
243
|
+
if Auth.configuration.prevent_oauth_merger == true
|
244
|
+
|
245
|
+
success = false
|
246
|
+
|
247
|
+
else
|
248
|
+
|
249
|
+
@resource.identities.push(identity.attributes.except("_id"))
|
250
|
+
|
251
|
+
@resource.versioned_update({"identities" => 1})
|
252
|
+
|
253
|
+
if @resource.op_success
|
254
|
+
puts "succeeded and signed in user."
|
255
|
+
sign_in @resource
|
256
|
+
|
257
|
+
success = true
|
258
|
+
|
259
|
+
#respond_with @resource, location: after_sign_in_path_for(@resource)
|
260
|
+
|
261
|
+
else
|
262
|
+
puts "op success failure"
|
263
|
+
success = false
|
264
|
+
#redirect_to omniauth_failed_path_for(resource_klazz.name),:notice => "Failed to create new identity"
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
268
|
+
|
269
|
+
else
|
270
|
+
|
271
|
+
puts "resource create failed."
|
272
|
+
puts @resource.errors.full_messages.to_s
|
273
|
+
success = false
|
274
|
+
#redirect_to omniauth_failed_path_for(resource_klazz.name),:notice => "Failed to create new identity"
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
rescue => e
|
286
|
+
puts "SOME OTHER ERROR"
|
287
|
+
puts e.to_s
|
288
|
+
puts e.backtrace
|
289
|
+
redirect_to omniauth_failed_path_for("error"), :notice => "error" and return
|
290
|
+
success = false
|
291
|
+
end
|
292
|
+
|
293
|
+
puts "Success is :#{success.to_s}"
|
294
|
+
|
295
|
+
|
296
|
+
respond_to do |format|
|
297
|
+
if success == true
|
298
|
+
format.html { redirect_to after_sign_in_path_for(@resource) and return}
|
299
|
+
format.json { render json: @resource, status: :updated and return}
|
300
|
+
else
|
301
|
+
#@resource.errors.add(:_id,"failed")
|
302
|
+
format.html { redirect_to omniauth_failed_path_for(failure_message), :notice => failure_message and return}
|
303
|
+
format.json { render json: {:errors => failure_message}, status: :unprocessible_entity and return}
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
|
308
|
+
end
|
309
|
+
|
310
|
+
end
|