IPN improvements

This commit is contained in:
Will Bradley 2013-08-28 03:18:47 -07:00
parent 0be2834a5d
commit c662be6dc0
10 changed files with 48 additions and 15 deletions

View File

@ -20,6 +20,7 @@ font-size: 13px;
line-height: 18px; line-height: 18px;
color: #333; color: #333;
text-align: center; text-align: center;
text-decoration: none;
text-shadow: 0 1px 1px rgba(255,255,255,.75); text-shadow: 0 1px 1px rgba(255,255,255,.75);
vertical-align: middle; vertical-align: middle;
background-color: #f5f5f5; background-color: #f5f5f5;

View File

@ -24,6 +24,16 @@ class IpnsController < ApplicationController
#end #end
end end
def import
@ipn = Ipn.new_from_dynamic_params(params)
@ipn.data = params.to_json
@ipn.save
redirect_to ipn_path(@ipn)
#unless @ipn.validate!
# Rails.logger.error "Unable to validate IPN: #{@ipn.inspect}"
#end
end
def validate def validate
if @ipn.validate! if @ipn.validate!
redirect_to ipns_url, :notice => 'Valid!' redirect_to ipns_url, :notice => 'Valid!'

View File

@ -1,5 +1,15 @@
class MacsController < ApplicationController class MacsController < ApplicationController
load_and_authorize_resource :mac, :except => [:index, :scan, :import] rescue_from CanCan::AccessDenied do |exception|
today = Date.today
event = Date.new(2013,9,1)
if today == event
redirect_to main_app.root_url, :alert => "CryptoParty today; no MAC scanning. Sorry, NSA!"
else
redirect_to main_app.root_url, :alert => "Nothing to see here!"
end
end
load_and_authorize_resource :mac
load_and_authorize_resource :user, :through => :mac, :except => [:index, :show, :scan, :import] load_and_authorize_resource :user, :through => :mac, :except => [:index, :show, :scan, :import]
#require "active_record" #require "active_record"

View File

@ -69,7 +69,7 @@ class UsersController < ApplicationController
def create def create
respond_to do |format| respond_to do |format|
if @user.save if @user.save
format.html { redirect_to users_url, :notice => 'User was successfully created.' } format.html { redirect_to @user, :notice => 'User was successfully created.' }
format.json { render :json => @user, :status => :created, :location => @user } format.json { render :json => @user, :status => :created, :location => @user }
else else
format.html { render :action => "new" } format.html { render :action => "new" }
@ -83,7 +83,7 @@ class UsersController < ApplicationController
def update def update
respond_to do |format| respond_to do |format|
if @user.update_attributes(params[:user]) if @user.update_attributes(params[:user])
format.html { redirect_to users_url, :notice => 'User was successfully updated.' } format.html { redirect_to @user, :notice => 'User was successfully updated.' }
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render :action => "edit" } format.html { render :action => "edit" }

View File

@ -3,14 +3,20 @@ class Ability
def initialize(user) def initialize(user)
# Anonymous can read mac # Anonymous can read mac
today = Date.today
event = Date.new(2013,9,1)
unless today == event
can :read, Mac can :read, Mac
can :scan, Mac # Need anonymous so CRON can scan
end
if !user.nil? if !user.nil?
# By default, users can only see their own stuff # By default, users can only see their own stuff
can :read, Card, :user_id => user.id can :read, Card, :user_id => user.id
can :read, Certification can :read, Certification
can :read_details, Mac can :read_details, Mac unless today == event
can [:update], Mac, :user_id => nil can [:update], Mac, :user_id => nil
can [:create,:update], Mac, :user_id => user.id can [:create,:update], Mac, :user_id => user.id
can :read, User, :id => user.id #TODO: why can users update themselves? can :read, User, :id => user.id #TODO: why can users update themselves?

View File

