bbmb 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -3
  3. data/Gemfile +2 -0
  4. data/History.txt +11 -8
  5. data/Rakefile +1 -1
  6. data/bbmb.gemspec +3 -3
  7. data/lib/bbmb.rb +1 -1
  8. data/lib/bbmb/config.rb +6 -2
  9. data/lib/bbmb/html/state/change_password.rb +3 -3
  10. data/lib/bbmb/html/state/current_order.rb +1 -1
  11. data/lib/bbmb/html/state/customer.rb +6 -6
  12. data/lib/bbmb/html/state/customers.rb +2 -2
  13. data/lib/bbmb/html/state/global.rb +4 -2
  14. data/lib/bbmb/html/state/init.rb +1 -0
  15. data/lib/bbmb/html/state/login.rb +5 -1
  16. data/lib/bbmb/html/state/viral/admin.rb +2 -1
  17. data/lib/bbmb/html/state/viral/customer.rb +4 -3
  18. data/lib/bbmb/html/util/known_user.rb +42 -10
  19. data/lib/bbmb/html/util/session.rb +32 -7
  20. data/lib/bbmb/html/util/validator.rb +5 -5
  21. data/lib/bbmb/html/view/customers.rb +7 -22
  22. data/lib/bbmb/html/view/head.rb +1 -1
  23. data/lib/bbmb/html/view/navigation.rb +1 -0
  24. data/lib/bbmb/model/customer.rb +19 -6
  25. data/lib/bbmb/model/order.rb +8 -5
  26. data/lib/bbmb/model/product.rb +14 -45
  27. data/lib/bbmb/persistence/odba.rb +4 -4
  28. data/lib/bbmb/util/invoicer.rb +1 -0
  29. data/lib/bbmb/util/mail.rb +1 -2
  30. data/lib/bbmb/util/polling_manager.rb +11 -6
  31. data/lib/bbmb/util/server.rb +122 -68
  32. data/lib/bbmb/util/transfer_dat.rb +1 -1
  33. data/lib/bbmb/util/updater.rb +3 -3
  34. data/lib/bbmb/version.rb +1 -1
  35. data/test/html/state/test_customers.rb +1 -2
  36. data/test/model/test_customer.rb +1 -1
  37. data/test/model/test_order.rb +2 -2
  38. data/test/model/test_product.rb +11 -27
  39. data/test/model/test_promotion.rb +3 -3
  40. data/test/test_bbmb.rb +0 -1
  41. data/test/util/test_invoicer.rb +8 -8
  42. data/test/util/test_polling_manager.rb +12 -17
  43. data/test/util/test_server.rb +2 -6
  44. data/test/util/test_transfer_dat.rb +0 -3
  45. metadata +5 -20
@@ -6,7 +6,7 @@ require 'sbsm/validator'
6
6
  module BBMB
7
7
  module Html
8
8
  module Util
9
- class Validator < SBSM::Validator
9
+ class Validator < ::SBSM::Validator
10
10
  BOOLEAN = [ :accept_terms, :order_confirmation ]
