kirgudu_base 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/kirgudu_base/dynamicEvents.js +2 -1
  3. data/app/assets/javascripts/kirgudu_base/jquery.container-management.js +241 -0
  4. data/app/assets/javascripts/kirgudu_base/jquery.fancybox copia.js +2020 -0
  5. data/app/assets/javascripts/kirgudu_base/scripts_nrg.js +300 -383
  6. data/app/controllers/kirgudu_base/admin_controller.rb +1 -44
  7. data/app/controllers/kirgudu_base/application_controller.rb +135 -92
  8. data/app/controllers/kirgudu_base/cabinet_controller.rb +35 -35
  9. data/app/controllers/kirgudu_base/security/authentications_controller.rb +452 -0
  10. data/app/controllers/kirgudu_base/security/email_confirmations_controller.rb +46 -0
  11. data/app/helpers/kirgudu_base/application_helper.rb +25 -0
  12. data/app/helpers/kirgudu_base/authentication_form_builder.rb +76 -0
  13. data/app/helpers/kirgudu_base/controllers/{basic_actions_with_parent.rb → OLD_basic_actions.rb} +39 -54
  14. data/app/helpers/kirgudu_base/controllers/basic_actions.rb +967 -161
  15. data/app/helpers/kirgudu_base/controllers/container_items_management_actions.rb +118 -40
  16. data/app/helpers/kirgudu_base/controllers/container_items_sorting_actions.rb +2 -2
  17. data/app/helpers/kirgudu_base/controllers/dynamic_pages.rb +147 -11
  18. data/app/helpers/kirgudu_base/form_builder.rb +3 -1
  19. data/app/helpers/kirgudu_base/gui_helper.rb +10 -5
  20. data/app/helpers/kirgudu_base/models/exports.rb +122 -122
  21. data/app/helpers/kirgudu_base/models/scopes.rb +5 -0
  22. data/app/mailers/authentications_mailer.rb +53 -0
  23. data/app/models/kirgudu_base/base_model.rb +47 -14
  24. data/app/models/kirgudu_base/dynamic_pages/builder.rb +0 -8
  25. data/app/models/kirgudu_base/dynamic_pages/controller_link.rb +4 -1
  26. data/app/models/kirgudu_base/dynamic_pages/controller_link_builder.rb +2 -1
  27. data/app/models/kirgudu_base/dynamic_pages/controller_link_id.rb +6 -6
  28. data/app/models/kirgudu_base/dynamic_pages/controller_link_id_builder.rb +6 -6
  29. data/app/models/kirgudu_base/dynamic_pages/element.rb +4 -5
  30. data/app/models/kirgudu_base/dynamic_pages/entry_builder.rb +2 -2
  31. data/app/models/kirgudu_base/dynamic_pages/event_if_block_builder.rb +1 -1
  32. data/app/models/kirgudu_base/dynamic_pages/form_builder.rb +2 -2
  33. data/app/models/kirgudu_base/dynamic_pages/list.rb +2 -0
  34. data/app/models/kirgudu_base/dynamic_pages/list_builder.rb +7 -3
  35. data/app/models/kirgudu_base/dynamic_pages/management_settings.rb +30 -0
  36. data/app/models/kirgudu_base/dynamic_pages/management_settings_builder.rb +47 -0
  37. data/app/models/kirgudu_base/dynamic_pages/menu.rb +9 -5
  38. data/app/models/kirgudu_base/dynamic_pages/menu_builder.rb +8 -5
  39. data/app/models/kirgudu_base/dynamic_pages/menu_item.rb +22 -6
  40. data/app/models/kirgudu_base/dynamic_pages/menu_items_block_builder.rb +9 -4
  41. data/app/models/kirgudu_base/dynamic_pages/menu_section.rb +38 -0
  42. data/app/models/kirgudu_base/dynamic_pages/menu_section_builder.rb +36 -0
  43. data/app/models/kirgudu_base/dynamic_pages/page.rb +6 -2
  44. data/app/models/kirgudu_base/dynamic_pages/page_builder.rb +18 -0
  45. data/app/models/kirgudu_base/dynamic_pages/relation.rb +23 -0
  46. data/app/models/kirgudu_base/dynamic_pages/relation_builder.rb +35 -0
  47. data/app/models/kirgudu_base/dynamic_pages/sorting_settings.rb +31 -0
  48. data/app/models/kirgudu_base/dynamic_pages/sorting_settings_builder.rb +48 -0
  49. data/app/models/kirgudu_base/security/autheintication.rb +4 -0
  50. data/app/models/kirgudu_base/security/authentication.rb +6 -7
  51. data/app/models/kirgudu_base/security/email_confirmation.rb +7 -0
  52. data/app/models/kirgudu_base/security/restore_password_code.rb +5 -0
  53. data/app/models/kirgudu_base/security/user.rb +2 -0
  54. data/app/models/kirgudu_base/security.rb +6 -7
  55. data/app/models/kirgudu_base/settings/group.rb +22 -0
  56. data/app/models/kirgudu_base/settings/option.rb +44 -0
  57. data/app/models/kirgudu_base/settings/settings_manager.rb +69 -0
  58. data/app/models/kirgudu_base/settings/value.rb +36 -0
  59. data/app/views/admin_templates/default/admin/layouts/application.html.erb +6 -4
  60. data/app/views/admin_templates/default/admin/system/settings/groups/edit.html.erb +9 -9
  61. data/app/views/admin_templates/default/admin/system/settings/groups/new.html.erb +1 -1
  62. data/app/views/admin_templates/default/admin/system/settings/options/edit.html.erb +1 -1
  63. data/app/views/admin_templates/default/admin/system/settings/options/new.html.erb +1 -1
  64. data/app/views/admin_templates/default/admin/system/settings/values/edit.html.erb +1 -1
  65. data/app/views/admin_templates/default/admin/system/settings/values/new.html.erb +1 -1
  66. data/app/views/admin_templates/erp/admin/shared/_top_nav_bar.html.erb +1 -3
  67. data/app/views/admin_templates/erp/admin/shared/entry_edit_form_renderer.html.erb +1 -1
  68. data/app/views/admin_templates/erp/admin/shared/entry_new_form_renderer.html.erb +1 -1
  69. data/app/views/admin_templates/good/admin/layouts/OLD_application.html.erb +14 -14
  70. data/app/views/admin_templates/good/admin/layouts/application.html.erb +11 -113
  71. data/app/views/admin_templates/good/admin/shared/_left_menu.html.erb +74 -63
  72. data/app/views/admin_templates/good/{zapanel/files/New Adobe Photoshop Image 12.psd → admin/shared/_left_menu_item.html.erb} +0 -0
  73. data/app/views/admin_templates/good/admin/shared/_left_menu_section.html.erb +21 -0
  74. data/app/views/admin_templates/good/admin/shared/render_new_OLD.html.erb +90 -0
  75. data/app/views/admin_templates/good/admin/shared/renderer_edit.html.erb +44 -13
  76. data/app/views/admin_templates/good/admin/shared/renderer_edit_OLD.html.erb +106 -0
  77. data/app/views/admin_templates/good/admin/shared/renderer_entries_list.html.erb +39 -18
  78. data/app/views/admin_templates/good/admin/shared/renderer_entries_list_with_parent.html.erb +4 -4
  79. data/app/views/admin_templates/good/admin/shared/renderer_management.html.erb +164 -0
  80. data/app/views/admin_templates/good/admin/shared/renderer_new.html.erb +40 -10
  81. data/app/views/admin_templates/good/admin/shared/renderer_show.html.erb +170 -58
  82. data/app/views/admin_templates/good/admin/shared/renderer_show_OLD.html.erb +159 -0
  83. data/app/views/admin_templates/good/admin/shared/renderer_sorting.html.erb +30 -0
  84. data/app/views/admin_templates/good/kirgudu_base/authentications/login.html.erb +13 -13
  85. data/app/views/admin_templates/good/kirgudu_base/authentications/register.html.erb +1 -1
  86. data/app/views/admin_templates/good/kirgudu_base/old/login_page.html.erb +7 -7
  87. data/app/views/admin_templates/good_flexy/admin/layouts/application.html.erb +17 -16
  88. data/app/views/admin_templates/good_flexy/admin/shared/_left_menu.html.erb +7 -0
  89. data/app/views/admin_templates/good_flexy/admin/shared/renderer_entries_list.html.erb +25 -17
  90. data/app/views/admin_templates/good_flexy/admin/shared/renderer_form_edit.html.erb +34 -13
  91. data/app/views/admin_templates/good_flexy/admin/shared/renderer_form_new.html.erb +31 -10
  92. data/app/views/admin_templates/good_flexy/admin/shared/renderer_show.html.erb +67 -52
  93. data/config/locales/kirgudu_base.ru.yml +92 -0
  94. data/config/routes.rb +16 -16
  95. data/db/migrate/20140413134252_create_kirgudu_base_security_authentications.rb +15 -0
  96. data/db/migrate/20140413152144_create_kirgudu_base_security_email_confirmations.rb +17 -0
  97. data/db/migrate/20140413201121_add_confirmations_kirgudu_base_security_users.rb +14 -0
  98. data/db/migrate/20140415093106_create_kirgudu_base_security_restore_password_codes.rb +20 -0
  99. data/lib/kirgudu_base.rb +2 -2
  100. data/test/fixtures/kirgudu_base/kirgudu_base/security/autheintications.yml +11 -0
  101. data/test/fixtures/kirgudu_base/security/applications.yml +21 -0
  102. data/test/fixtures/kirgudu_base/security/autheintications.yml +11 -0
  103. data/test/fixtures/kirgudu_base/security/authentications.yml +11 -0
  104. data/test/fixtures/kirgudu_base/security/email_confirmations.yml +13 -0
  105. data/test/fixtures/kirgudu_base/security/restore_password_codes.yml +13 -0
  106. data/test/models/kirgudu_base/kirgudu_base/security/autheintication_test.rb +9 -0
  107. data/test/models/kirgudu_base/security/application_test.rb +9 -0
  108. data/test/models/kirgudu_base/security/autheintication_test.rb +9 -0
  109. data/test/models/kirgudu_base/security/authentication_test.rb +9 -0
  110. data/test/models/kirgudu_base/security/email_confirmation_test.rb +9 -0
  111. data/test/models/kirgudu_base/security/restore_password_code_test.rb +9 -0
  112. metadata +102 -79
  113. data/app/assets/javascripts/kirgudu_base/jquery.fancybox.pack.js +0 -45
  114. data/app/controllers/kirgudu_base/authentications_controller.rb +0 -157
  115. data/app/views/admin_templates/good/zapanel/404.html +0 -386
  116. data/app/views/admin_templates/good/zapanel/billing.html +0 -550
  117. data/app/views/admin_templates/good/zapanel/blank-page.html +0 -343
  118. data/app/views/admin_templates/good/zapanel/buttons.html +0 -1018
  119. data/app/views/admin_templates/good/zapanel/calendars.html +0 -451
  120. data/app/views/admin_templates/good/zapanel/cart.html +0 -522
  121. data/app/views/admin_templates/good/zapanel/charts.html +0 -611
  122. data/app/views/admin_templates/good/zapanel/collapse.html +0 -555
  123. data/app/views/admin_templates/good/zapanel/contact.php +0 -102
  124. data/app/views/admin_templates/good/zapanel/dashboard.html +0 -985
  125. data/app/views/admin_templates/good/zapanel/dashboard2.html +0 -1091
  126. data/app/views/admin_templates/good/zapanel/dashboard3.html +0 -1079
  127. data/app/views/admin_templates/good/zapanel/data/movies.json +0 -1
  128. data/app/views/admin_templates/good/zapanel/faq.html +0 -435
  129. data/app/views/admin_templates/good/zapanel/file-manager.html +0 -358
  130. data/app/views/admin_templates/good/zapanel/files/index.php +0 -0
  131. data/app/views/admin_templates/good/zapanel/font-awesome/less/bootstrap.less +0 -84
  132. data/app/views/admin_templates/good/zapanel/font-awesome/less/core.less +0 -129
  133. data/app/views/admin_templates/good/zapanel/font-awesome/less/extras.less +0 -93
  134. data/app/views/admin_templates/good/zapanel/font-awesome/less/font-awesome-ie7.less +0 -1953
  135. data/app/views/admin_templates/good/zapanel/font-awesome/less/font-awesome.less +0 -33
  136. data/app/views/admin_templates/good/zapanel/font-awesome/less/icons.less +0 -381
  137. data/app/views/admin_templates/good/zapanel/font-awesome/less/mixins.less +0 -48
  138. data/app/views/admin_templates/good/zapanel/font-awesome/less/path.less +0 -14
  139. data/app/views/admin_templates/good/zapanel/font-awesome/less/variables.less +0 -735
  140. data/app/views/admin_templates/good/zapanel/font-awesome/scss/_bootstrap.scss +0 -84
  141. data/app/views/admin_templates/good/zapanel/font-awesome/scss/_core.scss +0 -129
  142. data/app/views/admin_templates/good/zapanel/font-awesome/scss/_extras.scss +0 -93
  143. data/app/views/admin_templates/good/zapanel/font-awesome/scss/_icons.scss +0 -381
  144. data/app/views/admin_templates/good/zapanel/font-awesome/scss/_mixins.scss +0 -48
  145. data/app/views/admin_templates/good/zapanel/font-awesome/scss/_path.scss +0 -14
  146. data/app/views/admin_templates/good/zapanel/font-awesome/scss/_variables.scss +0 -734
  147. data/app/views/admin_templates/good/zapanel/font-awesome/scss/font-awesome-ie7.scss +0 -1953
  148. data/app/views/admin_templates/good/zapanel/font-awesome/scss/font-awesome.scss +0 -33
  149. data/app/views/admin_templates/good/zapanel/form.html +0 -790
  150. data/app/views/admin_templates/good/zapanel/gallery.html +0 -392
  151. data/app/views/admin_templates/good/zapanel/grids.html +0 -574
  152. data/app/views/admin_templates/good/zapanel/hosting-dashboard.html +0 -448
  153. data/app/views/admin_templates/good/zapanel/icon.html +0 -722
  154. data/app/views/admin_templates/good/zapanel/inbox.html +0 -375
  155. data/app/views/admin_templates/good/zapanel/index.html +0 -48
  156. data/app/views/admin_templates/good/zapanel/invoice.html +0 -423
  157. data/app/views/admin_templates/good/zapanel/js/proxy/elFinderSupportVer1.js +0 -338
  158. data/app/views/admin_templates/good/zapanel/js/skins/default/lightbox-close.png +0 -0
  159. data/app/views/admin_templates/good/zapanel/js/skins/default/lightbox-next.png +0 -0
  160. data/app/views/admin_templates/good/zapanel/js/skins/default/lightbox-prev.png +0 -0
  161. data/app/views/admin_templates/good/zapanel/notification.html +0 -400
  162. data/app/views/admin_templates/good/zapanel/order-recieved.html +0 -348
  163. data/app/views/admin_templates/good/zapanel/php/MySQLStorage.sql +0 -23
  164. data/app/views/admin_templates/good/zapanel/php/connector.php +0 -44
  165. data/app/views/admin_templates/good/zapanel/php/elFinder.class.php +0 -1103
  166. data/app/views/admin_templates/good/zapanel/php/elFinderConnector.class.php +0 -133
  167. data/app/views/admin_templates/good/zapanel/php/elFinderVolumeDriver.class.php +0 -3370
  168. data/app/views/admin_templates/good/zapanel/php/elFinderVolumeLocalFileSystem.class.php +0 -835
  169. data/app/views/admin_templates/good/zapanel/php/elFinderVolumeMySQL.class.php +0 -896
  170. data/app/views/admin_templates/good/zapanel/php/mime.types +0 -512
  171. data/app/views/admin_templates/good/zapanel/price-table.html +0 -400
  172. data/app/views/admin_templates/good/zapanel/profile.html +0 -387
  173. data/app/views/admin_templates/good/zapanel/progressbar.html +0 -555
  174. data/app/views/admin_templates/good/zapanel/range-slider.html +0 -440
  175. data/app/views/admin_templates/good/zapanel/ribbon-grids.html +0 -491
  176. data/app/views/admin_templates/good/zapanel/sale-purchase-dashboard.html +0 -803
  177. data/app/views/admin_templates/good/zapanel/search.html +0 -370
  178. data/app/views/admin_templates/good/zapanel/skins/default/lightbox-close.png +0 -0
  179. data/app/views/admin_templates/good/zapanel/skins/default/lightbox-loading.gif +0 -0
  180. data/app/views/admin_templates/good/zapanel/skins/default/lightbox-next.png +0 -0
  181. data/app/views/admin_templates/good/zapanel/skins/default/lightbox-pause.png +0 -0
  182. data/app/views/admin_templates/good/zapanel/skins/default/lightbox-play.png +0 -0
  183. data/app/views/admin_templates/good/zapanel/skins/default/lightbox-playvideo.png +0 -0
  184. data/app/views/admin_templates/good/zapanel/skins/default/lightbox-prev.png +0 -0
  185. data/app/views/admin_templates/good/zapanel/slider.html +0 -453
  186. data/app/views/admin_templates/good/zapanel/tables.html +0 -470
  187. data/app/views/admin_templates/good/zapanel/typography.html +0 -746