@ -86,7 +86,7 @@ class User < ActiveRecord::Base
end end
def self.member_levels def self.member_levels
{25 => "Associate", 50 => "Basic", 100 => "Plus"} {25 => "Associate", 50 => "Basic", 75 => "Basic", 100 => "Plus"}
end end
def member_status def member_status
@ -144,7 +144,7 @@ class User < ActiveRecord::Base
# There are payments # There are payments
if self.payments.count > 0 then if self.payments.count > 0 then
# They're on time # They're on time
if self.payments.last.date > (DateTime.now - 45.days) if self.payments.last.date > (DateTime.now - 60.days)
flair = "-paid" flair = "-paid"
else else
message = "Last Payment #{(DateTime.now - self.payments.last.date).to_i/30} months ago" message = "Last Payment #{(DateTime.now - self.payments.last.date).to_i/30} months ago"

View File

@ -8,10 +8,11 @@
<% end %> <% end %>
<p> <p>
<% if @ipn.payment.present? %> <% if @ipn.payment.present? %>
<%= link_to "Payment", @ipn.payment %> <%= link_to "Linked Payment", @ipn.payment %>
<% else %> <% else %>
Couldn't link '<%= @ipn.payer_email %>' or payment amount '<%= @ipn.payment_gross.to_i %>' not a valid membership level. Please create payment manually. <span class="alert">Couldn't link automatically. Please create payment manually or adjust the user account and try again to <%= link_to "link email '#{@ipn.payer_email}' at membership level '#{@ipn.payment_gross.to_i}'", link_ipn_path(@ipn) %>.</span>
<% end %> <% end %>
</p> </p>
<%= link_to "Back", ipns_path %> <%= link_to "Back", ipns_path %>

View File

@ -1,5 +1,7 @@
Scanning... Scanning...
<% @log.each do |log| %> <% if can? :read_details, Mac
@log.each do |log| %>
<%= log.mac %> = <%= log.mac %> =
<%= log.ip %><br/> <%= log.ip %><br/>
<% end %> <% end
end %>

View File

@ -74,17 +74,19 @@
</p> </p>
<% end %> <% end %>
<p> <p>
<b>Card:</b><%= link_to "+ Add", (new_card_path+"?user="+@user.id.to_s), :class => 'btn' if can? :create, Card %> <b>Card: </b><%= link_to "+ Add", (new_card_path+"?user="+@user.id.to_s), :class => 'btn' if can? :create, Card %>
<% if current_user.admin? then %> <% if current_user.admin? then %>
<ul>
<% @user.cards.each do |c| %> <% @user.cards.each do |c| %>
<%= link_to c.card_number, c %><%= "," unless c == @user.cards.last %> <li><%= link_to c.card_number, c %><%= "," unless c == @user.cards.last %></li>
<% end %> <% end %>
</ul>
<% else %> <% else %>
<%= unless @user.cards.blank? then raw("&#x2713;") end %> <%= unless @user.cards.blank? then raw("&#x2713;") end %>
<% end %> <% end %>
</p> </p>
<b>Certifications:</b><%= link_to "+ Add", (new_user_certification_path+"?user="+@user.id.to_s), :class => 'btn' if can? :create, UserCertification %> <b>Certifications: </b><%= link_to "+ Add", (new_user_certification_path+"?user="+@user.id.to_s), :class => 'btn' if can? :create, UserCertification %>
<ul> <ul>
<% @user.certifications.each do |certification| %> <% @user.certifications.each do |certification| %>
<li><%= link_to certification.name, certification %></li> <li><%= link_to certification.name, certification %></li>

View File

@ -1,4 +1,5 @@
Dooraccess::Application.routes.draw do Dooraccess::Application.routes.draw do
match 'ipns/import' => 'ipns#import', :as => :import_ipn
resources :ipns resources :ipns
match 'ipns/:id/link' => 'ipns#link', :as => :link_ipn match 'ipns/:id/link' => 'ipns#link', :as => :link_ipn
match 'ipns/:id/validate' => 'ipns#validate', :as => :validate_ipn match 'ipns/:id/validate' => 'ipns#validate', :as => :validate_ipn