app/controllers/elt_controller.rb in parlement-0.10 vs app/controllers/elt_controller.rb in parlement-0.11

- old
+ new

@@ -2,11 +2,10 @@ # This is the central component to parlement # # An element is just the name for a poll/message/issue # class EltController < ApplicationController - def index params[:id] = params[:id].gsub(/.html/, '') show end @@ -38,17 +37,17 @@ render :partial => 'listByVote' end def rss params[:id] = params[:id].gsub(/.rss/, '') - @headers["Content-Type"] = "text/xml; charset=utf-8" + headers["Content-Type"] = "text/xml; charset=utf-8" @elt = Elt.find(params[:id]) if @elt == nil end def vote_rss params[:id] = params[:id].gsub(/.rss/, '') - @headers["Content-Type"] = "text/xml; charset=utf-8" + headers["Content-Type"] = "text/xml; charset=utf-8" @elt = Elt.find(params[:id]) if @elt == nil end # Used to initialise the elt, its subject mainly def new @@ -62,24 +61,27 @@ end end def create @elt = Elt.new(params[:elt]) - @elt.person = @session[:person] + @elt.person = session[:person] - if @elt.subject =~ /([<>\/]|href)/ \ - or @elt.body =~ /(.*([<>\/]|href).*){3}/ \ + if !session[:person] and \ + (@elt.subject =~ /([<>\/]|href)/ \ + or @elt.body =~ /(.*(http|href).*){3}/ \ or @elt.body =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i \ - or @elt.body =~ /([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}.*){3}/i + or @elt.body =~ /([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}.*){3}/i) then logger.error red { underline { "SPAM! '#{@elt.subject}'" } } logger.error "SPAM! '#{@elt.body}'" flash[:error] = 'Sorry, to fight spam "<" ">" or "href" are forbidden in the subject, and there can not be more than 3 links in the body, you also can\'t input one simple email or more than 3 emails!' headers["Status"] = "404 Post considered as spam" render :controller => 'elt', :action => 'new', :status => 404 elsif params[:submit] == "preview" or (@elt.publish and @elt.parent.add_child(@elt)) then #headers["Status"] = "201 Created" render :partial => '/elt/elt', :locals => { :elt => @elt, :eltTop => false } else + logger.error "Strange error, can't preview or save an element" + puts "Strange error, can't preview or save an element" flash[:notice] = 'Error' render :controller => 'elt', :action => 'new' end end