11
11
  ENUMS = {
12
12
  :canton => [
@@ -32,17 +32,17 @@ class Validator < SBSM::Validator
32
32
  return nil if(value.empty?)
33
33
  match = /\d{13}/.match(value.to_s)
34
34
  unless match
35
- raise SBSM::InvalidDataError.new(:e_invalid_ean13, :ean13, value)
35
+ raise SBSM::InvalidDataError.new(:e_invalid_ean13, :ean13, value)
36
36
  end
37
37
  values = match[0].split("")
38
38
  check = values.pop
39
39
  sum = 0
40
- values.each_with_index { |val, index|
41
- modulus = ((index%2)*2)+1
40
+ values.each_with_index { |val, index|
41
+ modulus = ((index%2)*2)+1
42
42
  sum += (modulus*val.to_i)
43
43
  }
44
44
  unless (check.to_i == (10-(sum%10))%10)
45
- raise SBSM::InvalidDataError.new(:e_invalid_ean13, :ean13, value)
45
+ raise SBSM::InvalidDataError.new(:e_invalid_ean13, :ean13, value)
46
46
  end
47
47
  match[0]
48
48
  end
@@ -64,49 +64,34 @@ class CustomersList < HtmlGrid::List
64
64
  def customer_id(model)
65
65
  link = HtmlGrid::Link.new(:customer_id, model, @session, self)
66
66
  link.value = model.customer_id
67
- link.href = @lookandfeel._event_url(:customer,
67
+ link.href = @lookandfeel._event_url(:customer,
68
68
  {:customer_id => model.customer_id})
69
69
  link
70
70
  end
71
71
  def organisation(model)
72
72
  link = HtmlGrid::Link.new(:organisation, model, @session, self)
73
73
  link.value = model.organisation
74
- link.href = @lookandfeel._event_url(:customer,
74
+ link.href = @lookandfeel._event_url(:customer,
75
75
  {:customer_id => model.customer_id})
76
76
  link
77
77
  end
78
- =begin
79
- def email(model)
80
- if(mail = model.email)
81
- link = HtmlGrid::Link.new(:email, model, @session, self)
82
- link.value = mail
83
- link.href = sprintf("mailto:%s", mail)
84
- link
85
- end
86
- end
87
- def email(model)
88
- EmailValue.new(model, @session, self)
89
- end
90
- def last_login(model)
91
- DateTimeView.new(:last_login, model, @session, self)
92
- end
93
- def active(model)
94
- model.value(:active)
95
- end
96
- =end
97
78
  def last_login(model)
98
79
  if model.respond_to?(:last_login)
99
80
  model.last_login
100
81
  else
101
- @session.user.last_login(model.email)
82
+ @session.auth_session.last_login(model.email)
102
83
  end
103
84
  end
104
85
  def valid(model)
105
86
  if model.respond_to?(:valid)
106
87
  @lookandfeel.lookup(model.valid)
88
+ elsif @session.auth_session && defined?(@session.auth_session.entity_valid?)
89
+ @session.auth_session.entity_valid?(model.email)
107
90
  else
108
91
  @lookandfeel.lookup(@session.user.entity_valid?(model.email).to_s)
109
92
  end
93
+ rescue => error
94
+ puts error
110
95
  end
111
96
  private
112
97
  def sort_link(header_key, matrix, component)
@@ -16,7 +16,7 @@ class Head < HtmlGrid::DivComposite
16
16
  CSS_ID_MAP = {2 => 'welcome', 1 => 'logged-in-as'}
17
17
  def logged_in_as(model)
18
18
  if(@session.logged_in?)
19
- @lookandfeel.lookup(:logged_in_as, @session.user.name)
19
+ @lookandfeel.lookup(:logged_in_as, @session.auth_session.name)
20
20
  end
21
21
  end
22
22
  def logo(model)
@@ -6,6 +6,7 @@ module BBMB
6
6
  module View
7
7
  class NavigationLink < HtmlGrid::Link
8
8
  def init
9
+ puts "NavigationLink unless #{@session.event} == #{@name}"
9
10
  unless(@session.event == @name)
10
11
  self.href = @lookandfeel._event_url(@name)
11
12
  end
@@ -6,8 +6,9 @@ require 'bbmb/model/order'
6
6
 
7
7
  module BBMB
8
8
  module Model
9
- MUTEX ||= Mutex.new
10
9
  class Customer
10
+ MUTEX = Mutex.new
11
+
11
12
  attr_reader :customer_id, :email, :archive, :quotas
12
13
  attr_accessor :address1, :address2, :address3, :canton, :city,
13
14
  :drtitle, :ean13, :fax, :firstname, :language, :lastname,
@@ -22,6 +23,11 @@ class Customer
22
23
  @quotas = []
23
24
  end
24
25
  def add_quota(quota)
26
+ unless @quotas.is_a?(Array)
27
+ puts "customer #{customer_id}: Fixing quotas #{@quotas} -> []"
28
+ @quotas = []
29
+ odba_store;
30
+ end
25
31
  @quotas.push(quota).uniq!
26
32
  quota
27
33
  end
@@ -36,7 +42,7 @@ class Customer
36
42
  ].compact
37
43
  end
38
44
  def commit_order!(commit_time = Time.now)
39
- BBMB::Model::MUTEX.synchronize {
45
+ MUTEX.synchronize {
40
46
  id = @archive.keys.max.to_i.next
41
47
  order = current_order
42
48
  order.commit!(id, commit_time)
@@ -56,7 +62,6 @@ class Customer
56
62
  end
57
63
  end
58
64
  def quota(article_id)
59
-
60
65
  @quotas.compact.find { |quota| quota.article_number == article_id }
61
66
  end
62
67
  def email=(email)
@@ -69,11 +74,11 @@ class Customer
69
74
  @email = email
70
75
  end
71
76
  end
72
- def favorites
77
+ def favorites
73
78
  @favorites ||= Order.new(self)
74
79
  end
75
80
  def inject_order(order, commit_time = Time.now)
76
- BBMB::Model::MUTEX.synchronize {
81
+ MUTEX.synchronize {
77
82
  id = @archive.keys.max.to_i.next
78
83
  order.commit!(id, commit_time)
79
84
  @archive.store(id, order)
@@ -93,7 +98,15 @@ class Customer
93
98
  @protected.fetch(key, false)
94
99
  end
95
100
  def turnover
96
- orders.inject(0) { |memo, order| order.total + memo }
101
+ orders.inject(0) do
102
+ |memo, order|
103
+ begin
104
+ order.total + memo
105
+ rescue => error
106
+ SBSM.info "turnover error for #{order.order_id} returning memo"
107
+ memo
108
+ end
109
+ end
97
110
  end
98
111
  end
99
112
  end
@@ -87,7 +87,7 @@ class Order
87
87
  info
88
88
  end
89
89
  def calculate_effective_prices
90
- @positions.each { |pos|
90
+ @positions.each { |pos|
91
91
  pos.price_effective = price_effective(pos)
92
92
  }
93
93
  end
@@ -98,7 +98,7 @@ class Order
98
98
  def commit!(commit_id, commit_time)
99
99
  raise "can't commit empty order" if(empty?)
100
100
  calculate_effective_prices
101
- @positions.each { |pos|
101
+ @positions.each { |pos|
102
102
  pos.commit!
103
103
  }
104
104
  @unavailable.clear
@@ -157,8 +157,8 @@ class Order
157
157
  if(@priority)
158
158
  lines.push "238:%i" % @priority
159
159
  end
160
- lines.push "250:ADE",
161
- sprintf("251:%i%05i", @customer.customer_id, @commit_id),
160
+ lines.push "250:ADE",
161
+ sprintf("251:%i%05i", @customer.customer_id, @commit_id),
162
162
  "300:4", "301:%s" % @commit_time.strftime('%Y%m%d')
163
163
  lines.join("\n")
164
164
  end
@@ -205,6 +205,9 @@ class Order
205
205
  end
206
206
  def total
207
207
  @positions.inject(@shipping) { |memo, pos| pos.total + memo }
208
+ rescue
209
+ SBSM.info "total: rescuing by adding 0 to memo #{memo} as total for #{order_id}"
210
+ return memo
208
211
  end
209
212
  def total_incl_vat
210
213
  if rate = BBMB.config.vat_rate
@@ -222,7 +225,7 @@ class Order
222
225
  @customer.customer_id,
223
226
  @customer.ean13,
224
227
  @commit_time.strftime('%d%m%Y'),
225
- @commit_id,
228
+ @commit_id,
226
229
  position.pcode,
227
230
  position.ean13,
228
231
  position.article_number,
@@ -62,47 +62,11 @@ class ProductInfo < Subject
62
62
  instance_variable_get("@l#{level}_qty")
63
63
  end
64
64
  end
65
-
66
- def ==(other)
67
- other.is_a?(ProductInfo) && @article_number == other.article_number
68
- end
69
-
70
65
  def to_info
71
- self
72
- end
73
-
74
- def to_product
75
- convert_to(Product)
66
+ self
76
67
  end
77
-
78
- private
79
-
80
- # Converts as new instance
81
- #
82
- # @param [Class] klass New class {Product|ProductInfo}
83
- # @return [Array(Product,ProductInfo)] new instance
84
- def convert_to(klass)
85
- base_keys = %i{
86
- backorder_date catalogue1 catalogue2 catalogue3
87
- description ean13 expiry_date partner_index pcode status
88
- }
89
- keys = case klass.to_s
90
- when 'BBMB::Model::Product'
91
- base_keys
92
- when 'BBMB::Model::ProductInfo'
93
- base_keys += %i{
94
- vat price
95
- l1_qty l2_qty l3_qty l4_qty l5_qty l6_qty
96
- l1_price l2_price l3_price l4_price l5_price l6_price
97
- }
98
- else
99
- raise "Unknown class #{klass}"
100
- end
101
- obj = klass.new(@article_number)
102
- keys.each { |key| obj.send("#{key}=", self.send(key)) }
103
- obj.promotion = @promotion.dup if (@promotion && @promotion.current?)
104
- obj.sale = @sale.dup if (@sale && @sale.current?)
105
- obj
68
+ def ==(other)
69
+ other.is_a?(ProductInfo) && @article_number == other.article_number
106
70
  end
107
71
  end
108
72
  class Product < ProductInfo
@@ -117,13 +81,18 @@ class Product < ProductInfo
117
81
  def current_promo
118
82
  [@sale, @promotion].find { |promo| promo && promo.current? }
119
83
  end
120
-
121
- def to_product
122
- self
123
- end
124
-
125
84
  def to_info
126
- convert_to(ProductInfo)
85
+ info = ProductInfo.new(@article_number)
86
+ [ :backorder_date, :catalogue1, :catalogue2, :catalogue3,
87
+ :description, :ean13, :expiry_date, :partner_index, :pcode,
88
+ :status, :l1_qty, :l2_qty, :l3_qty, :l4_qty, :l5_qty, :l6_qty, :vat,
89
+ :price, :l1_price, :l2_price, :l3_price, :l4_price, :l5_price, :l6_price
90
+ ].each { |key|
91
+ info.send("#{key}=", self.send(key))
92
+ }
93
+ info.promotion = @promotion.dup if(@promotion && @promotion.current?)
94
+ info.sale = @sale.dup if(@sale && @sale.current?)
95
+ info
127
96
  end
128
97
  end
129
98
  end
@@ -24,12 +24,12 @@ module BBMB
24
24
  objs.each { |obj| obj.odba_delete }
25
25
  end
26
26
  def ODBA.migrate_to_subject
27
- all(Model::Product) { |product|
28
- product.migrate_to_subject && product.odba_store
27
+ all(Model::Product) { |product|
28
+ product.migrate_to_subject && product.odba_store
29
29
  }
30
30
  all(Model::Order) { |order|
31
- order.each { |position|
32
- position.migrate_to_subject && position.odba_store
31
+ order.each { |position|
32
+ position.migrate_to_subject && position.odba_store
33
33
  }
34
34
  }
35
35
  ::ODBA.cache.create_deferred_indices(true)
@@ -3,6 +3,7 @@
3
3
 
4
4
  require 'ydim/config'
5
5
  require 'ydim/client'
6
+ require 'bbmb/util/mail'
6
7
  require 'openssl'
7
8
 
8
9
  module BBMB
@@ -101,8 +101,7 @@ module Mail
101
101
  parts = []
102
102
  config.mail_confirm_lines.collect do |line|
103
103
  content = order.collect do |pos|
104
- sprintf(line, pos.quantity.to_i,
105
- pos.description, pos.price_qty.to_f, pos.total.to_f)
104
+ sprintf line, pos.quantity, pos.description, pos.price_qty, pos.total
106
105
  end
107
106
  parts.push date, content.join("\n"), order.total
108
107
  if vtotal = order.total_incl_vat
@@ -16,12 +16,15 @@ class FileMission
16
16
  attr_accessor :backup_dir, :delete, :directory, :glob_pattern
17
17
  def file_paths
18
18
  path = File.expand_path(@glob_pattern || '*', @directory)
19
- Dir.glob(path).collect { |entry|
19
+ res = Dir.glob(path).collect { |entry|
20
20
  File.expand_path(entry, @directory)
21
21
  }.compact
22
+ puts res
23
+ res
22
24
  end
23
25
  def poll(&block)
24
- @directory = File.expand_path(@directory, BBMB.config.bbmb_dir)
26
+ @directory = File.expand_path(@directory, BBMB.config.bbmb_dir) unless File.directory?(@directory) &&
27
+ File.absolute_path(@directory) == @directory
25
28
  file_paths.each { |path|
26
29
  poll_path(path, &block)
27
30
  }
@@ -34,7 +37,11 @@ class FileMission
34
37
  BBMB::Util::Mail.notify_error(err)
35
38
  ensure
36
39
  if(@backup_dir)
37
- dir = File.expand_path(@backup_dir, BBMB.config.bbmb_dir)
40
+ if File.absolute_path(@backup_dir) == @backup_dir
41
+ dir = @backup_dir
42
+ else
43
+ dir = File.expand_path(@backup_dir, BBMB.config.bbmb_dir)
44
+ end
38
45
  FileUtils.mkdir_p(dir)
39
46
  FileUtils.cp(path, dir)
40
47
  end
@@ -43,12 +50,10 @@ class FileMission
43
50
  end
44
51
  end
45
52
  end
46
- class PopMission
53
+ class PopMission
47
54
  attr_accessor :host, :port, :user, :pass, :content_type
48
55
  def poll(&block)
49
56
  # puts "PopMission starts polling host #{@host}:#{@port} u: #{@user} pw: #{@pass}"
50
- @backup_dir ||= Dir.tmpdir
51
-
52
57
  options = {
53
58
  :address => @host,
54
59
  :port => @port,
@@ -6,20 +6,116 @@ require 'bbmb/html/util/known_user'
6
6
  require 'bbmb/html/util/session'
7
7
  require 'bbmb/html/util/validator'
8
8
  require 'bbmb/util/invoicer'
9
+ require 'bbmb/util/invoicer'
9
10
  require 'bbmb/util/mail'
10
11
  require 'bbmb/util/updater'
11
12
  require 'bbmb/model/order' # needed to be enable to invoice later
12
13
  require 'bbmb/model/customer'
13
14
  require 'date'
14
- require 'sbsm/drbserver'
15
+ require 'sbsm/app'
16
+ require 'bbmb/persistence/odba'
17
+ require 'bbmb/model/customer'
18
+ require 'bbmb/model/quota'
19
+ require 'bbmb/model/product'
20
+ require 'bbmb/model/promotion'
15
21
 
16
22
  module BBMB
23
+ def self.persistence
24
+ @@persistence ||= BBMB::Persistence::ODBA
25
+ end
17
26
  module Util
18
- class Server < SBSM::DRbServer
27
+ class Server
28
+ def initialize(persistence, app)
29
+ puts "Self #{self.class} initialize"
30
+ @persistence = persistence
31
+ @app = app
32
+ end
33
+ def invoice(range)
34
+ Invoicer.run(range)
35
+ rescue Exception => e
36
+ Mail.notify_error(e)
37
+ end
38
+ def update
39
+ Updater.run
40
+ rescue Exception => e
41
+ Mail.notify_error(e)
42
+ end
43
+ def inject_order(customer_id, products, infos, opts={})
44
+ @app.inject_order(customer_id, products, infos, opts)
45
+ end
46
+ def rename_user(old_name, new_name)
47
+ @app.rename_user(old_name, new_name)
48
+ end
49
+ def run_invoicer
50
+ SBSM.debug("run_invoicer starting")
51
+ @invoicer ||= Thread.new {
52
+ Thread.current.abort_on_exception = true
53
+ loop {
54
+ today = Date.today
55
+ day = today >> 1
56
+ start = Time.local(today.year, today.month)
57
+ now = Time.now
58
+ at = Time.local(day.year, day.month)
59
+ secs = at - now
60
+ SBSM.debug("invoicer") {
61
+ "sleeping %.2f seconds" % secs
62
+ }
63
+ sleep(secs)
64
+ SBSM.debug("invoice starting")
65
+ invoice(start...at)
66
+ SBSM.debug("invoice finished")
67
+ }
68
+ }
69
+ end
70
+ def run_updater
71
+ run_only_once_at_startup = false
72
+ SBSM.debug("updater") { "run_updater run_only_once_at_startup? #{run_only_once_at_startup} " }
73
+ @updater ||= Thread.new {
74
+ loop {
75
+ day = Date.today
76
+ now = Time.now
77
+ if(now.hour >= BBMB.config.update_hour)
78
+ day += 1
79
+ end
80
+ at = Time.local(day.year, day.month, day.day, BBMB.config.update_hour)
81
+ secs = at - now
82
+ SBSM.debug("updater") { "sleeping %.2f seconds. run_only_once_at_startup #{run_only_once_at_startup}" % secs }
83
+ if run_only_once_at_startup then puts "Skipped sleeping #{secs}" else sleep(secs) end
84
+
85
+ SBSM.debug("update starting")
86
+ update
87
+ SBSM.debug("update finished")
88
+ Thread.abort if run_only_once_at_startup
89
+ }
90
+ }
91
+ end
92
+ end
93
+ class RackInterface < SBSM::RackInterface
19
94
  ENABLE_ADMIN = true
20
- SESSION = Html::Util::Session
21
- VALIDATOR = Html::Util::Validator
22
- attr_reader :updater
95
+ SESSION = Html::Util::Session
96
+ VALIDATOR = Html::Util::Validator
97
+ attr_reader :updater, :auth
98
+ def initialize(app: BBMB::Util::App.new,
99
+ auth: nil,
100
+ validator: BBMB::Html::Util::Validator)
101
+ [ File.join(Dir.pwd, 'etc', 'config.yml'),
102
+ ].each do |config_file|
103
+ if File.exist?(config_file)
104
+ puts "BBMB.config.load from #{config_file}"
105
+ BBMB.config.load (config_file)
106
+ break
107
+ end
108
+ end
109
+ @auth = DRb::DRbObject.new(nil, BBMB.config.auth_url)
110
+ puts "@auth is #{@auth} from #{self.class}"
111
+ @app = app
112
+ super(app: app,
113
+ session_class: BBMB::Html::Util::Session,
114
+ unknown_user: Html::Util::KnownUser,
115
+ validator: validator,
116
+ cookie_name: 'virbac.bbmb'
117
+ )
118
+ end
23
119
  def inject_order(customer_id, products, infos, opts={})
24
120
  customer = Model::Customer.find_by_customer_id(customer_id) \
25
121
  || Model::Customer.find_by_ean13(customer_id)
@@ -39,8 +135,8 @@ module BBMB
39
135
  order = Model::Order.new(customer)
40
136
  products.each { |info|
41
137
  if(product = Model::Product.find_by_pcode(info[:pcode]) \
42
- || Model::Product.find_by_ean13(info[:ean13]) \
43
- || Model::Product.find_by_article_number(info[:article_number]))
138
+ || Model::Product.find_by_ean13(info[:ean13]) \
139
+ || Model::Product.find_by_article_number(info[:article_number]))
44
140
  order.add(info[:quantity], product)
45
141
  [:article_number, :backorder].each do |key|
46
142
  info.store key, product.send(key)
@@ -65,19 +161,14 @@ module BBMB
65
161
  end
66
162
  { :order_id => order.order_id, :products => products }
67
163
  end
68
- def invoice(range)
69
- Invoicer.run(range)
70
- rescue Exception => e
71
- Mail.notify_error(e)
72
- end
73
164
  def login(email, pass)
74
- session = BBMB.auth.login(email, pass, BBMB.config.auth_domain)
75
- Html::Util::KnownUser.new(session)
76
- end
77
- def logout(session)
78
- BBMB.auth.logout(session)
79
- rescue DRb::DRbError, RangeError, NameError
80
- end
165
+ session = BBMB.auth.login(email, pass, BBMB.config.auth_domain)
166
+ Html::Util::KnownUser.new(session)
167
+ end
168
+ def logout(session)
169
+ BBMB.auth.logout(session)
170
+ rescue DRb::DRbError, RangeError, NameError
171
+ end
81
172
  def rename_user(old_name, new_name)
82
173
  return if old_name.eql?(new_name)
83
174
  BBMB.auth.autosession(BBMB.config.auth_domain) do |session|
@@ -88,49 +179,6 @@ module BBMB
88
179
  end
89
180
  end
90
181
  end
91
- def run_invoicer
92
- BBMB.logger.debug("run_invoicer starting")
93
- @invoicer ||= Thread.new {
94
- Thread.current.abort_on_exception = true
95
- loop {
96
- today = Date.today
97
- day = today >> 1
98
- start = Time.local(today.year, today.month)
99
- now = Time.now
100
- at = Time.local(day.year, day.month)
101
- secs = at - now
102
- BBMB.logger.debug("invoicer") {
103
- "sleeping %.2f seconds" % secs
104
- }
105
- sleep(secs)
106
- BBMB.logger.debug("invoice starting")
107
- invoice(start...at)
108
- BBMB.logger.debug("invoice finished")
109
- }
110
- }
111
- end
112
- def run_updater
113
- run_only_once_at_startup = false
114
- BBMB.logger.debug("updater") { "run_updater run_only_once_at_startup? #{run_only_once_at_startup} " }
115
- @updater ||= Thread.new {
116
- loop {
117
- day = Date.today
118
- now = Time.now
119
- if(now.hour >= BBMB.config.update_hour)
120
- day += 1
121
- end
122
- at = Time.local(day.year, day.month, day.day, BBMB.config.update_hour)
123
- secs = at - now
124
- BBMB.logger.debug("updater") { "sleeping %.2f seconds. run_only_once_at_startup #{run_only_once_at_startup}" % secs }
125
- if run_only_once_at_startup then puts "Skipped sleeping #{secs}" else sleep(secs) end
126
-
127
- BBMB.logger.debug("update starting")
128
- update
129
- BBMB.logger.debug("update finished")
130
- Thread.abort if run_only_once_at_startup
131
- }
132
- }
133
- end
134
182
  def send_order order, customer
135
183
  begin
136
184
  Timeout.timeout(300) {
@@ -157,11 +205,17 @@ module BBMB
157
205
  BBMB::Util::Mail.notify_error(err)
158
206
  end
159
207
  end
160
- def update
161
- Updater.run
162
- rescue Exception => e
163
- Mail.notify_error(e)
208
+ end
209
+ class App < SBSM::App
210
+ def login(email, pass)
211
+ session = BBMB.auth.login(email, pass, BBMB.config.auth_domain)
212
+ Html::Util::KnownUser.new(session)
213
+ end
214
+ def logout(session)
215
+ # Here we start when logging in from the home page
216
+ BBMB.auth.logout(session)
217
+ rescue DRb::DRbError, RangeError, NameError
164
218
  end
165
219
  end
166
- end
167
- end
220
+ end
221
+ end