wordjelly-auth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +35 -0
  5. data/app/assets/images/auth/activity.jpg +0 -0
  6. data/app/assets/images/auth/facebook.svg +1 -0
  7. data/app/assets/images/auth/google_oauth2.svg +1 -0
  8. data/app/assets/images/auth/js_pic3.jpg +0 -0
  9. data/app/assets/images/auth/profile.jpg +0 -0
  10. data/app/assets/javascripts/auth/admin_create_users.js +2 -0
  11. data/app/assets/javascripts/auth/application.js +20 -0
  12. data/app/assets/javascripts/auth/auth_dependencies.js +12 -0
  13. data/app/assets/javascripts/auth/auth_modals_and_navbar.js +218 -0
  14. data/app/assets/javascripts/auth/clients.js +2 -0
  15. data/app/assets/javascripts/auth/search.js +2 -0
  16. data/app/assets/javascripts/auth/shopping/discounts.js +2 -0
  17. data/app/assets/javascripts/auth/users/profiles.js +188 -0
  18. data/app/assets/stylesheets/auth/admin_create_users.css +4 -0
  19. data/app/assets/stylesheets/auth/application.scss +14 -0
  20. data/app/assets/stylesheets/auth/auth_default_css.scss +13 -0
  21. data/app/assets/stylesheets/auth/common-styles.scss +579 -0
  22. data/app/assets/stylesheets/auth/overrides.scss +26 -0
  23. data/app/assets/stylesheets/auth/search.css +4 -0
  24. data/app/assets/stylesheets/auth/shopping/discounts.css +4 -0
  25. data/app/assets/stylesheets/auth/users/profiles.scss +40 -0
  26. data/app/assets/stylesheets/scaffold.css +56 -0
  27. data/app/controllers/auth/admin_create_users_controller.rb +89 -0
  28. data/app/controllers/auth/application_controller.rb +97 -0
  29. data/app/controllers/auth/clients_controller.rb +105 -0
  30. data/app/controllers/auth/concerns/activity_controller_concern.rb +32 -0
  31. data/app/controllers/auth/concerns/devise_concern.rb +193 -0
  32. data/app/controllers/auth/concerns/omni_concern.rb +310 -0
  33. data/app/controllers/auth/concerns/otp_concern.rb +251 -0
  34. data/app/controllers/auth/concerns/shopping/cart_controller_concern.rb +105 -0
  35. data/app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb +150 -0
  36. data/app/controllers/auth/concerns/shopping/discount_controller_concern.rb +97 -0
  37. data/app/controllers/auth/concerns/shopping/pay_u_money_controller_concern.rb +38 -0
  38. data/app/controllers/auth/concerns/shopping/payment_controller_concern.rb +101 -0
  39. data/app/controllers/auth/concerns/shopping/product_controller_concern.rb +68 -0
  40. data/app/controllers/auth/concerns/token_concern.rb +187 -0
  41. data/app/controllers/auth/confirmations_controller.rb +3 -0
  42. data/app/controllers/auth/mailgun_controller.rb +8 -0
  43. data/app/controllers/auth/omniauth_callbacks_controller.rb +6 -0
  44. data/app/controllers/auth/passwords_controller.rb +4 -0
  45. data/app/controllers/auth/profiles_controller.rb +156 -0
  46. data/app/controllers/auth/registrations_controller.rb +99 -0
  47. data/app/controllers/auth/search_controller.rb +61 -0
  48. data/app/controllers/auth/sessions_controller.rb +20 -0
  49. data/app/controllers/auth/shopping/cart_items_controller.rb +14 -0
  50. data/app/controllers/auth/shopping/carts_controller.rb +13 -0
  51. data/app/controllers/auth/shopping/discounts_controller.rb +19 -0
  52. data/app/controllers/auth/shopping/payments_controller.rb +13 -0
  53. data/app/controllers/auth/shopping/products_controller.rb +17 -0
  54. data/app/controllers/auth/shopping/shopping_controller.rb +86 -0
  55. data/app/controllers/auth/unlocks_controller.rb +3 -0
  56. data/app/controllers/auth/webhooks_controller.rb +3 -0
  57. data/app/helpers/auth/admin_create_users_helper.rb +2 -0
  58. data/app/helpers/auth/application_helper.rb +136 -0
  59. data/app/helpers/auth/clients_helper.rb +4 -0
  60. data/app/helpers/auth/resource_helper.rb +10 -0
  61. data/app/helpers/auth/search_helper.rb +2 -0
  62. data/app/helpers/auth/shopping/cart_items/cart_items_helper.rb +29 -0
  63. data/app/helpers/auth/shopping/carts/carts_helper.rb +25 -0
  64. data/app/helpers/auth/shopping/discounts/discounts_helper.rb +39 -0
  65. data/app/helpers/auth/shopping/payments/pay_u_money_helper.rb +56 -0
  66. data/app/helpers/auth/shopping/payments/payments_helper.rb +54 -0
  67. data/app/helpers/auth/shopping/products/products_helper.rb +52 -0
  68. data/app/helpers/auth/shopping/shopping_helper.rb +3 -0
  69. data/app/helpers/auth/users/profiles_helper.rb +12 -0
  70. data/app/jobs/otp_job.rb +92 -0
  71. data/app/mailers/application_mailer.rb +4 -0
  72. data/app/mailers/auth/notifier.rb +9 -0
  73. data/app/models/auth/admin_create_user.rb +3 -0
  74. data/app/models/auth/client.rb +52 -0
  75. data/app/models/auth/concerns/activity_concern.rb +112 -0
  76. data/app/models/auth/concerns/chief_model_concern.rb +73 -0
  77. data/app/models/auth/concerns/es_concern.rb +21 -0
  78. data/app/models/auth/concerns/notification_concern.rb +232 -0
  79. data/app/models/auth/concerns/notification_response_concern.rb +71 -0
  80. data/app/models/auth/concerns/owner_concern.rb +81 -0
  81. data/app/models/auth/concerns/shopping/cart_concern.rb +329 -0
  82. data/app/models/auth/concerns/shopping/cart_item_concern.rb +437 -0
  83. data/app/models/auth/concerns/shopping/discount_concern.rb +482 -0
  84. data/app/models/auth/concerns/shopping/discount_flow.txt +11 -0
  85. data/app/models/auth/concerns/shopping/pay_u_money_concern.rb +184 -0
  86. data/app/models/auth/concerns/shopping/payment_concern.rb +613 -0
  87. data/app/models/auth/concerns/shopping/product_concern.rb +102 -0
  88. data/app/models/auth/concerns/sms_otp_concern.rb +68 -0
  89. data/app/models/auth/concerns/user_concern.rb +788 -0
  90. data/app/models/auth/identity.rb +23 -0
  91. data/app/models/auth/shopping/cart.rb +3 -0
  92. data/app/models/auth/shopping/cart_item.rb +6 -0
  93. data/app/models/auth/shopping/cart_item_payment_result.rb +7 -0
  94. data/app/models/auth/shopping/discount.rb +4 -0
  95. data/app/models/auth/shopping/payment.rb +5 -0
  96. data/app/models/auth/shopping/product.rb +5 -0
  97. data/app/models/auth/user.rb +3 -0
  98. data/app/views/auth/admin_create_users/_admin_actions.html.erb +46 -0
  99. data/app/views/auth/admin_create_users/_form.html.erb +19 -0
  100. data/app/views/auth/admin_create_users/edit.html.erb +6 -0
  101. data/app/views/auth/admin_create_users/index.html.erb +25 -0
  102. data/app/views/auth/admin_create_users/new.html.erb +5 -0
  103. data/app/views/auth/admin_create_users/show.html.erb +8 -0
  104. data/app/views/auth/clients/_form.html.erb +41 -0
  105. data/app/views/auth/clients/edit.html.erb +6 -0
  106. data/app/views/auth/clients/index.html.erb +33 -0
  107. data/app/views/auth/clients/new.html.erb +5 -0
  108. data/app/views/auth/clients/show.html.erb +21 -0
  109. data/app/views/auth/confirmations/_enter_otp.html.erb +27 -0
  110. data/app/views/auth/confirmations/_get_otp_status.html.erb +25 -0
  111. data/app/views/auth/confirmations/_new_otp_input.js.erb +11 -0
  112. data/app/views/auth/confirmations/_resend_otp.js.erb +8 -0
  113. data/app/views/auth/confirmations/_resend_sms_otp.html.erb +18 -0
  114. data/app/views/auth/confirmations/_verify_otp.js.erb +64 -0
  115. data/app/views/auth/confirmations/create.js.erb +8 -0
  116. data/app/views/auth/confirmations/enter_otp.html.erb +7 -0
  117. data/app/views/auth/confirmations/get_otp_status.html.erb +3 -0
  118. data/app/views/auth/confirmations/new.html.erb +1 -0
  119. data/app/views/auth/confirmations/new.js.erb +16 -0
  120. data/app/views/auth/confirmations/otp_status_result.html.erb +20 -0
  121. data/app/views/auth/mailer/confirmation_instructions.html.erb +5 -0
  122. data/app/views/auth/mailer/password_change.html.erb +3 -0
  123. data/app/views/auth/mailer/reset_password_instructions.html.erb +8 -0
  124. data/app/views/auth/mailer/unlock_instructions.html.erb +7 -0
  125. data/app/views/auth/modals/_ajax_error_modal.html.erb +3 -0
  126. data/app/views/auth/modals/_ajax_error_modal_content.html.erb +0 -0
  127. data/app/views/auth/modals/_edit_account_content.html.erb +68 -0
  128. data/app/views/auth/modals/_edit_account_success_content.html.erb +5 -0
  129. data/app/views/auth/modals/_error_notification.html.erb +8 -0
  130. data/app/views/auth/modals/_forgot_password_content.html.erb +18 -0
  131. data/app/views/auth/modals/_forgot_password_success_content.html.erb +8 -0
  132. data/app/views/auth/modals/_login_default_content.html.erb +3 -0
  133. data/app/views/auth/modals/_login_forms.html.erb +13 -0
  134. data/app/views/auth/modals/_login_navigation_options.html.erb +12 -0
  135. data/app/views/auth/modals/_new_otp_input.html.erb +28 -0
  136. data/app/views/auth/modals/_oauth_and_submit.html.erb +21 -0
  137. data/app/views/auth/modals/_recaptcha_tags.html.erb +4 -0
  138. data/app/views/auth/modals/_resend_confirmation_content.html.erb +17 -0
  139. data/app/views/auth/modals/_resend_confirmation_success_content.html.erb +8 -0
  140. data/app/views/auth/modals/_resend_otp.html.erb +23 -0
  141. data/app/views/auth/modals/_resource_errors.js.erb +24 -0
  142. data/app/views/auth/modals/_sign_in_inputs.html.erb +10 -0
  143. data/app/views/auth/modals/_sign_in_needed_modal.html.erb +3 -0
  144. data/app/views/auth/modals/_sign_in_success_content.html.erb +5 -0
  145. data/app/views/auth/modals/_sign_up_inputs.html.erb +9 -0
  146. data/app/views/auth/modals/_sign_up_success_content.html.erb +1 -0
  147. data/app/views/auth/modals/_sign_up_success_inactive_content.html.erb +2 -0
  148. data/app/views/auth/modals/_unlock_content.html.erb +17 -0
  149. data/app/views/auth/modals/_verify_otp.html.erb +1 -0
  150. data/app/views/auth/modals/base_modal/_base.html.erb +25 -0
  151. data/app/views/auth/modals/login.js.erb +120 -0
  152. data/app/views/auth/modals/unlock_success_content.html.erb +8 -0
  153. data/app/views/auth/notifier/_email.html.erb +3 -0
  154. data/app/views/auth/notifier/notification.html.erb +2 -0
  155. data/app/views/auth/notifier/notification.text.erb +1 -0
  156. data/app/views/auth/omniauth_callbacks/failure.html.erb +4 -0
  157. data/app/views/auth/passwords/create.js.erb +12 -0
  158. data/app/views/auth/passwords/edit.html.erb +25 -0
  159. data/app/views/auth/passwords/new.html.erb +16 -0
  160. data/app/views/auth/passwords/new.js.erb +19 -0
  161. data/app/views/auth/profiles/_proxy_resource.html.erb +5 -0
  162. data/app/views/auth/profiles/set_proxy_resource.js.erb +1 -0
  163. data/app/views/auth/profiles/show.html.erb +8 -0
  164. data/app/views/auth/registrations/create.js.erb +40 -0
  165. data/app/views/auth/registrations/edit.html.erb +2 -0
  166. data/app/views/auth/registrations/edit.js.erb +5 -0
  167. data/app/views/auth/registrations/new.html.erb +33 -0
  168. data/app/views/auth/registrations/update.js.erb +47 -0
  169. data/app/views/auth/search/_search_bar.html.erb +11 -0
  170. data/app/views/auth/search/_search_result.html.erb +7 -0
  171. data/app/views/auth/search/_search_results.html.erb +4 -0
  172. data/app/views/auth/search/authenticated_user_search.js.erb +45 -0
  173. data/app/views/auth/search/authenticated_user_search.json +7 -0
  174. data/app/views/auth/sessions/create.js.erb +5 -0
  175. data/app/views/auth/sessions/new.html.erb +4 -0
  176. data/app/views/auth/sessions/new.js.erb +20 -0
  177. data/app/views/auth/shared/_devise_error_messages.html.erb +9 -0
  178. data/app/views/auth/shared/_links.html.erb +25 -0
  179. data/app/views/auth/shared/_object_errors.html.erb +12 -0
  180. data/app/views/auth/shared/_proxy_resource.html.erb +18 -0
  181. data/app/views/auth/shopping/cart_items/_form.html.erb +34 -0
  182. data/app/views/auth/shopping/cart_items/_show_cart_items_collection.html.erb +31 -0
  183. data/app/views/auth/shopping/cart_items/create_multiple.html.erb +6 -0
  184. data/app/views/auth/shopping/cart_items/create_multiple.json.erb +9 -0
  185. data/app/views/auth/shopping/cart_items/edit.html.erb +6 -0
  186. data/app/views/auth/shopping/cart_items/index.html.erb +52 -0
  187. data/app/views/auth/shopping/cart_items/new.html.erb +5 -0
  188. data/app/views/auth/shopping/cart_items/show.html.erb +13 -0
  189. data/app/views/auth/shopping/carts/_form.html.erb +35 -0
  190. data/app/views/auth/shopping/carts/_payment_links.html.erb +27 -0
  191. data/app/views/auth/shopping/carts/_remove_cart_item.html.erb +11 -0
  192. data/app/views/auth/shopping/carts/_show_cart_balance_info.html.erb +35 -0
  193. data/app/views/auth/shopping/carts/edit.html.erb +6 -0
  194. data/app/views/auth/shopping/carts/index.html.erb +43 -0
  195. data/app/views/auth/shopping/carts/new.html.erb +5 -0
  196. data/app/views/auth/shopping/carts/show.html.erb +46 -0
  197. data/app/views/auth/shopping/discounts/_form.html.erb +18 -0
  198. data/app/views/auth/shopping/discounts/_form_for_create_multiple_cart_items.html.erb +17 -0
  199. data/app/views/auth/shopping/discounts/_show_pending_discount_request.html.erb +17 -0
  200. data/app/views/auth/shopping/discounts/destroy.html.erb +2 -0
  201. data/app/views/auth/shopping/discounts/edit.html.erb +29 -0
  202. data/app/views/auth/shopping/discounts/index.html.erb +40 -0
  203. data/app/views/auth/shopping/discounts/new.html.erb +1 -0
  204. data/app/views/auth/shopping/discounts/show.html.erb +18 -0
  205. data/app/views/auth/shopping/discounts/update.html.erb +2 -0
  206. data/app/views/auth/shopping/payments/_approve_payment.html.erb +7 -0
  207. data/app/views/auth/shopping/payments/_cash_card_cheque.html.erb +24 -0
  208. data/app/views/auth/shopping/payments/_create_discount_coupon.html.erb +5 -0
  209. data/app/views/auth/shopping/payments/_form.html.erb +19 -0
  210. data/app/views/auth/shopping/payments/_gateway.html.erb +21 -0
  211. data/app/views/auth/shopping/payments/_proceed_to_gateway_or_verify_payment.html.erb +18 -0
  212. data/app/views/auth/shopping/payments/_refresh_payment.html.erb +7 -0
  213. data/app/views/auth/shopping/payments/_refund.html.erb +10 -0
  214. data/app/views/auth/shopping/payments/_show_payment_receipt.html.erb +12 -0
  215. data/app/views/auth/shopping/payments/edit.html.erb +6 -0
  216. data/app/views/auth/shopping/payments/index.html.erb +43 -0
  217. data/app/views/auth/shopping/payments/new.html.erb +13 -0
  218. data/app/views/auth/shopping/payments/show.html.erb +36 -0
  219. data/app/views/auth/shopping/products/_form.html.erb +27 -0
  220. data/app/views/auth/shopping/products/edit.html.erb +6 -0
  221. data/app/views/auth/shopping/products/index.html.erb +48 -0
  222. data/app/views/auth/shopping/products/index.json.erb +7 -0
  223. data/app/views/auth/shopping/products/new.html.erb +5 -0
  224. data/app/views/auth/shopping/products/show.html.erb +12 -0
  225. data/app/views/auth/shopping/products/show.json.erb +1 -0
  226. data/app/views/auth/unlocks/create.js.erb +12 -0
  227. data/app/views/auth/unlocks/new.html.erb +14 -0
  228. data/app/views/auth/unlocks/new.js.erb +17 -0
  229. data/app/views/auth/users/_search_result.html.erb +8 -0
  230. data/app/views/auth/users/profiles/_user_data.html.erb +4 -0
  231. data/app/views/auth/users/profiles/show.html.erb +54 -0
  232. data/app/views/layouts/auth/_modals.html.erb +2 -0
  233. data/app/views/layouts/auth/application.html.erb +17 -0
  234. data/app/views/layouts/auth/navbar/_navbar.html.erb +49 -0
  235. data/app/views/layouts/auth/navbar/_personalization.html.erb +17 -0
  236. data/app/views/layouts/auth/navbar/_progress_spinner.html.erb +11 -0
  237. data/app/views/layouts/mailer.html.erb +5 -0
  238. data/app/views/layouts/mailer.text.erb +1 -0
  239. data/config/initializers/active_model.rb +36 -0
  240. data/config/initializers/devise.rb +623 -0
  241. data/config/initializers/json.rb +10 -0
  242. data/config/initializers/omniauth.rb +447 -0
  243. data/config/initializers/redis.rb +2 -0
  244. data/config/initializers/redis.yml +14 -0
  245. data/config/locales/devise.en.yml +63 -0
  246. data/config/routes.rb +1 -0
  247. data/lib/assets/javascripts/data.js +126 -0
  248. data/lib/assets/javascripts/jquery.calendario.js +394 -0
  249. data/lib/assets/javascripts/jquery.tagcloud.js +92 -0
  250. data/lib/assets/javascripts/leanModal.js +236 -0
  251. data/lib/assets/javascripts/main.js +668 -0
  252. data/lib/assets/javascripts/modernizr.custom.63321.js +4 -0
  253. data/lib/assets/javascripts/payumoney.js +9 -0
  254. data/lib/assets/javascripts/search.js +36 -0
  255. data/lib/assets/javascripts/spinner.js +77 -0
  256. data/lib/assets/javascripts/trianglify.min.js +2 -0
  257. data/lib/assets/javascripts/you_need_to_sign_in.js.erb +478 -0
  258. data/lib/assets/stylesheets/calendar.css +111 -0
  259. data/lib/assets/stylesheets/calendar_modifications.scss +276 -0
  260. data/lib/auth.rb +32 -0
  261. data/lib/auth/custom_failure.rb +3 -0
  262. data/lib/auth/engine.rb +231 -0
  263. data/lib/auth/job_exception_handler.rb +7 -0
  264. data/lib/auth/mailgun.rb +28 -0
  265. data/lib/auth/notify.rb +8 -0
  266. data/lib/auth/omniauth/path.rb +104 -0
  267. data/lib/auth/partials.rb +12 -0
  268. data/lib/auth/rails/routes.rb +169 -0
  269. data/lib/auth/search/main.rb +97 -0
  270. data/lib/auth/sidekiq_up.rb +16 -0
  271. data/lib/auth/two_factor_otp.rb +202 -0
  272. data/lib/auth/url_shortener.rb +29 -0
  273. data/lib/auth/version.rb +3 -0
  274. data/lib/tasks/auth_tasks.rake +4 -0
  275. metadata +863 -0
