Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

WIP: Adding login to donation/new

  • Loading branch information...
commit 4e5fb5fba86f6811483bd9f2852aaf2ab4eca96f 1 parent abf04c0
Tim Pope and Veez (Matt Remsik) authored veezus committed
View
27 app/controllers/myspot/donations_controller.rb
@@ -2,12 +2,16 @@ class Myspot::DonationsController < ApplicationController
before_filter :login_required, :except => :create
resources_controller_for :donations, :only => [:index, :create, :destroy]
- response_for :create do |format|
- if resource_saved?
+ def create
+ unless params[:email].blank?
+ self.current_user = User.authenticate(params[:email], params[:password])
+ end
+ self.resource = new_resource
+ if resource.save
update_balance_cookie
- format.html { redirect_to edit_myspot_donations_amounts_path }
+ redirect_to edit_myspot_donations_amounts_path
else
- format.html { render :text => "TODO" }
+ render "new"
end
end
@@ -18,19 +22,10 @@ class Myspot::DonationsController < ApplicationController
protected
- def can_create?
- if current_user.nil?
- session[:return_to] = edit_myspot_donations_amounts_path
- session[:news_item_id] = params[:pitch_id]
- session[:donation_amount] = params[:amount]
- render :partial => "sessions/header_form" and return false
- end
-
- access_denied unless Donation.createable_by?(current_user)
- end
-
def new_resource
- current_user.donations.new(params[:donation])
+ Donation.new(params[:donation]) do |d|
+ d.user = current_user
+ end
end
def find_resources
View
1  app/models/pitch.rb
@@ -270,6 +270,7 @@ def default_donation_amount
end
def user_can_donate_more?(user, attempted_donation_amount)
+ return true unless user
return false if attempted_donation_amount.nil?
return true if user.organization? && attempted_donation_amount <= requested_amount
return false if attempted_donation_amount > funding_needed
View
2  app/views/donations/_donate_default_form.html.haml
@@ -1,4 +1,4 @@
-- form_for Donation.new(:pitch => news_item, :amount => Donation::DEFAULT_AMOUNT), :url => myspot_donations_path, :html => {:id => "new_donation_#{news_item.id}", :class => "auth"} do |f|
+- form_for Donation.new(:pitch => news_item, :amount => Donation::DEFAULT_AMOUNT), :url => myspot_donations_path, :html => {:id => "new_donation_#{news_item.id}"} do |f|
= f.hidden_field :amount, :id => "donation_default_amount"
= f.hidden_field :pitch_id
= image_submit_tag "donate_default.png", :alt => "Donate #{Donation::DEFAULT_AMOUNT}", :title => "Donate #{Donation::DEFAULT_AMOUNT}"
View
2  app/views/donations/_donate_variable_amount_form.html.haml
@@ -1,4 +1,4 @@
-- form_for Donation.new(:pitch => news_item), :url => myspot_donations_path, :html => {:id => "custom_donation_#{news_item.id}", :class => "auth"} do |f|
+- form_for Donation.new(:pitch => news_item), :url => myspot_donations_path, :html => {:id => "custom_donation_#{news_item.id}"} do |f|
.float_left
= f.label :amount, "Donate other amount", :class => "hide"
- if current_user && current_user.has_donated_to?(news_item)
View
60 app/views/myspot/donations/new.html.haml
@@ -0,0 +1,60 @@
+- if @donations && @donations.any?(&:errors)
+ - content_for :error do
+ = error_messages_for :donations, :object => @donation
+
+#equalize
+
+ - # first column content
+ .span-715.box_white
+
+ %h2{:style => "color: #800000; text-align: center;"} Almost done! One more step:
+ .block-spacer-negative
+ - if logged_in? && current_user.total_credits > 0
+ .float-right
+ == You have #{number_to_currency(current_user.total_credits)} in credits
+ %h3 Login or Register
+ .double_content_border
+
+ - form_for @donation, :url => myspot_donations_path do |f|
+ - unless logged_in?
+ .donate-login
+ .row
+ %label Your E-mail Address
+ %div{:class => session_field_class_name }
+ = text_field_tag "email", nil, :class=>"text"
+ .row
+ %label Your Password
+ %div{:class => session_field_class_name }
+ = password_field_tag "password", nil, :class=>"text"
+ .block-padding
+ %h3 Fund Your Donations
+ .double_content_border
+ %ul.unpaid_donations
+ - content_tag_for :li, @donation, :class => 'unpaid' do
+ .column.span-70
+ = link_to image_tag(@donation.pitch.featured_image.url(:thumb)), @donation.pitch
+ .column.span-550
+ %h3
+ PITCH:
+ = link_to @donation.pitch.headline, @donation.pitch
+ - if Group.all.any?
+ %p
+ Donate on behalf of:
+ = select_tag "donation_amounts[#{@donation.id}][group_id]", '<option value=''>Giving for a group?</option>' + options_from_collection_for_select(Group.all, :id, :name), :include_blank => true
+ %p
+ = truncate_words(@donation.pitch.short_description)
+ = link_to 'Read More &raquo;', @donation.pitch
+ .column.span-95
+ $
+ = f.text_field :amount, :size => 4
+ %hr
+ .float-right
+ = image_submit_tag 'purchase.png', :alt => 'Purchase'
+
+ - # second column content
+ .span-160.box_white
+ = render :partial => 'layouts/common_questions'
+
+.clear
+.block-spacer
+
View
8 public/stylesheets/screen_spotus.css
@@ -266,6 +266,14 @@ body {
.login-boxer h3 div.float-left, .login-boxer h3 div.float-right {
padding-top: 10px;
}
+.donate-login .row label {
+ float: left;
+ width: 150px;
+ margin-top: 9px;
+}
+.donate-login .row input {
+ width: 200px;
+}
.register input.text, .or_login input.text {
width: 190px!important;
}
Please sign in to comment.
Something went wrong with that request. Please try again.