diff --git a/front-api/Gemfile b/front-api/Gemfile index 4ee82af..88c65f1 100644 --- a/front-api/Gemfile +++ b/front-api/Gemfile @@ -22,3 +22,4 @@ gem 'puma' gem "sinatra-contrib" gem 'rerun' gem 'xxhash', '~> 0.3.0' +gem 'pony' diff --git a/front-api/Gemfile.lock b/front-api/Gemfile.lock index 423703c..0568336 100644 --- a/front-api/Gemfile.lock +++ b/front-api/Gemfile.lock @@ -49,10 +49,15 @@ GEM celluloid (>= 0.15.2) rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) + mail (2.6.3) + mime-types (>= 1.16, < 3) + mime-types (2.6.1) minitest (5.5.0) multi_json (1.10.1) multipart-post (2.0.0) pg (0.17.1) + pony (1.11) + mail (>= 2.0) puma (2.10.2) rack (>= 1.1, < 2.0) puma (2.10.2-java) @@ -102,6 +107,7 @@ DEPENDENCIES jruby-openssl json pg + pony puma rerun sinatra diff --git a/front-api/app.rb b/front-api/app.rb index 5a6bb2a..aca9388 100644 --- a/front-api/app.rb +++ b/front-api/app.rb @@ -5,6 +5,7 @@ require 'json' require 'sinatra/cookies' require 'elasticsearch' require 'xxhash' +require 'pony' Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file } @@ -18,7 +19,7 @@ before do # domain is allowed headers 'Access-Control-Allow-Origin' => 'http://localhost:3001', - 'Access-Control-Allow-Methods' => ['OPTIONS', 'GET', 'POST','PUT'], + 'Access-Control-Allow-Methods' => ['OPTIONS', 'GET', 'POST','PUT'].join(','), 'Access-Control-Allow-Headers' => 'Origin, X-Requested-With, Content-Type, Accept', 'Access-Control-Expose-Headers' => 'X-Total-Count', 'Access-Control-Allow-Credentials' => 'true' diff --git a/front-api/controllers/cart.rb b/front-api/controllers/cart.rb index fccd89d..5a8e9c1 100644 --- a/front-api/controllers/cart.rb +++ b/front-api/controllers/cart.rb @@ -54,6 +54,26 @@ put '/cart/delivery_destination', &update_delivery_destination post '/cart/delivery_destination', &update_delivery_destination +def send_order_email(cart) + Pony.options = { + :subject => "Nova Narudžba: #{cart.id}", + :html_body => "Mušterija naručila nešto.
Pogledati https://www.ribica.ba/backoffice/carts/#{cart.id}", + :body => "Mušterija naručila nešto. Pogledati https://www.ribica.ba/backoffice/carts/#{cart.id}", + :via => :smtp, + :via_options => { + :address => 'smtp.gmail.com', + :port => '587', + :enable_starttls_auto => true, + :user_name => 'ribica.ba@gmail.com', + :password => 'pumparica*pumpa*sumpa*lumpa', + :authentication => :plain, # :plain, :login, :cram_md5, no auth by default + :domain => "localhost.localdomain" + } +} +Pony.mail(:to => "narudzbe@ribica.ba") +end + + post '/cart/confirmation' do anonymous = anonymous_id cart = Cart.just_find(anonymous, logged_in_user_id) @@ -64,5 +84,6 @@ post '/cart/confirmation' do # since there is no more ordered cart this needs to be done # in order for next call of Cart#just_find to be ready Cart.find_or_create(anonymous, logged_in_user_id) + send_order_email(cart) "OK".to_json end