@@ -0,0 +1,102 @@
1
+ ##need a seperate model that implements it
2
+ module Auth::Concerns::Shopping::ProductConcern
3
+
4
+ extend ActiveSupport::Concern
5
+ include Auth::Concerns::ChiefModelConcern
6
+ include Auth::Concerns::OwnerConcern
7
+ include Auth::Concerns::EsConcern
8
+
9
+ included do
10
+ INDEX_DEFINITION = {
11
+ index_options: {
12
+ settings: {
13
+ index: {
14
+ analysis: {
15
+ filter: {
16
+ nGram_filter: {
17
+ type: "nGram",
18
+ min_gram: 2,
19
+ max_gram: 20,
20
+ token_chars: [
21
+ "letter",
22
+ "digit",
23
+ "punctuation",
24
+ "symbol"
25
+ ]
26
+ }
27
+ },
28
+ analyzer: {
29
+ nGram_analyzer: {
30
+ type: "custom",
31
+ tokenizer: "whitespace",
32
+ filter: [
33
+ "lowercase",
34
+ "asciifolding",
35
+ "nGram_filter"
36
+ ]
37
+ },
38
+ whitespace_analyzer: {
39
+ type: "custom",
40
+ tokenizer: "whitespace",
41
+ filter: [
42
+ "lowercase",
43
+ "asciifolding"
44
+ ]
45
+ }
46
+ }
47
+ }
48
+ }
49
+ },
50
+ mappings: {
51
+ "shopping/product" => {
52
+ _all: {
53
+ index_analyzer: "nGram_analyzer",
54
+ search_analyzer: "whitespace_analyzer"
55
+ },
56
+ properties: {
57
+ name: {
58
+ type: "string",
59
+ index: "not_analyzed"
60
+ },
61
+ price: {
62
+ type: "double"
63
+ },
64
+ public: {
65
+ type: "string",
66
+ index: "not_analyzed",
67
+ include_in_all: false
68
+ },
69
+ resource_id: {
70
+ type: "string",
71
+ index: "not_analyzed"
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+ #include MongoidVersionedAtomic::VAtomic
79
+ field :price, type: BigDecimal
80
+ field :name, type: String
81
+
82
+ ## all products are public to be searched.
83
+ before_save do |document|
84
+ self.public = "yes"
85
+ end
86
+
87
+
88
+
89
+ end
90
+
91
+ def as_indexed_json(options={})
92
+ {
93
+ name: name,
94
+ price: price,
95
+ resource_id: resource_id,
96
+ public: public
97
+ }
98
+ end
99
+
100
+
101
+
102
+ end
@@ -0,0 +1,68 @@
1
+ module Auth::Concerns::SmsOtpConcern
2
+
3
+ extend ActiveSupport::Concern
4
+ include Auth::Concerns::ChiefModelConcern
5
+ included do
6
+
7
+ field :otp, type: String
8
+ field :intent_token, type: String
9
+ after_save :send_sms_otp, if: :param_changed_and_not_blank
10
+ end
11
+
12
+ ##ALL THESE METHODS ARE OVERRIDEN IN THE MODEL THAT IMPLEMENTS
13
+ ##THIS CONCERN
14
+ ##THE MODEL SHOULD CALL THE METHODS OF THE RESPECTIVE ADAPTER
15
+ ##THAT IS USED FOR OTP.
16
+ ##INSIDE OF THESE METHOD.
17
+ ##E.G
18
+ ##USER MODEL
19
+ ## def send_sms_otp
20
+ ## adapter.send_sms_otp
21
+ ## super
22
+ ## end
23
+ ##END
24
+
25
+
26
+ def check_otp_errors
27
+
28
+ end
29
+
30
+
31
+
32
+
33
+ def send_sms_otp
34
+ ##the user model will call the initial step of actually sending the sms otp.
35
+
36
+ ##we do this step because it is possible that send_sms_otp
37
+ ##can be called from a resend_otp requirement, in which case
38
+ ##the additional_login_param_status will already be 1, and we
39
+ ##wont need to save it.
40
+ #if self.additional_login_param_status_changed?
41
+ # self.skip_send_sms_otp_callback = true
42
+ # self.save
43
+ #end
44
+
45
+ end
46
+
47
+
48
+ ##overridden in the model that implements this concern,
49
+ ##whoever calls this method , must set the self.additional_login_param_pre_request_status to 2, at the end of successfull verification,since this is needed for password recovery, unlocks mechanisms.
50
+ def verify_sms_otp(otp)
51
+
52
+ end
53
+
54
+ private
55
+
56
+ ##only do the callbacks if
57
+ ##1.the param has changed
58
+ ##AND NOT DONE ANYMORE THIS FOLLOWING CONDITION
59
+ ##2.we dont want to explicitly skip the callback.(this prevents recursive loops)
60
+ ##AND THIS IS DONE
61
+ ##3.the new param is not blank.(we dont want to send sms otp verification to a non-existent number)
62
+ def param_changed_and_not_blank
63
+ additional_login_param_changed? && !additional_login_param.blank?
64
+ end
65
+
66
+
67
+ end
68
+
@@ -0,0 +1,788 @@
1
+ require 'mongoid'
2
+ require 'simple_token_authentication'
3
+
4
+ module Auth::Concerns::UserConcern
5
+
6
+ extend ActiveSupport::Concern
7
+ include Auth::Concerns::ChiefModelConcern
8
+ include Auth::Concerns::EsConcern
9
+
10
+ included do
11
+
12
+ INDEX_DEFINITION = {
13
+ index_options: {
14
+ settings: {
15
+ index: {
16
+ analysis: {
17
+ filter: {
18
+ nGram_filter: {
19
+ type: "nGram",
20
+ min_gram: 2,
21
+ max_gram: 20,
22
+ token_chars: [
23
+ "letter",
24
+ "digit",
25
+ "punctuation",
26
+ "symbol"
27
+ ]
28
+ }
29
+ },
30
+ analyzer: {
31
+ nGram_analyzer: {
32
+ type: "custom",
33
+ tokenizer: "whitespace",
34
+ filter: [
35
+ "lowercase",
36
+ "asciifolding",
37
+ "nGram_filter"
38
+ ]
39
+ },
40
+ whitespace_analyzer: {
41
+ type: "custom",
42
+ tokenizer: "whitespace",
43
+ filter: [
44
+ "lowercase",
45
+ "asciifolding"
46
+ ]
47
+ }
48
+ }
49
+ }
50
+ }
51
+ },
52
+ mappings: {
53
+ "user" => {
54
+ _all: {
55
+ index_analyzer: "nGram_analyzer",
56
+ search_analyzer: "whitespace_analyzer"
57
+ },
58
+ properties: {
59
+ name: {
60
+ type: "string"
61
+ },
62
+ email: {
63
+ type: "string",
64
+ index: "not_analyzed"
65
+ },
66
+ additional_login_param: {
67
+ type: "string",
68
+ index: "not_analyzed"
69
+ },
70
+ public: {
71
+ type: "string",
72
+ index: "not_analyzed"
73
+ },
74
+ resource_id: {
75
+ type: "string",
76
+ index: "not_analyzed"
77
+ }
78
+ }
79
+ }
80
+ }
81
+ }
82
+ }
83
+
84
+ include GlobalID::Identification
85
+
86
+ USER_INFO_FIELDS = ["name","image_url"]
87
+
88
+ PUBLICLY_VISIBLE_FIELD_NAMES = ["email","additional_login_param"]
89
+
90
+ include MongoidVersionedAtomic::VAtomic
91
+
92
+
93
+ opts = Auth.configuration.auth_resources[self.name]
94
+
95
+
96
+
97
+
98
+ ## so if it doesnt respond to confirmed_at -> then create a client anyways
99
+ ## if it responds to and the confirmed_at has changed, then create a client.
100
+ after_save :create_client, :if => Proc.new { |a| (!(a.respond_to? :confirmed_at)) || (a.confirmed_at_changed?) || (a.additional_login_param_status_changed? && a.additional_login_param_status == 2) }
101
+
102
+ after_save :set_client_authentication
103
+
104
+ before_save do |document|
105
+ ## set the document resource id if its not already set.
106
+ document.resource_id = document.id.to_s unless document.resource_id
107
+
108
+ ##if the additional login param changes, for eg. during an update, then set the additional login param status to pending immediately before saving itself, so that it is transactional type of thing.
109
+ if document.additional_login_param_changed? && !document.additional_login_param.blank?
110
+ document.additional_login_param_status = 1
111
+ end
112
+
113
+ if document.email_changed? || document.additional_login_param_changed? || document.encrypted_password_changed?
114
+ document.regenerate_token
115
+ end
116
+ end
117
+
118
+ after_destroy :destroy_client
119
+
120
+ ## if a or b or c.
121
+ after_save :send_reset_password_link
122
+
123
+ #######################################################
124
+ #
125
+ #
126
+ # Owner concern is not included in user concern.
127
+ # but we add the field "resource_id", because it allows
128
+ # search in elasticsearch, for a user to find his own record.
129
+ #
130
+ #######################################################
131
+
132
+ field :resource_id, type: String
133
+
134
+ ########################################################
135
+ # FIELDS FOR ALLOWING THE ADMIN TO CREATE USERS, AND ALSO REQUEST
136
+ #
137
+ #
138
+ #
139
+ ########################################################
140
+ field :created_by_admin, type: Boolean, default: false
141
+
142
+
143
+
144
+
145
+
146
+ ########################################################
147
+ ##
148
+ ##
149
+ ##BASIC USER FIELDS.
150
+ ##
151
+ ##
152
+ ########################################################
153
+ field :email, type: String
154
+ attr_accessor :skip_email_unique_validation
155
+ field :login, type: String
156
+
157
+ field :admin, type: Boolean, default: false
158
+
159
+ attr_accessor :m_client
160
+
161
+ ##additional parameter by which login can be done.
162
+ ##it should be defined in the configuration.
163
+ ##see spec/dummy/config/initializers/preinitializer.rb
164
+ field :additional_login_param, type: String
165
+
166
+ ##three possibilities
167
+ ##"pending" 1
168
+ ##"confirmed" 2
169
+ ##"unconfirmed" 0
170
+ field :additional_login_param_status, type: Integer, default: 0
171
+
172
+
173
+
174
+ field :name, type: String, default: ""
175
+ field :image_url, type: String, default: ""
176
+ ###ENDS.
177
+
178
+ unless self.method_defined?(:devise_modules)
179
+
180
+ ##get the options for the current class.
181
+
182
+
183
+ ## Database authenticatable
184
+ ##
185
+ #################################
186
+ if !opts[:skip].include? :sessions
187
+ devise :database_authenticatable
188
+ devise :trackable
189
+ ##setting the authentication keys parameter here.
190
+ devise :authentication_keys => {:login => true}
191
+ field :encrypted_password, type: String, default: ""
192
+ field :client_id, type: BSON::ObjectId
193
+ field :sign_in_count, type: Integer, default: 0
194
+ field :current_sign_in_at, type: Time
195
+ field :last_sign_in_at, type: Time
196
+ field :current_sign_in_ip, type: String
197
+ field :last_sign_in_ip, type: String
198
+ end
199
+
200
+
201
+
202
+ ##REGISTRABLES
203
+ ##
204
+ ####################################
205
+ if !opts[:skip].include? :registrations
206
+ devise :registerable
207
+ devise :validatable
208
+ def email_required?
209
+ #additional_login_param.nil?
210
+ return additional_login_param.nil?
211
+ end
212
+ validates_presence_of :additional_login_param, if: :additional_login_param_required?
213
+
214
+
215
+
216
+ ##IT ALLOWS A BLANK OR EMPTY ADDITIONAL LOGIN PARAM TO GO INTO THE DATABASE,BUT ONLY SENDS THE SMS_OTP IF THE PARAM IS NOT BLANK
217
+ validates_uniqueness_of :additional_login_param, allow_blank: true, if: :additional_login_param_changed?
218
+
219
+ validate :additional_login_param_format, if: :additional_login_param_changed?
220
+
221
+ ##VALIDATIONS TO BE DONE ONLY ON UPDATE
222
+ validate :additional_login_param_changed_on_unconfirmed_email,on: :update
223
+ validate :email_changed_on_unconfirmed_additional_login_param,on: :update
224
+ validate :email_and_additional_login_param_both_changed,on: [:update,:create]
225
+
226
+ field :remember_created_at, type: Time
227
+ end
228
+
229
+
230
+ ##### Recoverable
231
+ ###
232
+ ##########################################
233
+ if !opts[:skip].include? :passwords
234
+ devise :recoverable
235
+ field :reset_password_token, type: String
236
+ field :reset_password_sent_at, type: Time
237
+ end
238
+
239
+
240
+
241
+ ##### ## Confirmable
242
+ ##
243
+ #########################################
244
+ if !opts[:skip].include? :confirmations
245
+ devise :confirmable
246
+ field :confirmation_token, type: String
247
+ field :confirmed_at, type: Time
248
+ field :confirmation_sent_at, type: Time
249
+ field :unconfirmed_email, type: String # Only if using reconfirmable
250
+
251
+ ##this is what was overriden to ensure that confirmation_token and confirmation_sent_at are not set if we create an accoutn with just the mobile, but that caused active_for_authentication? to always return true, and so we had to let it be as is.
252
+ #def confirmation_required?
253
+ # !confirmed? && (self.email || self.unconfirmed_email)
254
+ #end
255
+
256
+ end
257
+
258
+
259
+ ## Lockable
260
+ ###################
261
+ ##########################################
262
+ if !opts[:skip].include? :unlocks
263
+ devise :lockable
264
+ field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
265
+ field :unlock_token, type: String # Only if unlock strategy is :email or :both
266
+ field :locked_at, type: Time
267
+ end
268
+
269
+
270
+ ####OAUTHABLE
271
+ ##
272
+ ############################################3
273
+ if !opts[:skip].include? :omniauthable
274
+ devise :omniauthable, :omniauth_providers => [:google_oauth2,:facebook]
275
+ field :identities, type: Array, default: [Auth::Identity.new.attributes.except("_id")]
276
+ end
277
+
278
+
279
+
280
+
281
+ end
282
+
283
+ unless Auth.configuration.enable_token_auth
284
+
285
+ else
286
+
287
+ acts_as_token_authenticatable
288
+ field :authentication_token, type: String
289
+ ##this we add to ensure that the token has an expiry.
290
+ field :authentication_token_expires_at, type: Integer
291
+ field :client_authentication, type: Hash, default: {}
292
+ field :current_app_id, type: String
293
+
294
+
295
+ end
296
+
297
+ ##THIS METHOD HAD TO BE OVERRIDDEN TO FIND THE
298
+ ##the user either by additional_login_param or email.
299
+ ##provide additional condition that the confirmed must be true.
300
+ def self.find_for_database_authentication(warden_conditions)
301
+
302
+ conditions = warden_conditions.dup
303
+ if login = conditions.delete(:login)
304
+ login = login.downcase
305
+ where(conditions).where('$or' => [ {:additional_login_param => /^#{Regexp.escape(login)}$/i, :additional_login_param_status => 2}, {:email => /^#{Regexp.escape(login)}$/i} ]).first
306
+ else
307
+
308
+ where(conditions).first
309
+ end
310
+ end
311
+
312
+
313
+ ##override active_for_authentication? to say true if additional login param is confirmed.
314
+ def active_for_authentication?
315
+ #puts "came to active for authentication,"
316
+ #puts "the status of additional login param is:"
317
+ #puts additional_login_param_status.to_s
318
+ ##if additional_login_param is confirmed and
319
+ if additional_login_param_status == 2
320
+
321
+ true
322
+ else
323
+
324
+ super
325
+ end
326
+ end
327
+
328
+ ##this method takes the credential params which are expected to be something like:
329
+ ##{:email => "test", :resource => "authenticate/users"}
330
+ ##
331
+ ##basically it takes each of the login params defined in the
332
+ ##preinitializer for this resource, and then makes the conditions for all of them
333
+ ##for eg: if the login_params are "email,additional_login_param", then it will make the conditions look for both of them, for the same parameter that comes in .
334
+ ##conditions => [{"email" => "test"},{"additional_login_params" => "test"}]
335
+ ##these are then returned to the controller to be searched.
336
+ def self.credential_exists(credential_params)
337
+ login_params = Auth.configuration.auth_resources[self.name.to_s][:login_params]
338
+ credential = credential_params.select{|c,v| login_params.include? c.to_sym}.values[0]
339
+ conditions = login_params.map{|key|
340
+ key = {key => credential}
341
+ }
342
+ conditions
343
+ end
344
+
345
+ end
346
+
347
+ module ClassMethods
348
+
349
+ ## @param[String] _id : the id sent into the request.
350
+ ## @param[Object] resource : the currently signed in resource.
351
+ ## how this works : it is called in the profiles_controller
352
+ ## if the current signed in resource is admin, then whatever user_id(_id) was requested is searched and returned.
353
+ ## if the current signed in resource is not admin, then _id is instead searched for using the current_signed_in_resource => basically will only return the user that is signed in.
354
+
355
+ def find_resource(_id,resource)
356
+ conditions = {:_id => _id}
357
+ conditions[:_id] = resource.id.to_s if !resource.is_admin?
358
+ all = self.where(conditions)
359
+ return all.first if all.size > 0
360
+ return nil
361
+ end
362
+
363
+ end
364
+
365
+ ##FOR THE LOGIN AUTHENTICATION KEY PARAMETER, WE DEFINE GETTERS AND SETTERS
366
+ def login=(login)
367
+ @login = login
368
+ end
369
+
370
+ def login
371
+ @login || self.email || self.additional_login_param
372
+ end
373
+
374
+ =begin
375
+ ##reset the auth token if the email or password changes.
376
+ def email=(email)
377
+ super
378
+ #puts "email coming in is: #{email}"
379
+ #puts "email set called."
380
+ ##method is defined in lib/omniauth#Simpletokenauthentication
381
+ #if email_changed?
382
+ regenerate_token
383
+ #end
384
+ end
385
+
386
+ def additional_login_param=(additional_login_param)
387
+ super
388
+
389
+ regenerate_token
390
+ end
391
+
392
+ def password=(password)
393
+ super
394
+
395
+ regenerate_token
396
+ end
397
+ =end
398
+
399
+
400
+
401
+ #def has_token_and_es
402
+ # return !self.authentication_token.nil?
403
+ #end
404
+
405
+
406
+
407
+ ##setting these as nil, forces a new auth_token and es to be generated
408
+ ##because in the before_save hooks they are set if they are blank.
409
+ #def set_es
410
+ # if !email.nil?
411
+ # salt = SecureRandom.hex(32)
412
+ # pre_es = salt + email
413
+ # self.es = Digest::SHA256.hexdigest(pre_es)
414
+ # end
415
+ #end
416
+
417
+ def set_client_authentication
418
+
419
+
420
+ if !self.m_client.nil?
421
+ if self.client_authentication[self.m_client.current_app_id].nil? && self.valid?
422
+ self.client_authentication[self.m_client.current_app_id] = SecureRandom.hex(32)
423
+
424
+ self.save
425
+ end
426
+
427
+ else
428
+
429
+ end
430
+ #
431
+
432
+ end
433
+
434
+
435
+ ## @called_from : after_save -> override
436
+ ## @working :
437
+ ## if the resource was created by an administrator, and the attr_accessor request_send_reset_password_link is true, then it will check if the email is confirmed, and then send the reset_password_instructions to the email. otherwise will check if the mobile is confirmed, and will just generate that reset_password_link
438
+ def send_reset_password_link
439
+
440
+ reset_password_link = nil
441
+
442
+ #puts "came to send reset password link, and this is the attr accessor."
443
+ #puts self.request_send_reset_password_link.to_s
444
+
445
+ ## if there was an unconfirmed_email present.
446
+
447
+ if self.created_by_admin
448
+
449
+ #puts "the request send is true."
450
+ #puts self.attributes.to_s
451
+ #puts "is the additional login param confirmed"
452
+ #puts self.additional_login_param_confirmed?
453
+ ## this case is exceptional because the user will have gone to
454
+ if self.confirmed?
455
+ #puts "self is confirmed."
456
+ begin
457
+ self.class.skip_callback(:save, :after, :send_reset_password_link)
458
+
459
+ self.class.send_reset_password_instructions(self.attributes)
460
+ rescue
461
+ ensure
462
+ self.created_by_admin = false
463
+ self.save
464
+ self.class.set_callback(:save, :after, :send_reset_password_link)
465
+ end
466
+
467
+ elsif self.additional_login_param_confirmed?
468
+ #puts "additiona login param is confirmed."
469
+ begin
470
+ #self.created_by_admin = false
471
+ self.class.skip_callback(:save, :after, :send_reset_password_link)
472
+ reset_password_link = Rails.application.routes.url_helpers.send("edit_#{self.class.name.downcase}_password_path",{:reset_password_token => self.set_reset_password_token})
473
+
474
+ rescue => e
475
+ puts e.to_s
476
+ ensure
477
+ self.created_by_admin = false
478
+ self.save
479
+ self.class.set_callback(:save, :after, :send_reset_password_link)
480
+ end
481
+
482
+ end
483
+
484
+ end
485
+
486
+ reset_password_link
487
+
488
+ end
489
+
490
+
491
+ def destroy_client
492
+ @client = Auth::Client.find(self.id)
493
+ @client.delete
494
+ end
495
+
496
+ ##tries to create a client with a unique api_key, and user id.
497
+ ##tries 10 attempts
498
+ ##initially tries a versioned_create
499
+ ##if the op is successfull then it breaks.
500
+ ##if the op_count becomes zero it breaks.
501
+ ##if there is no client with this user id, then and only then will it change the api_key and again try to create a client with this resource_id and this api_key.
502
+ ##at the end it will exit, and there may or may not be a client with this resource_id.
503
+ ##so this method basically fails silently, and so when you look at a user profiel and if you don't see an api_key, it means that there is no client for him, that is the true sign that it failed.
504
+ ##api key checking includes whether the user for that key is confirmed or not.
505
+ ##client is created irrespective of whether the user is confirmed or not.
506
+ def create_client
507
+
508
+
509
+ ##we want to create a new client, provided that there is no client for this user id.
510
+ ##if a client already exists, then we dont want to do anything.
511
+ ##when we create the client we want to be sure that
512
+ ##provided that there is no client with this user id.
513
+ #puts "called create client."
514
+
515
+ ##first find out if there is already a client for this user id.
516
+ c = Auth::Client.new(:api_key => SecureRandom.hex(32), :resource_id => self.id)
517
+
518
+ #puts "Came to create a client."
519
+
520
+ c.versioned_create({:resource_id => self.id})
521
+ op_count = 10
522
+
523
+
524
+
525
+ while(true)
526
+
527
+ if c.op_success?
528
+ #puts "the op was a success"
529
+ break
530
+ elsif op_count == 0
531
+ #puts "op count was 0"
532
+ break
533
+ elsif (Auth::Client.where(:resource_id => self.id).count == 0)
534
+ #puts "tried to create here."
535
+ c.api_key = SecureRandom.hex(32)
536
+ c.versioned_create({:resource_id => self.id})
537
+ op_count-=1
538
+ else
539
+ #puts "finally broke."
540
+ break
541
+ end
542
+
543
+
544
+ end
545
+
546
+ end
547
+
548
+ ###@param[Array] : array of field names that you want the values for.
549
+ ###@return[Hash] : hash of key , value pairs containing the values that you asked for.
550
+ def get_user_info(keys)
551
+ keys = keys.keep_if{ |c| (USER_INFO_FIELDS.include? c) && (self.respond_to(c.to_sym)) }
552
+
553
+ return Hash[keys.map{|c| [c,self.send("#{c}")]}]
554
+ end
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+ ##for the api responses.
563
+ ##if there is a current_app_id, then it will respond with the
564
+ ##authentication-token and es
565
+ ##if there is none, then it will return nil.
566
+ ##it should return the errors irrespective of these settings.
567
+ ## if otp_verification key is present in the options, then the auth_token and es will not be returned.
568
+ ## this is needed in
569
+ def as_json(options={})
570
+
571
+
572
+ json = {:nothing => true}
573
+
574
+ if (!self.destroyed? && options[:otp_verification].nil?)
575
+
576
+ if self.m_client.current_app_id && at_least_one_authentication_key_confirmed? && self.errors.empty?
577
+
578
+ json = super(:only => [:authentication_token])
579
+ json[:es] = self.client_authentication[self.m_client.current_app_id]
580
+ unless options[:show_id].nil?
581
+ json[:id] = self.id.to_s
582
+ json[:admin] = self.admin.to_s
583
+ end
584
+
585
+ end
586
+ if self.errors.full_messages.size > 0
587
+ json[:errors] = self.errors.full_messages
588
+ end
589
+ end
590
+ json
591
+ end
592
+
593
+ ##returns true if there is at least one non empty oauth identity
594
+ def has_oauth_identity?
595
+ return false unless self.respond_to? :identities
596
+ self.identities.keep_if{|c|
597
+
598
+ Auth::Identity.new(c).has_provider?
599
+
600
+ }.size > 0
601
+ end
602
+
603
+ ## skip_email_unique_validation is set to true in omni_concern in the situation:
604
+ ##1.there is no user with the given identity.
605
+ ## however it is possible that a user with this email exists.
606
+ ## 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.
607
+ def email_changed?
608
+ super && skip_email_unique_validation.nil?
609
+ end
610
+
611
+
612
+ ##it is required only if the email is missing.
613
+ def additional_login_param_required?
614
+ email.nil?
615
+ end
616
+
617
+ ##this method will validate the format of the additional_login_param.
618
+ ##it can be overridden by the user to do his own custom validation.
619
+ ##default behaviour is not to add any errors in the validation process.
620
+ def additional_login_param_format
621
+
622
+ end
623
+
624
+ ## confirmed?
625
+ ## OR
626
+ ## both email and unconfirmed email are nil AND additional_login_param has been confirmed already.
627
+ ##currently used in this file in #authentication_keys_confirmed?
628
+ def email_confirmed_or_does_not_exist
629
+ (self.confirmed? && !self.pending_reconfirmation?) || (self.email.nil? && self.unconfirmed_email.nil?)
630
+ end
631
+
632
+ def additional_login_param_confirmed?
633
+ self.additional_login_param_status == 2
634
+ end
635
+
636
+ ## if the additional_login_param_status == 2
637
+ def additional_login_param_confirmed_or_does_not_exist
638
+ additional_login_param_confirmed? || self.additional_login_param_status == 0
639
+ end
640
+
641
+ ## at least one authentication_key should be confirmed.
642
+ ## so even if we change the other one, we still return the remote authentication options even when that one is still unconfirmed.
643
+ ## used in lib/devise to decide whether to return the auth token and es and redirect.
644
+ ## used in self.as_json, to see whether to return the auth_token and es.
645
+ def at_least_one_authentication_key_confirmed?
646
+ (self.confirmed? && !self.pending_reconfirmation?) || self.additional_login_param_status == 2
647
+ end
648
+
649
+ ## used in auth/registrations/update.js.erb
650
+ ## use it to chekc if the resource is fully confirmed, otherwise we redirect in the erb to whichever of the two needs to be confirmed.
651
+ def authentication_keys_confirmed?
652
+ return email_confirmed_or_does_not_exist && additional_login_param_confirmed_or_does_not_exist
653
+ end
654
+
655
+ ##if you change the additional login param while the email is not confirmed, you will get a validation error on additional_login_param
656
+ def additional_login_param_changed_on_unconfirmed_email
657
+ #puts "calling additional login param changed"
658
+ if additional_login_param_changed? && (self.pending_reconfirmation?)
659
+ errors.add(:additional_login_param,"Please verify your email or add an email id before changing your #{additional_login_param_name}")
660
+ end
661
+ end
662
+
663
+ ##if you change the email while the additional login param not confirmed, then you will get validation errors on the email, as long as you have enabled an additional_login_param in the configuration.
664
+ def email_changed_on_unconfirmed_additional_login_param
665
+ #puts "calling email changed"
666
+ if email_changed? && (additional_login_param_status == 1) && additional_login_param_name
667
+ errors.add(:email, "Please add or verify your #{additional_login_param_name} before changing your email id")
668
+ end
669
+ end
670
+
671
+ ##has the attribute gone from blank to blank?
672
+ ##what happens is that if submit the update form, it submits empty strings for input fields which we dont fill. so suppose you change the adiditonal_login_param , it will submit email as "", in that case , earlier the email was nil, and now it becomes "", so that is detected as an email change and it feels like both email and additional param have changed and triggers the validation #email_and_additional_login_param_both_changed, so we dont want that to happen, so we check if the param has gone from being blank to blank in the below validation.
673
+ ##@param attr[String] : the param name.
674
+ def attr_blank_to_blank?(attr)
675
+ #puts "calling blank to blank."
676
+ if self.respond_to?(attr)
677
+ if (self.send("#{attr}_was").blank? && self.send("#{attr}").blank?)
678
+
679
+ true
680
+ end
681
+ end
682
+ end
683
+
684
+ ##now what if both have changed?
685
+ def email_and_additional_login_param_both_changed
686
+ #puts "calling email and additional login param both changed"
687
+ ##add error saying you cannot change both at the same time.
688
+ ##additional login param can change as long as neither goes from nil to blank or blank to nil.
689
+
690
+ if email_changed? && !attr_blank_to_blank?("email") && additional_login_param_changed? && !attr_blank_to_blank?("additional_login_param")
691
+ errors.add(:email,"you cannot update your email and #{additional_login_param_name} at the same time")
692
+ end
693
+ end
694
+
695
+ ## no longer used.
696
+ def set_client_authentication?(act_name,cont_name,client)
697
+
698
+ client && act_name != "destroy" && !(["passwords","confirmations","unlocks"].include? cont_name)
699
+
700
+
701
+ end
702
+
703
+
704
+ ##this def is used to determine if the auth_token and es should
705
+ ##be sent back.
706
+ def reply_with_auth_token_es?(client,curr_user)
707
+
708
+ ##we have a client authentication for the client.
709
+ ##we have an authentication token
710
+ ##we are signed_in
711
+ ##we have at least one authentication_key confirmed.
712
+ return false if !curr_user
713
+ client && client_authentication[client.current_app_id] && authentication_token && (id.to_s == curr_user.id.to_s) && at_least_one_authentication_key_confirmed?
714
+ end
715
+
716
+ ##just a combination of having the redirect_url and the above method,
717
+ ##and whether to redirect or not.
718
+ def reply_with_redirect_url_and_auth_token_and_es?(redirect_url,client,curr_user)
719
+ Auth.configuration.do_redirect && redirect_url && reply_with_auth_token_es?(client,curr_user)
720
+ end
721
+
722
+ ##
723
+ def token_expired?
724
+ if authentication_token_expires_at < Time.now.to_i
725
+
726
+ regenerate_token
727
+ save
728
+ true
729
+ end
730
+ end
731
+
732
+
733
+
734
+ ##returns the additional login param name.
735
+ def additional_login_param_name
736
+ Auth.configuration.auth_resources[self.class.name.to_s.underscore.capitalize][:additional_login_param_name]
737
+ end
738
+
739
+ ## => resource name converted to string with a capital
740
+ ## => first letter. eg : "User"
741
+ def resource_key_for_auth_configuration
742
+ self.class.name.to_s.underscore.capitalize
743
+ end
744
+
745
+ ##THIS DEF CAN BE OVERRIDDEN IN YOUR MODEL TO SUIT YOUR NEEDS.
746
+ def has_phone
747
+ Auth.configuration.auth_resources[resource_key_for_auth_configuration][:additional_login_param_name] && Auth.configuration.auth_resources[resource_key_for_auth_configuration][:additional_login_param_name] == "mobile"
748
+ end
749
+
750
+ ##override as needed.
751
+ ##currently used in _gateway.html.erb
752
+ def resource_first_name
753
+ name
754
+ end
755
+
756
+
757
+ def has_gcm_token
758
+ false
759
+ end
760
+
761
+ ## this method is to be overridden, it returns the value of the admin_variable.
762
+ ## it can be used to decide if the user is an admin.
763
+ ## @used_in : payment_concern in the refund_callback
764
+ def is_admin?
765
+ admin
766
+ end
767
+
768
+
769
+
770
+ ## @return[Boolean] true/false : override to decide how the user decides if it can create discount coupons for its contents or not.
771
+ ## the current implementation returns true by default
772
+ def can_create_discount_coupons?
773
+ true
774
+ end
775
+
776
+
777
+ def as_indexed_json(options={})
778
+ {
779
+ name: name,
780
+ email: email,
781
+ additional_login_param: additional_login_param,
782
+ additional_login_param_status: additional_login_param_status,
783
+ resource_id: resource_id,
784
+ public: public
785
+ }
786
+ end
787
+
788
+ end