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 @@ + + +
+ + + +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 %> +