@@ -0,0 +1,452 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module KirguduBase
4
+ module Security
5
+ class AuthenticationsController < ::KirguduBase::ApplicationController
6
+
7
+ before_action :redirect_if_loggedin, only: :login
8
+
9
+ # before_action :on_before_login, only: :login
10
+ # after_action :on_after_login, only: :login
11
+
12
+ #include ApplicationHelper
13
+
14
+ DEFAULT_FROM = "kirgudu.net@gmail.com"
15
+
16
+
17
+ def login
18
+ local_data = {
19
+ messages: [],
20
+ errors: []
21
+ }
22
+ params_to_local_data = [:email, :password, :token_id, :redirect_to]
23
+ params_to_local_data.each do |param_name|
24
+ local_data[param_name] = params[param_name] if params[param_name]
25
+ end
26
+
27
+ session[:redirect_to] = params[:redirect_to] if params[:redirect_to]
28
+
29
+ logger.info("AUTH CONTROLLER TEMPLATE: #{self.class.get_method_latest_result(:get_kb_template)}")
30
+ logger.info("LOGIN VIEW PATH: #{self.class.get_method_latest_result(:get_kb_template)}/authentications/login")
31
+
32
+ render "#{self.class.get_method_latest_result(:get_kb_template)}/authentications/login", locals: {data: local_data}, layout: "#{self.class.get_method_latest_result(:get_kb_template)}/layouts/application"
33
+ end
34
+
35
+ def login_process
36
+ local_data = {
37
+ messages: [],
38
+ errors: []
39
+ }
40
+
41
+ local_data[:user] = ::KirguduBase::Security::User.where(email: params[:email]).first
42
+
43
+ params_to_local_data = [:email, :password, :token_id, :redirect_to]
44
+ params_to_local_data.each do |param_name|
45
+ local_data[param_name] = params[param_name] if params[param_name]
46
+ end
47
+
48
+ process_result = false
49
+
50
+
51
+ if local_data[:user] && local_data[:user].password == ::ChupakabraTools::Security.get_password_hash(params[:password])
52
+
53
+ session_expire_timeout = nil
54
+ # session_expire_timeout = @settings_manager.get('session_expire_timeout') if @settings_manager.get('session_expire_timeout') && params[:remember_me] == false
55
+ # session_expire_timeout = @settings_manager.get('session_expire_remember_timeout') if @settings_manager.get('session_expire_remember_timeout') && params[:remember_me] == true
56
+ session_expire_timeout = 1.hour if session_expire_timeout.nil?
57
+
58
+
59
+ session[:user_id] = local_data[:user].id
60
+ session[:user_expire] = DateTime.now + session_expire_timeout
61
+ session[:remember_me] = params[:remember_me] == true
62
+ process_result = true
63
+
64
+ else
65
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.login.errors.generic_user_password")
66
+ end
67
+ unless verify_recaptcha
68
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.login.errors.captcha_error")
69
+ process_result = false
70
+ end
71
+
72
+
73
+ if process_result
74
+ redirect_to session[:return_to] || ::KirguduBase.url_for_default_redirection_after_login || "/"
75
+ else
76
+ render "#{self.class.get_method_latest_result(:get_kb_template)}/authentications/login", locals: {data: local_data}, layout: "#{self.class.get_method_latest_result(:get_kb_template)}/layouts/application"
77
+ end
78
+ end
79
+
80
+
81
+ def one_time_pass_login
82
+ local_data = {}
83
+ render "#{self.class.get_method_latest_result(:get_kb_template)}/authentications/token_login", locals: {data: local_data}, layout: "#{self.class.get_method_latest_result(:get_kb_template)}/layouts/application"
84
+
85
+ end
86
+
87
+ def one_time_pass_login_process
88
+ end
89
+
90
+ def direct_login
91
+ local_data[:app_id] = params[:app_id]
92
+ local_data[:email] = params[:email]
93
+ local_data[:password] = params[:password]
94
+
95
+
96
+
97
+
98
+ end
99
+
100
+ def logout
101
+ security_logout(session)
102
+
103
+ session[:user_id] = nil
104
+ session[:user_expire] = 1.day.ago
105
+ session[:remember_me] = false
106
+ redirect_to url_for(controller: ::KirguduBase::Security::AuthenticationsController.to_route_path, action: 'login')
107
+ end
108
+
109
+ def create
110
+
111
+ omniauth = request.env["omniauth.auth"]
112
+ # Checking if External Authentication Services Allowed
113
+ external_authentication_allowed = Option.where(name: 'external_authentication_allowed').first
114
+
115
+ if !external_authentication_allowed.nil? && external_authentication_allowed == false
116
+ flash[:error] = "External Authentication Services are prohibited. Pleas Login with Your Local Account"
117
+ redirect_to ::KirguduBase::Security::AuthenticationsController.to_url_for(action: :login)
118
+ return
119
+ end
120
+
121
+ authentication = ::KirguduBase::Security::Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
122
+ if authentication
123
+ flash[:notice] = "Signed in successfully."
124
+ session[:user_id] = authentication.user.id
125
+ session[:user_provider] = authentication.provider
126
+ #sign_in_and_redirect(:user, authentication.user)
127
+ #redirect_to home_path
128
+ return
129
+ elsif @current_website
130
+ authentication = @current_website.authentications.create!(
131
+ provider: omniauth['provider'],
132
+ uid: omniauth['uid']
133
+ )
134
+ session[:user_provider] = authentication.provider
135
+ flash[:notice] = "Authentication successful."
136
+ #redirect_to home_path
137
+ return
138
+ else
139
+ user_params = {
140
+ first_name: omniauth.info.first_name || "",
141
+ last_name: omniauth.info.last_name || "",
142
+ email: omniauth.info.email,
143
+ #phone: "",
144
+ password: ::ChupakabraTools::Security.generate_secret(length: 10)
145
+ }
146
+
147
+ local_data[:user] = ::KirguduBase::Security::User.new(user_params)
148
+
149
+ if local_data[:user].save
150
+ authentication = local_data[:user].authentications.create!(
151
+ provider: omniauth['provider'],
152
+ uid: omniauth['uid']
153
+ )
154
+ session[:user_provider] = authentication.provider
155
+ flash[:notice] = "Signed in successfully."
156
+ session[:user_id] = local_data[:user].id
157
+ #redirect_to home_path
158
+ return
159
+ else
160
+ #session[:omniauth] = omniauth.except('extra')
161
+ redirect_to url_for(controller: ::KirguduBase::Security::AuthenticationsController.to_route_path, action: :register)
162
+ return
163
+ end
164
+ end
165
+ end
166
+
167
+ def register
168
+ local_data = {
169
+ messages: [],
170
+ errors: [],
171
+ user: ::KirguduBase::Security::User.new
172
+ }
173
+
174
+ params_to_local_data = [:token_id, :redirect_to]
175
+ params_to_local_data.each do |param_name|
176
+ local_data[param_name] = params[param_name] if params[param_name]
177
+ end
178
+
179
+
180
+ render "#{self.class.get_method_latest_result(:get_kb_template)}/authentications/register", locals: {data: local_data}, layout: "#{self.class.get_method_latest_result(:get_kb_template)}/layouts/application"
181
+ end
182
+
183
+ def register_process
184
+
185
+ params_user = params[::KirguduBase::Security::User.for_form_params]
186
+ local_data = {
187
+ errors: [],
188
+ messages: [],
189
+ user: ::KirguduBase::Security::User.new(self.strong_params_on_create)
190
+ }
191
+
192
+ params_to_local_data = [:token_id, :redirect_to]
193
+ params_to_local_data.each do |param_name|
194
+ local_data[param_name] = params[param_name] if params[param_name]
195
+ end
196
+
197
+
198
+ local_data[:user].email = params_user[:email]
199
+ local_data[:user].password = params_user[:password]
200
+ local_data[:user].password_confirmation = params_user[:password_confirmation]
201
+ local_data[:user].uin ||= ::SecureRandom.uuid
202
+
203
+ process_result = false
204
+
205
+ existent_user = ::KirguduBase::Security::User.get_by_email(local_data[:user].email)
206
+ if existent_user
207
+ local_data[:user].errors[:email] << I18n.t("kirgudu_base.authentications.register.errors.user_already_exists")
208
+ else
209
+ local_data[:user].created_at = DateTime.now
210
+ local_data[:user].updated_at = DateTime.now
211
+ if local_data[:user].valid?
212
+ user_plain_text_password = local_data[:user].password
213
+ local_data[:user].password = ::ChupakabraTools::Security.get_password_hash(local_data[:user].password)
214
+ local_data[:user].password_confirmation = local_data[:user].password
215
+ ActiveRecord::Base.transaction do
216
+ if local_data[:user].save
217
+ if local_data[:user].authentications.create!(provider: "kirgudu", uid: local_data[:user].uin)
218
+ local_data[:messages] << I18n.t("kirgudu_base.authentications.register.messages.user_created")
219
+ process_result = true
220
+ else
221
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.register.errors.cannot_create_authentication")
222
+ raise ::ActiveRecord::Rollback
223
+ end
224
+ else
225
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.register.errors.failed_to_save_user")
226
+ end
227
+ end
228
+ end
229
+ end
230
+
231
+ unless verify_recaptcha
232
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.register.errors.captcha_error")
233
+ process_result = false
234
+ end
235
+
236
+ if process_result
237
+ local_data[:user].password = user_plain_text_password
238
+ local_data[:user].password_confirmation = local_data[:user].password
239
+ render "/authentications/register_successful", locals: {data: local_data}
240
+ else
241
+ render "#{self.class.get_method_latest_result(:get_kb_template)}/authentications/register", locals: {data: local_data}, layout: "#{self.class.get_method_latest_result(:get_kb_template)}/layouts/application"
242
+ end
243
+ end
244
+
245
+ def restore_password
246
+ local_data = {
247
+ errors: [],
248
+ messages: []
249
+ }
250
+
251
+ params_to_local_data = [:token_id, :redirect_to, :email]
252
+ params_to_local_data.each do |param_name|
253
+ local_data[param_name] = params[param_name] if params[param_name]
254
+ end
255
+ render "#{self.class.get_method_latest_result(:get_kb_template)}/authentications/restore_password", locals: {data: local_data}, layout: "#{self.class.get_method_latest_result(:get_kb_template)}/layouts/application"
256
+ end
257
+
258
+ def restore_password_send
259
+ local_data = {
260
+ errors: [],
261
+ messages: []
262
+ }
263
+ params_to_local_data = [:token_id, :redirect_to, :email]
264
+ params_to_local_data.each do |param_name|
265
+ local_data[param_name] = params[param_name] if params[param_name]
266
+ end
267
+
268
+ process_result = false
269
+
270
+ if verify_recaptcha
271
+ if local_data[:email] && !local_data[:email].blank?
272
+ if local_data[:email]
273
+ user = ::KirguduBase::Security::User.get_by_email(local_data[:email])
274
+ if user
275
+ restore = ::KirguduBase::Security::RestorePasswordCode.where { (expire_at > Time.now) & (is_used == false) }.order(::KirguduBase::Security::RestorePasswordCode.for_sql_order_by(:created_at, :desc)).first
276
+ unless restore
277
+ restore = ::KirguduBase::Security::RestorePasswordCode.new(expire_at: 30.minute.from_now, code: 100000 + SecureRandom.random_number(899999), user_id: user.id)
278
+ unless restore.save
279
+ restore = nil
280
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.cant_create_restore_code")
281
+ end
282
+ end
283
+ if restore
284
+ # begin
285
+ ::KirguduBase::AuthenticationsMailer.restore_password_code(DEFAULT_FROM, user.email, user, restore).deliver!
286
+ process_result = true
287
+ restore.sent_at = Time.now
288
+ restore.save
289
+ # rescue
290
+ # local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.mail_delivery_error")
291
+ # end
292
+
293
+ end
294
+ else
295
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.user_not_found")
296
+ end
297
+ else
298
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.email_wrong_format")
299
+ end
300
+ else
301
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.email_cannot_be_empty")
302
+ end
303
+ else
304
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.captcha_error")
305
+ end
306
+
307
+
308
+ if process_result
309
+ redirect_to ::KirguduBase.authentications_controller.to_url_for(:restore_password_code, email: user.email)
310
+ else
311
+ render "#{self.class.get_method_latest_result(:get_kb_template)}/authentications/restore_password", locals: {data: local_data}, layout: "#{self.class.get_method_latest_result(:get_kb_template)}/layouts/application"
312
+ end
313
+
314
+ end
315
+
316
+ def restore_password_code
317
+ local_data = {
318
+ errors: [],
319
+ messages: []
320
+ }
321
+
322
+ params_to_local_data = [:token_id, :redirect_to, :email, :id, :code]
323
+ params_to_local_data.each do |param_name|
324
+ local_data[param_name] = params[param_name] if params[param_name]
325
+ end
326
+ render "#{self.class.get_method_latest_result(:get_kb_template)}/authentications/restore_password_code", locals: {data: local_data}, layout: "#{self.class.get_method_latest_result(:get_kb_template)}/layouts/application"
327
+ end
328
+
329
+ def restore_password_code_process
330
+ local_data = {
331
+ errors: [],
332
+ messages: []
333
+ }
334
+ params_to_local_data = [:token_id, :redirect_to, :email, :id, :code]
335
+ params_to_local_data.each do |param_name|
336
+ local_data[param_name] = params[param_name] if params[param_name]
337
+ end
338
+
339
+ restore_code = nil
340
+ restore_code = ::KirguduBase::Security::RestorePasswordCode.find(local_data[:id]) if local_data[:id]
341
+
342
+ process_result = false
343
+ if restore_code && restore_code.code == local_data[:code]
344
+ unless restore_code.is_used?
345
+ password = ::ChupakabraTools::Security.generate_secret(length: 8)
346
+ restore_code.user.password = ::ChupakabraTools::Security.get_password_hash(password)
347
+ if restore_code.user.save
348
+ #begin
349
+ ::KirguduBase::AuthenticationsMailer.restore_password_success(DEFAULT_FROM, restore_code.user.email, restore_code.user, password).deliver!
350
+ local_data[:email] = restore_code.user.email
351
+ process_result = true
352
+ restore_code.is_used = true
353
+ restore_code.save
354
+ # rescue
355
+ # local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password_code.errors.failed_to_send_password")
356
+ # end
357
+ else
358
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password_code.errors.failed_to_save_password")
359
+ end
360
+ else
361
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password_code.errors.used_code")
362
+ end
363
+
364
+
365
+ else
366
+ local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password_code.errors.wrong_code")
367
+ process_result = false
368
+ end
369
+
370
+
371
+ if process_result
372
+ redirect_to ::KirguduBase.authentications_controller.to_url_for(:restore_password_success, email: local_data[:email])
373
+ else
374
+ render "#{self.class.get_method_latest_result(:get_kb_template)}/authentications/restore_password_code", locals: {data: local_data}
375
+ end
376
+ end
377
+
378
+ def restore_password_success
379
+ local_data = {
380
+ errors: [],
381
+ messages: []
382
+ }
383
+ params_to_local_data = [:token_id, :redirect_to, :email, :id, :code]
384
+ params_to_local_data.each do |param_name|
385
+ local_data[param_name] = params[param_name] if params[param_name]
386
+ end
387
+ render "#{self.class.get_method_latest_result(:get_kb_template)}/authentications/restore_password_success", locals: {data: local_data}
388
+
389
+ end
390
+
391
+
392
+ def confirm_email
393
+ local_data = {
394
+ errors: [],
395
+ messages: []
396
+ }
397
+
398
+ end
399
+
400
+ def confirm_email_process
401
+
402
+ end
403
+
404
+ def destroy
405
+
406
+ end
407
+
408
+ def destroy_process
409
+
410
+ local_data = {}
411
+
412
+ local_data[:user] = ::KirguduBase::Security::User.where(id: session[:user_id])
413
+
414
+ if local_data[:user]
415
+ if local_data[:user].destroy
416
+ flash[:notice] = "Successfully destroyed authentication."
417
+ redirect_to authentications_url
418
+ else
419
+ # failed to delete user
420
+ end
421
+ else
422
+
423
+ end
424
+ end
425
+
426
+
427
+ protected
428
+ def on_before_login
429
+
430
+ end
431
+
432
+ def on_after_login
433
+
434
+ end
435
+
436
+ def strong_params_on_create
437
+ params.require(::KirguduBase::Security::User.for_form_params).permit(:email, :first_name, :last_name, :password, :password_confirmation)
438
+ end
439
+
440
+ private
441
+ def redirect_if_loggedin
442
+ if @current_user
443
+ if session[:token_id]
444
+
445
+ else
446
+ redirect_to params[:return_to] || session[:return_to] || ::KirguduBase.url_for_default_redirection_after_login || "/"
447
+ end
448
+ end
449
+ end
450
+ end
451
+ end
452
+ end
@@ -0,0 +1,46 @@
1
+ module KirguduBase
2
+
3
+ module Security
4
+ class AuthenticationsController < ::KirguduBase::ApplicationController
5
+
6
+ def confirm
7
+ local_data = {
8
+ errors: [],
9
+ messages: []
10
+ }
11
+ local_data[:email] = params[:email]
12
+ local_data[:code] = params[:code]
13
+
14
+ render
15
+
16
+ end
17
+
18
+ def process
19
+ local_data = {
20
+ messages: [],
21
+ errors: []
22
+ }
23
+ transaction_result = true
24
+
25
+ if params[:email]
26
+ user = ::KirguduBase::Security::User.get_by_email(params[:email])
27
+ if user
28
+ confirmation = ::KirguduBase::Security::EmailConfirmation.where
29
+ else
30
+ local_data[:errors] = "User With This Email Not Found"
31
+ transaction_result = false
32
+ end
33
+ else
34
+ local_data[:errors] = "Email Not Supplied"
35
+ transaction_result = false
36
+ end
37
+
38
+ if transaction_result
39
+ else
40
+
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -67,6 +67,31 @@ module KirguduBase
67
67
  params_new
