Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow creation of default user through web interface.

[#553 state:resolved]
  • Loading branch information...
commit 53e755001e0122eb0620b630b60ab28a7be6fb2e 1 parent 1fb61ad
Sean Schofield schof authored
122 app/controllers/application.rb
@@ -16,75 +16,79 @@ class ApplicationController < ActionController::Base
16 16 include EasyRoleRequirementSystem
17 17 include SslRequirement
18 18
19   - private
20   - def current_user_session
21   - return @current_user_session if defined?(@current_user_session)
22   - @current_user_session = UserSession.find
23   - end
  19 + def admin_created?
  20 + User.first(:include => :roles, :conditions => ["roles.name = 'admin'"])
  21 + end
  22 +
  23 + private
  24 + def current_user_session
  25 + return @current_user_session if defined?(@current_user_session)
  26 + @current_user_session = UserSession.find
  27 + end
24 28
25   - def current_user
26   - return @current_user if defined?(@current_user)
27   - @current_user = current_user_session && current_user_session.user
28   - end
  29 + def current_user
  30 + return @current_user if defined?(@current_user)
  31 + @current_user = current_user_session && current_user_session.user
  32 + end
29 33
30   - def require_user
31   - unless current_user
32   - store_location
33   - flash[:notice] = "You must be logged in to access this page"
34   - redirect_to new_user_session_url
35   - return false
36   - end
  34 + def require_user
  35 + unless current_user
  36 + store_location
  37 + flash[:notice] = "You must be logged in to access this page"
  38 + redirect_to new_user_session_url
  39 + return false
37 40 end
  41 + end
38 42
39   - def require_no_user
40   - if current_user
41   - store_location
42   - flash[:notice] = "You must be logged out to access this page"
43   - redirect_to account_url
44   - return false
45   - end
  43 + def require_no_user
  44 + if current_user
  45 + store_location
  46 + flash[:notice] = "You must be logged out to access this page"
  47 + redirect_to account_url
  48 + return false
46 49 end
  50 + end
47 51
48   - def store_location
49   - session[:return_to] = request.request_uri
50   - end
  52 + def store_location
  53 + session[:return_to] = request.request_uri
  54 + end
51 55
52   - def redirect_back_or_default(default)
53   - redirect_to(session[:return_to] || default)
54   - session[:return_to] = nil
55   - end
  56 + def redirect_back_or_default(default)
  57 + redirect_to(session[:return_to] || default)
  58 + session[:return_to] = nil
  59 + end
56 60
57   - # Redirect as appropriate when an access request fails.
58   - #
59   - # The default action is to redirect to the login screen.
60   - #
61   - # Override this method in your controllers if you want to have special
62   - # behavior in case the user is not authorized
63   - # to access the requested action. For example, a popup window might
64   - # simply close itself.
65   - def access_denied
66   - respond_to do |format|
67   - format.html do
68   - if current_user
69   - flash[:error] = t("authorization_failure")
70   - redirect_to '/user_sessions/authorization_failure'
71   - next
72   - else
73   - store_location
74   - redirect_to login_path
75   - next
76   - end
77   - end
78   - format.xml do
79   - request_http_basic_authentication 'Web Password'
  61 + # Redirect as appropriate when an access request fails.
  62 + #
  63 + # The default action is to redirect to the login screen.
  64 + #
  65 + # Override this method in your controllers if you want to have special
  66 + # behavior in case the user is not authorized
  67 + # to access the requested action. For example, a popup window might
  68 + # simply close itself.
  69 + def access_denied
  70 + respond_to do |format|
  71 + format.html do
  72 + if current_user
  73 + flash[:error] = t("authorization_failure")
  74 + redirect_to '/user_sessions/authorization_failure'
  75 + next
  76 + else
  77 + store_location
  78 + redirect_to login_path
  79 + next
80 80 end
81 81 end
  82 + format.xml do
  83 + request_http_basic_authentication 'Web Password'
  84 + end
82 85 end
  86 + end
  87 +
  88 + def instantiate_controller_and_action_names
  89 + @current_action = action_name
  90 + @current_controller = controller_name
83 91
84   - def instantiate_controller_and_action_names
85   - @current_action = action_name
86   - @current_controller = controller_name
87   -
88   - @taxonomies = Taxonomy.find(:all, :include => {:root => :children})
89   - end
  92 + @taxonomies = Taxonomy.find(:all, :include => {:root => :children})
  93 + end
90 94 end
13 app/controllers/products_controller.rb
... ... @@ -1,6 +1,8 @@
1 1 class ProductsController < Spree::BaseController
  2 + before_filter :setup_admin_user
  3 +
2 4 resource_controller
3   - helper :taxons
  5 + helper :taxons
4 6 before_filter :load_data, :only => :show
5 7 actions :show, :index
6 8
@@ -17,8 +19,13 @@ def change_image
17 19 end
18 20
19 21 private
20   - def load_data
21   -
  22 + def setup_admin_user
  23 + return if admin_created?
  24 + flash[:notice] = I18n.t(:please_create_user)
  25 + redirect_to signup_url
  26 + end
  27 +
  28 + def load_data
22 29 return unless permalink = params[:taxon_path]
23 30 @taxon = Taxon.find_by_permalink(params[:taxon_path].join("/") + "/")
24 31 end
5 app/controllers/users_controller.rb
@@ -14,6 +14,11 @@ class UsersController < Spree::BaseController
14 14 wants.js { render :js => true.to_json }
15 15 failure.wants.html { render :new }
16 16 failure.wants.js { render :js => @user.errors.to_json }
  17 + end
  18 +
  19 + create.after do
  20 + next if admin_created?
  21 + @user.roles << Role.find_by_name("admin")
17 22 end
18 23
19 24 show.before do
1  config/locales/da.yml
@@ -398,6 +398,7 @@ da:
398 398 payments: Payments
399 399 phone: Phone
400 400 place_order: Place Order
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Presentation
403 404 previous: Previous
1  config/locales/de-CH.yml
@@ -398,6 +398,7 @@ de-CH:
398 398 payments: Zahlungen
399 399 phone: Telefon
400 400 place_order: "Bestellung aufgeben"
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Anzeige
403 404 previous: zurück
1  config/locales/de.yml
@@ -398,6 +398,7 @@ de:
398 398 payments: Zahlungen
399 399 phone: Telefon
400 400 place_order: Place Order
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Anzeige
403 404 previous: zurück
1  config/locales/en-GB.yml
@@ -398,6 +398,7 @@ en-GB:
398 398 payments: Payments
399 399 phone: Phone
400 400 place_order: Place Order
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Presentation
403 404 previous: Previous
1  config/locales/en-US.yml
@@ -398,6 +398,7 @@ en-US:
398 398 payments: Payments
399 399 phone: Phone
400 400 place_order: Place Order
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Presentation
403 404 previous: Previous
1  config/locales/es.yml
@@ -398,6 +398,7 @@ es:
398 398 payments: Pagos
399 399 phone: Teléfono
400 400 place_order: Hacer pedido
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Presentación
403 404 previous: Anterior
1  config/locales/fr-FR.yml
@@ -398,6 +398,7 @@ fr-FR:
398 398 payments: Paiements
399 399 phone: Téléphone
400 400 place_order: Place Order
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Presentation
403 404 previous: Précédent
54 config/locales/il.yml
@@ -46,10 +46,8 @@ il:
46 46 ip_address: "IP Address"
47 47 item_total: "Item Total"
48 48 number: Number
49   - ship_amount: "Ship Amount"
50 49 special_instructions: "Special Instructions"
51 50 state: מדינה
52   - tax_amount: "Tax Amount"
53 51 total: Total
54 52 product:
55 53 available_on: "Available On"
@@ -58,6 +56,7 @@ il:
58 56 name: Name
59 57 on_hand: "On Hand"
60 58 shipping_category: "Shipping Category"
  59 + tax_category: "Tax Category"
61 60 property:
62 61 name: Name
63 62 presentation: Presentation
@@ -68,6 +67,11 @@ il:
68 67 state:
69 68 abbr: Abbreviation
70 69 name: Name
  70 + tax_category:
  71 + description: Description
  72 + name: Name
  73 + tax_rate:
  74 + amount: Rate
71 75 taxon:
72 76 name: Name
73 77 permalink: Permalink
@@ -132,6 +136,12 @@ il:
132 136 state:
133 137 one: State
134 138 other: States
  139 + tax_category:
  140 + one: "Tax Category"
  141 + other: "Tax Categories"
  142 + tax_rate:
  143 + one: "Tax Rate"
  144 + other: "Tax Rates"
135 145 taxon:
136 146 one: Taxon
137 147 other: Taxons
@@ -164,7 +174,9 @@ il:
164 174 allow_backorders: "Allow Backorders"
165 175 allow_ssl_to_be_used_when_in_developement_and_test_modes: Allow SSL to be used when in development and test modes
166 176 allow_ssl_to_be_used_when_in_production_mode: Allow SSL to be used in production mode
  177 + allowed_ssl_in_production_mode: "SSL will {{not}} be used in production"
167 178 already_registered: Already Registered?
  179 + alternative_phone: Alternative Phone
168 180 amount: Amount
169 181 are_you_sure: "Are you sure"
170 182 are_you_sure_category: "Are you sure you want to delete this category?"
@@ -180,6 +192,7 @@ il:
180 192 available_taxons: "Available Taxons"
181 193 back: Back
182 194 back_to_store: "Go Back To Store"
  195 + backordering_is_allowed: "Backordering {{not}} allowed"
183 196 bill_address: "Bill Address"
184 197 billing_address: "כתובת למשלוח חשבונית"
185 198 cancel: cancel
@@ -187,6 +200,7 @@ il:
187 200 capture: capture
188 201 card_code: "קוד כרטיס"
189 202 card_number: "מספר כרטיס"
  203 + card_type_is: Card type is
190 204 cart: עגלה
191 205 categories: Categories
192 206 category: Category
@@ -235,6 +249,7 @@ il:
235 249 editing_shipping_method: "Editing Shipping Method"
236 250 editing_state: "Editing State"
237 251 editing_tax_category: "Editing Tax Category"
  252 + editing_tax_rate: "Editing Tax Rate"
238 253 editing_user: "Editing User"
239 254 editing_zone: "Editing Zone"
240 255 email: Email
@@ -242,6 +257,7 @@ il:
242 257 email_server_settings_description: "Set email server settings."
243 258 empty_cart: "רוקן עגלה"
244 259 enable_mail_delivery: Enable Mail Delivery
  260 + enter_exactly_as_shown_on_card: Please enter exactly as shown on the card
245 261 error: error
246 262 event: Event
247 263 existing_customer: "Existing Customer"
@@ -255,6 +271,7 @@ il:
255 271 first_name: "שם פרטי"
256 272 forgot_password: "Forgot Password"
257 273 gateway: Gateway
  274 + gateway_configuration: "Gateway configuration"
258 275 gateway_error: "Gateway Error"
259 276 gateway_setting_description: "Select a payment gateway and configure its settings."
260 277 general: "General"
@@ -271,6 +288,7 @@ il:
271 288 hello_user: "Hello User"
272 289 history: History
273 290 home: "עמוד הבית"
  291 + icons_by: "Icons by"
274 292 image: Image
275 293 images: Images
276 294 in_progress: "In Progress"
@@ -279,6 +297,7 @@ il:
279 297 inventory_adjustment: "Inventory Adjustment"
280 298 inventory_setting_description: "Inventory Configuration, Backordering, Zero-Stock Display"
281 299 inventory_settings: "Inventory Settings"
  300 + issue_number: Issue Number
282 301 item: פריט
283 302 item_description: "Item Description"
284 303 item_total: "Item Total"
@@ -290,6 +309,7 @@ il:
290 309 listing_reports: "Listing Reports"
291 310 listing_tax_categories: "Listing Tax Categories"
292 311 listing_users: "Listing Users"
  312 + loading: Loading
293 313 locale_changed: "Locale Changed"
294 314 log_in: "התחברות"
295 315 logged_in_as: "Logged in as"
@@ -299,6 +319,7 @@ il:
299 319 login_failed: "Login authentication failed."
300 320 login_name: Login
301 321 logout: יציאה
  322 + maestro_or_solo_cards: Maestro/Solo cards
302 323 mail_delivery_enabled: "Mail delivery is enabled"
303 324 mail_delivery_not_enabled: "Mail delivery is not enabled"
304 325 mail_server_preferences: Mail Server Preferences
@@ -328,6 +349,7 @@ il:
328 349 new_state: "New State"
329 350 new_tax_category: "New Tax Category"
330 351 new_tax_rate: "New Tax Rate"
  352 + new_taxon: "New Taxon"
331 353 new_taxonomy: "New Taxonomy"
332 354 new_user: "New User"
333 355 new_variant: "New Variant"
@@ -338,6 +360,7 @@ il:
338 360 no_user_found: "No user was found with that email address"
339 361 none: None
340 362 none_available: "None Available"
  363 + not: not
341 364 on_hand: "On Hand"
342 365 operation: Operation
343 366 option_Values: "Option Values"
@@ -350,6 +373,7 @@ il:
350 373 order_date: "Order Date"
351 374 order_details: "Order Details"
352 375 order_email_resent: "Order Email Resent"
  376 + order_not_in_system: That order number is not valid on this site.
353 377 order_number: Order
354 378 order_operation_authorize: Authorize
355 379 order_processed_successfully: "Your order has been processed successfully"
@@ -374,6 +398,8 @@ il:
374 398 payments: Payments
375 399 phone: טלפון
376 400 place_order: הזמן
  401 + please_create_user: "Please create a user account"
  402 + powered_by: "Powered by"
377 403 presentation: Presentation
378 404 previous: Previous
379 405 price: מחיר
@@ -384,8 +410,10 @@ il:
384 410 process: Process
385 411 product: Product
386 412 product_details: "Product Details"
  413 + product_has_no_description: Product has not description
387 414 product_properties: "Product Properties"
388 415 products: Products
  416 + products_with_zero_inventory_display: "Products with a zero inventory will {{not}} be displayed"
389 417 properties: Properties
390 418 property: Property
391 419 prototype: Prototype
@@ -398,6 +426,7 @@ il:
398 426 remember_me: "Remember me"
399 427 remove: Remove
400 428 reports: Reports
  429 + required_for_solo_and_maestro: Required for Solo and Maestro cards.
401 430 resend: Resend
402 431 reset_password: "Reset my password"
403 432 response_code: "Response Code"
@@ -420,6 +449,7 @@ il:
420 449 send_copy_of_orders_mails_to: Send Copy of Order Mails To
421 450 send_mails_as: Send Mails As
422 451 send_order_mails_as: Send Order Mails As
  452 + server_error: "The server returned an error"
423 453 ship: ship
424 454 ship_address: "Ship Address"
425 455 shipment: Shipment
@@ -432,6 +462,7 @@ il:
432 462 shipping_categories_description: "Manage shipping categories to identify which products can be shipped via which method"
433 463 shipping_cost: Cost
434 464 shipping_error: "Shipping Error"
  465 + shipping_instructions: "Shipping Instructions"
435 466 shipping_method: אופן המשלוח
436 467 shipping_methods: "Shipping Methods"
437 468 shipping_methods_description: "Manage shipping methods"
@@ -442,6 +473,7 @@ il:
442 473 show_incomplete_orders: "Show Incomplete Orders"
443 474 show_only_complete_orders: "Only show complete orders"
444 475 show_out_of_stock_products: "Show out-of-stock products"
  476 + show_price_inc_vat: "Show price including VAT"
445 477 sign_up: "Sign up"
446 478 site_name: "Site Name"
447 479 site_url: "Site URL"
@@ -452,11 +484,20 @@ il:
452 484 smtp_mail_host: SMTP Mail Host
453 485 smtp_password: SMTP Password
454 486 smtp_port: SMTP Port
  487 + smtp_send_all_emails_as_from_following_address: "Send all mails as from the following address."
  488 + smtp_send_copy_of_orders_to_this_addresses: "Sends a copy of all order's mails to this address. For multiple addresses, separate with commas."
  489 + smtp_send_copy_to_this_addresses: "Sends a copy of all outgoing mails to this address. For multiple addresses, separate with commas."
  490 + smtp_send_order_mails_as_from_following_address: "Send orders mails as from the following address."
455 491 smtp_username: SMTP Username
456 492 spree:
457 493 date: Date
458 494 time: Time
  495 + ssl_will_be_used_in_development_and_test_modes: "SSL will be used in development and test mode if necessary."
  496 + ssl_will_be_used_in_production_mode: "SSL will be used in production mode"
  497 + ssl_will_not_be_used_in_development_and_test_modes: "SSL will not be used in development and test mode if necessary."
  498 + ssl_will_not_be_used_in_production_mode: "SSL will not be used in production mode"
459 499 start: Start
  500 + start_date: Valid from
460 501 state: מדינה
461 502 state_based: "State Based"
462 503 state_setting_description: "Administer the list of states/provinces associated with each country."
@@ -473,11 +514,18 @@ il:
473 514 tax_categories: "Tax Categories"
474 515 tax_categories_setting_description: "Set up tax categories to identify which products should be taxable."
475 516 tax_category: "Tax Category"
  517 + tax_rates: "Tax Rates"
  518 + tax_rates_description: Tax rates setup and configuration.
  519 + tax_settings: "Tax Settings"
  520 + tax_settings_description: Basic tax settings.
476 521 tax_total: "Tax Total"
477 522 tax_type: "Tax Type"
478 523 taxon: Taxon
479 524 taxonomies: Taxonomies
480 525 taxonomies_setting_description: "Create and manage taxonomies"
  526 + taxonomy_edit: "Edit taxonomy"
  527 + taxonomy_tree_error: "The requested change has not been accepted and the tree has been returned to its previous state, please try again."
  528 + taxonomy_tree_instruction: "* Right click a child in the tree to access the menu for adding, deleting or sorting a child."
481 529 taxons: Taxons
482 530 thank_you_for_your_order: "Thank you for your business. Please print out a copy of this confirmation page for your records."
483 531 this_file_language: "English (US)"
@@ -492,9 +540,11 @@ il:
492 540 unable_to_authorize_credit_card: "Unable to Authorize Credit Card"
493 541 unable_to_capture_credit_card: "Unable to Capture Credit Card"
494 542 unable_to_save_order: "Unable to Save Order"
  543 + unrecognized_card_type: Unrecognized card type
495 544 update: עדכן
496 545 update_password: "Update my password and log me in"
497 546 updated_successfully: "Updated Successfully"
  547 + updating: Updating
498 548 use_as_shipping_address: Use as Shipping Address
499 549 use_billing_address: זהה לכתובת למשלוח חשבונית
500 550 use_different_shipping_address: "Use Different Shipping Address"
1  config/locales/it.yml
@@ -398,6 +398,7 @@ it:
398 398 payments: Payments
399 399 phone: Telefono
400 400 place_order: Place Order
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Presentazione
403 404 previous: Indietro
1  config/locales/jp.yml
@@ -398,6 +398,7 @@ jp:
398 398 payments: 支払い方法
399 399 phone: 電話番号
400 400 place_order: Place Order
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: 表示名
403 404 previous: 前へ
1  config/locales/nb-NO.yml
@@ -398,6 +398,7 @@ nb-NO:
398 398 payments: Betalinger
399 399 phone: Telefon
400 400 place_order: "Bekreft ordre"
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Presentasjon
403 404 previous: Forrige
1  config/locales/nl-BE.yml
@@ -398,6 +398,7 @@ nl-BE:
398 398 payments: Betalingen
399 399 phone: Telefoon
400 400 place_order: Bestellen
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Presentatie
403 404 previous: vorige
1  config/locales/pl.yml
@@ -398,6 +398,7 @@ pl:
398 398 payments: Payments
399 399 phone: Telefon
400 400 place_order: Place Order
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Presentacja
403 404 previous: Poprzednie
1  config/locales/pt-BR.yml
@@ -398,6 +398,7 @@ pt-BR:
398 398 payments: Pagamentos
399 399 phone: Telefone
400 400 place_order: Coloque o Pedido
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Apresentação
403 404 previous: anterior
1  config/locales/pt-PT.yml
@@ -398,6 +398,7 @@ pt-PT:
398 398 payments: Pagamentos
399 399 phone: Telefone
400 400 place_order: Place Order
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Powered by"
402 403 presentation: Apresentação
403 404 previous: anterior
1  config/locales/ru-RU.yml
@@ -398,6 +398,7 @@ ru-RU:
398 398 payments: "Платежи"
399 399 phone: "Телефон"
400 400 place_order: "Разместить заказ"
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "Работает на"
402 403 presentation: "Отображение"
403 404 previous: "пред."
1  config/locales/th.yml
@@ -398,6 +398,7 @@ th:
398 398 payments: รายการจ่าย
399 399 phone: เบอร์โทรศัพท์
400 400 place_order: Place Order
  401 + please_create_user: "Please create a user account"
401 402 powered_by: "สนับสนุนโดย"
402 403 presentation: ชื่อที่แสดง
403 404 previous: ก่อนหน้า

0 comments on commit 53e7550

Please sign in to comment.
Something went wrong with that request. Please try again.