diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 69d0908cb2..4dc0a1ed24 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,5 +1,5 @@ class AdminController < ApplicationController - http_basic_authenticate_with name: "jungle", password: "boogie" + http_basic_authenticate_with name: ENV['ADMIN_NAME'], password: ENV['ADMIN_PASSWORD'] end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..6c366e0512 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,21 @@ +class SessionsController < ApplicationController + + def new + end + + def create + if user = User.authenticate_with_credentials(params[:email], params[:password]) + session[:user_id] = user.id + redirect_to '/' + else + flash[:notice] = "Incorrect email or password." + redirect_to '/login' + end + end + + def destroy + session[:user_id] = nil + redirect_to '/' + end + +end diff --git a/app/helpers/appication_controller.rb b/app/helpers/appication_controller.rb new file mode 100644 index 0000000000..a709059257 --- /dev/null +++ b/app/helpers/appication_controller.rb @@ -0,0 +1,2 @@ +module ApplicationController +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb deleted file mode 100644 index de6be7945c..0000000000 --- a/app/helpers/application_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ApplicationHelper -end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000000..d25d8892dd --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "from@example.com" + layout 'mailer' +end diff --git a/app/mailers/order_mailers.rb b/app/mailers/order_mailers.rb new file mode 100644 index 0000000000..d1d4ca1dfa --- /dev/null +++ b/app/mailers/order_mailers.rb @@ -0,0 +1,9 @@ +class OrderMailer < ApplicationMailer + default from: 'no-reply@jungle.com' + + def receipt_email(order) + @order = order + @products = Product.joins(:line_items).where('line_items.order_id' => order.id).select('products.name, line_items.quantity, line_items.item_price_cents, line_items.total_price_cents') + mail(to: @order.email, subject: "Jungle Receipt for order ##{@order.id}") + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 93c658e2d5..378b0ae2ab 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,7 @@ class User < ActiveRecord::Base validates :first_name, presence: true validates :last_name, presence: true - validates :email, presence: true + validates :email, presence: true, uniqueness: true; validates :password_digest, presence: true has_secure_password diff --git a/app/views/order_mailer/receipt_email.html.erb b/app/views/order_mailer/receipt_email.html.erb new file mode 100644 index 0000000000..512f99f6ee --- /dev/null +++ b/app/views/order_mailer/receipt_email.html.erb @@ -0,0 +1,14 @@ + + + + + + +

Thank you for your order

+

You ordered:

+ <% @products.each do |product| %> +

<%=product.quantity%> <%=product.name%> for $<%=product.item_price_cents/100.00%>

+ <% end %> +

Total: $<%= (@order.total_cents/100.00).round(2) %>

+ + diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 101d9eff59..c58962c1a4 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -29,6 +29,7 @@ <%= @cart_total %> +
To @order.email
diff --git a/db/seeds.rb b/db/seeds.rb index dd43d36f19..9461aa1fd5 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -130,7 +130,6 @@ def open_asset(file_name) }) User.create!({ - id: 1, first_name: "Guy", last_name: "Booth", email: "guy@guy", @@ -138,7 +137,6 @@ def open_asset(file_name) }) User.create!({ - id: 2, first_name: "Benno", last_name: "Booth", email: "ben@ben", diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 0000000000..aad9e36caf --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,22 @@ +0 info it worked if it ends with ok +1 verbose cli [ '/home/vagrant/.nvm/versions/node/v6.7.0/bin/node', +1 verbose cli '/home/vagrant/.nvm/versions/node/v6.7.0/bin/npm', +1 verbose cli 'start' ] +2 info using npm@3.10.3 +3 info using node@v6.7.0 +4 verbose stack Error: ENOENT: no such file or directory, open '/vagrant/package.json' +4 verbose stack at Error (native) +5 verbose cwd /vagrant/jungle +6 error Linux 4.4.0-21-generic +7 error argv "/home/vagrant/.nvm/versions/node/v6.7.0/bin/node" "/home/vagrant/.nvm/versions/node/v6.7.0/bin/npm" "start" +8 error node v6.7.0 +9 error npm v3.10.3 +10 error path /vagrant/package.json +11 error code ENOENT +12 error errno -2 +13 error syscall open +14 error enoent ENOENT: no such file or directory, open '/vagrant/package.json' +15 error enoent ENOENT: no such file or directory, open '/vagrant/package.json' +15 error enoent This is most likely not a problem with npm itself +15 error enoent and is related to npm not being able to find a file. +16 verbose exit [ -2, true ]