68
68
  end
69
69
 
70
+ def kb_dynamic_form_for(item, options, &proc)
71
+ options ||= {}
72
+ options[:builder] = ::KirguduBase::FormBuilder
73
+
74
+ html_options = options[:html] || {}
75
+ classes = html_options[:class]
76
+ # if classes
77
+ # classes += " form-horizontal row-fluid"
78
+ # else
79
+ # classes = "form-horizontal row-fluid"
80
+ # end
81
+ html_options.merge!(class: classes)
82
+
83
+ options.merge!(html: html_options)
84
+ form_for(item, options, &proc)
85
+ end
86
+
87
+
88
+ def kb_auth_form_for(item, options, &proc)
89
+ options ||= {}
90
+ options[:builder] = ::KirguduBase::AuthenticationFormBuilder
91
+
92
+ form_for(item, options, &proc)
93
+ end
94
+
70
95
 
71
96
  def print_property item, method, options = {}
72
97
 
@@ -0,0 +1,76 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module KirguduBase
4
+ class AuthenticationFormBuilder < ActionView::Helpers::FormBuilder
5
+
6
+ include ActionView::Helpers::AssetTagHelper
7
+ include ActionView::Helpers::TagHelper
8
+
9
+ #include ::KirguduBase::GuiHelper
10
+
11
+
12
+ def error_label(label, html_options = {})
13
+
14
+ html_options.merge!(generated: "true", style: "display: block")
15
+
16
+ html_options_add_class(html_options, "error") if @object.errors[label].present?
17
+
18
+ errors_in_html = []
19
+
20
+ @object.errors[label].each do |error_message|
21
+ errors_in_html << @template.content_tag("label", error_message.capitalize.html_safe, html_options)
22
+ end if @object.errors[label].present?
23
+
24
+ errors_in_html.join("").html_safe
25
+ end
26
+
27
+ def label(label, html_options = {})
28
+ @template.content_tag("label", html_options) do
29
+ @object.class.human_attribute_name(label)
30
+ end
31
+ end
32
+
33
+
34
+ def text_field(label, value, html_options = {})
35
+ html_options ||= {}
36
+ html_options.merge!(
37
+ {
38
+ id: "#{@object.class.for_form_params}_#{label}",
39
+ name: "#{@object.class.for_form_params}[#{label}]",
40
+ type: "text",
41
+ value: value || @object[label]
42
+ }
43
+ )
44
+ html_options_add_class(html_options, "error") if @object.errors[label].present?
45
+ @template.content_tag("input", "", html_options)
46
+ end
47
+
48
+ def password_field(label, value, html_options = {})
49
+ html_options ||= {}
50
+ html_options.merge!(
51
+ {
52
+ id: "#{@object.class.for_form_params}_#{label}",
53
+ name: "#{@object.class.for_form_params}[#{label}]",
54
+ type: "password",
55
+ value: value || @object[label]
56
+ }
57
+ )
58
+ html_options_add_class(html_options, "error") if @object.errors[label].present?
59
+ @template.content_tag("input", "", html_options)
60
+ end
61
+
62
+ private
63
+ def html_options_add_class(html_options, classes_to_add)
64
+ classes = html_options[:class] ? html_options[:class].split(' ') : []
65
+ if classes_to_add.is_a?(Array)
66
+ classes_to_add.each do |item|
67
+ classes << item.to_s unless classes.include?(item.to_s)
68
+ end
69
+ else
70
+ classes << classes_to_add.to_s unless classes.include?(classes_to_add.to_s)
71
+ end
72
+ html_options[:class] = classes.join(" ") if classes.length > 0
73
+ end
74
+
75
+ end
76
+ end