Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,373 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class ContactsController < PublicController | ||
|
||
public | ||
def new | ||
@contact = Contact.new | ||
@contact.listing = Listing.first!(:id => params[:listing_id], :board => @board) | ||
render :template => "public/contact" | ||
end | ||
|
||
def create | ||
@contact = Contact.new(params[:contact]) | ||
@contact.listing = Listing.first!(:id => params[:listing_id], :board => @board) | ||
if @contact.valid? | ||
# first create the message | ||
email = Mailer.create_contact(@contact) | ||
|
||
# sent the message | ||
Mailer.deliver_contact(@contact) | ||
|
||
# finally display the message in the page | ||
# after clearing all the visual noise | ||
@message = email.encoded.gsub(/To: .*\n/, '').gsub(/Date: .*\n/, '').gsub(/From: .*\n/, '').gsub(/Subject: .*\n/, '').gsub(/Mime-Version: .*\n/, '').gsub(/Content-Type: .*\n/, '').sub(/\n/, '') | ||
render :template => "public/sent" | ||
else | ||
render :template => "public/contact" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class PublicBoardsController < PublicController | ||
|
||
# GET /:lang/:venue/:boards | ||
def show | ||
render :template => "public/board" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
class PublicController < ActionController::Base | ||
|
||
layout "public" | ||
|
||
before_filter :public_filter | ||
|
||
skip_before_filter :authenticate, :guard, :check_session_expiry | ||
|
||
def session_timeout | ||
raise "ADsasd" | ||
end | ||
# p before_filters | ||
|
||
def public_filter | ||
@lang, @venue, @board = Venue.retrieve(params[:lang] || language_from_browser, params[:venue], params[:board] || params[:id] || params[:board_id]) | ||
if(@venue) | ||
p (params[:board_id].nil? && params[:id].nil?) | ||
p (params[:board] != @board.name && params[:id] != @board.id.to_s && params[:board_id] != @board.id.to_s) | ||
if(params[:lang].nil? || params[:venue].nil? || (params[:id].nil? && params[:board_id].nil?) || params[:lang] != @lang.code || (params[:board] != @board.name && params[:id] != @board.id.to_s && params[:board_id] != @board.id.to_s)) | ||
puts "-" * 80 | ||
p @lang | ||
p @venue | ||
p @board | ||
redirect_to url_for(:controller => :public_boards, | ||
:action => :show, | ||
:venue => @venue.name, | ||
:id => @board.id, | ||
:lang => @lang.code) | ||
false | ||
elsif(@board.nil? || @lang.nil?) | ||
render_not_found | ||
else | ||
# TODO session tracking for venues with password | ||
@path_prefix = url_for(:controller => :public_boards, | ||
:action => :show, | ||
:venue => @venue.name, | ||
:board => @board.name, | ||
:lang => @lang.code) | ||
true | ||
end | ||
else | ||
# check for php pages | ||
php = File.join(RAILS_ROOT, 'public', params[:venue], "index.php") | ||
if (File.exists?(php)) | ||
redirect_to "/#{params[:venue]}/index.php" | ||
false | ||
else | ||
render_not_found | ||
end | ||
end | ||
end | ||
|
||
def language_from_browser | ||
#get prefered browser language | ||
#TODO needs find the language from the browser which fits into | ||
#the venue's languages | ||
accept = request.env["HTTP_ACCEPT_LANGUAGE"] | ||
if accept | ||
lang = accept.split(",")[0] | ||
lang = lang[0..1] | ||
end | ||
|
||
# if no language could be found, fall back to default | ||
unless lang | ||
lang = 'en' #TODO @venue.default_language | ||
end | ||
lang | ||
end | ||
|
||
def render_not_found | ||
render :template => "public/novenue", :layout => "error", :status => 404 | ||
false | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
class PublicListingsController < PublicController | ||
|
||
def index | ||
raise Exception.new("forced error to test error page") | ||
end | ||
|
||
# GET /listings/new/offer | ||
def offer | ||
@listing = Listing.new | ||
@listing.driver = true | ||
@listing.board = @board | ||
|
||
render :template => "public/new" | ||
end | ||
|
||
# GET /listings/new/wanted | ||
def wanted | ||
@listing = Listing.new | ||
@listing.driver = false | ||
@listing.board = @board | ||
|
||
render :template => "public/new" | ||
end | ||
|
||
# GET /listings/1/edit | ||
def edit | ||
@listing = Listing.first!(:id => params[:id], :board => @board) | ||
|
||
render :template => "public/removal" | ||
end | ||
|
||
# POST /listings/1/reminder | ||
def reminder | ||
@listing = Listing.first!(:id => params[:id], :board => @board) | ||
|
||
# @listing.board.venue has no lang_code state set !!! | ||
url = @venue.iframe_url | ||
if url.blank? | ||
if @venue.password | ||
# TODO maybe it is just the other url as well ?! | ||
url = url_for(:controller => :listings, | ||
:action => :edit) | ||
else | ||
url = url_for(:id => @listing.id, | ||
:venue => @venue.name, | ||
:board_id => @board.id, | ||
:lang => @lang.code, | ||
:controller => :public_listings, | ||
:action => :edit) | ||
end | ||
end | ||
logger.debug "listing url: " + url if logger && logger.debug? | ||
Mailer.deliver_remind(@listing, url) | ||
render :template => "public/reminder_sent" | ||
end | ||
|
||
# POST /listings | ||
# POST /listings.xml | ||
def create | ||
date = DateTime.civil(params[:listing].delete("ridedate(1i)").to_i, params[:listing].delete("ridedate(2i)").to_i, params[:listing].delete("ridedate(3i)").to_i) | ||
@listing = Listing.new(params[:listing]) | ||
@listing.ridedate = date | ||
@listing.board = @board | ||
@listing.reset_password | ||
|
||
if !Listing.first(:board_id => @listing.board.id, | ||
:name => @listing.name, | ||
:location => @listing.location, | ||
:email => @listing.email, | ||
:ridedate => @listing.ridedate, | ||
:driver => @listing.driver).nil? | ||
render :template => "public/exists" | ||
elsif @listing.save | ||
url = @venue.iframe_url | ||
if url.blank? | ||
url = url_for(:venue => @venue.name, | ||
:id => @board.id, | ||
:lang => @lang.code, | ||
:controller => :public_boards, | ||
:action => :show) | ||
end | ||
|
||
Mailer.deliver_confirm(@listing, url, @lang.code) | ||
|
||
render :template => "public/created" | ||
else | ||
render :template => "public/new" | ||
end | ||
end | ||
|
||
# DELETE /listings/1 | ||
# DELETE /listings/1.xml | ||
def destroy | ||
@listing = Listing.first(:id => params[:id], :board => @board) | ||
|
||
if @listing && params[:password] == @listing.password | ||
@listing.destroy | ||
render :template => "public/confirmed" | ||
else | ||
render :template => "public/not_authorized" | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module ContactsHelper | ||
|
||
def display(tag, field) | ||
if @contact.errors.invalid? field | ||
"<div class='fieldWithErrors'>#{tag}</div>" | ||
else | ||
tag | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
class Contact | ||
attr_accessor :name, :email, :phone | ||
|
||
def model | ||
self.class | ||
end | ||
|
||
def key | ||
name | ||
end | ||
|
||
def initialize(contact = nil) | ||
if contact | ||
self.name = contact[:name] | ||
self.email = contact[:email] | ||
self.phone = contact[:phone] | ||
@my_listing_id = contact[:listing_id] | ||
@my_listing = contact[:listing] | ||
end | ||
@my_errors = { } | ||
end | ||
|
||
def valid? | ||
validate | ||
@my_errors.size == 0 | ||
end | ||
|
||
def errors | ||
def @my_errors.invalid?(attr) | ||
self[attr.to_sym] || false | ||
end | ||
def @my_errors.count | ||
self.size | ||
end | ||
def @my_errors.full_messages | ||
self.values | ||
end | ||
@my_errors | ||
end | ||
|
||
def validate | ||
@my_errors[:listing] = "listing cannot be blank" if (@my_listing == nil && @my_listing_id == nil) | ||
@my_errors[:name] = "Please fill in your name" if self.name == nil | ||
@my_errors[:name] = "Please fill in a valid name" unless (self.name =~ /^\w+$/) | ||
@my_errors[:phone] = "Please fill in a valid phone number" if (self.phone && !self.phone =~ /^[-0-9() +]+$/) | ||
@my_errors[:email] = "Please fill in a valid email address" unless self.email =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/ | ||
end | ||
|
||
def listing_id | ||
listing.id | ||
end | ||
|
||
def listing=(listing) | ||
@my_listing = listing | ||
end | ||
|
||
def listing | ||
@my_listing = Listing.find(@my_listing_id) if @my_listing == nil and @my_listing_id != nil | ||
@my_listing | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.