Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #require 'gruff'
- class FrontController < ApplicationController
- before_filter :get_stuff,
- :except => [:login]
- before_filter :check_authentication,
- :check_authorization,
- :only => [:add_topic, :post_reply, :post_photo_comment, :settings]
- def index
- @pics = Gallery.find(:all)
- @welcome = Welcome.find(:first)
- @news = News.find(:all, :order => "date DESC")
- @sponsors = Sponsor.find(:all, :order => "image_url DESC")
- @fixtures = Fixture.find(:all, :order => "date ASC" )
- @nextFixture
- for fixture in @fixtures do
- if(fixture.date.to_date >= Time.now.to_date)
- @nextFixture = fixture
- break
- end
- end
- @fiveFixtures = Array.new
- for fixture in @fixtures
- if(fixture.date > Time.now)
- @fiveFixtures << fixture
- end
- if @fiveFixtures.length == 5
- break
- end
- end
- @results = Result.find(:all)
- @lastFix
- for fixture in @fixtures do
- if(fixture.date < Time.now)
- @lastFix = fixture
- break
- end
- end
- @lastResult = Result.find(:first, :conditions => "fixture_id = #{@lastFix.id}")
- @fiveResults = Array.new
- for result in @results
- @fiveResults << result
- if @fiveResults.length == 5
- break
- end
- end
- end
- #News
- def news
- @news = News.find(:all, :order => "date DESC")
- end
- def showNews
- @article = News.find(params[:id])
- end
- #Players
- def players
- end
- def show_player
- @player = Player.find(params[:id])
- end
- #Polls
- def polls
- end
- def addVote
- if cookies[:voted] != "true"
- @answers = PollAnswer.find(:all, :conditions => "poll_id = #{params[:poll_id]}")
- @vote = PollVote.new
- @vote.answer_id = params[:poll_vote][:answer_id]
- @vote.poll_id = params[:poll_id]
- @vote.save
- cookies[:voted] = "true"
- redirect_to :action => 'polls'
- else
- flash[:notice] = "You have already voted!"
- redirect_to :action => 'polls'
- end
- end
- def showResults
- @total_votes = PollVote.count(["poll_id = ?", params[:id]])
- @q= PollQuestion.find(:first, :conditions => ["id = ? ", params[:id]])
- @answers = PollAnswer.find(:all, :conditions =>["poll_id = ?", @q.id])
- @votes = PollVote.find(:all, :conditions =>["poll_id = ?", @q.id])
- @poll = PollQuestion.find(:all, :conditions => "poll_open = 1")
- if @poll.length > 0
- @answers = PollAnswer.find(:all, :conditions =>["poll_id = ?", @poll[0].id])
- end
- end
- def sponsors
- end
- def contact
- end
- def links
- @links = Link.find(:all)
- end
- def videos
- @videos = Video.find(:all)
- end
- def fixtures
- @fixtures = Fixture.find(:all, :order => "date")
- end
- #Results
- def results
- @fixtures = Fixture.find(:all, :order => "date")
- @results = Result.find(:all)
- @reports = Report.find(:all)
- end
- def show_report
- @fixtures = Fixture.find(:all, :order => "date")
- @report = Report.find(params[:id])
- @result = Result.find(@report.result_id)
- @fix = Fixture.find(@result.fixture_id)
- end
- #gallery
- def galleries
- @galleries = Gallery.find(:all)
- @comments = GalleryComment.find(:all)
- end
- def view_photo
- @photo = Gallery.find(params[:id])
- @comments = GalleryComment.find(:all, :conditions => ["gallery_id = ?", params[:id]], :order => "date DESC")
- end
- def post_photo_comment
- @photo = Gallery.find(params[:id])
- end
- def add_comment
- @gallery_comment = GalleryComment.new(params[:gallery_comment])
- @gallery_comment.gallery_id = params[:gallery_id]
- @gallery_comment.member_id = session[:user]
- @gallery_comment.date = Time.now
- @photo = Gallery.find(params[:gallery_id])
- if @gallery_comment.save
- flash[:notice] = 'Comment was successfully added.'
- redirect_to :action => 'view_photo', :controller => 'front', :id => @gallery_comment.gallery_id
- else
- render :action => 'post_photo_comment', :controller => 'front', :id => @gallery_comment.gallery_id
- end
- end
- #Events
- def events
- @events = Event.find(:all, :order => "date ASC")
- end
- #Forum
- def forum
- @forums = Forum.find(:all)
- @posts = Post.find(:all)
- end
- def view_forum
- @forum = Forum.find(params[:id])
- @posts = Post.find(:all, :conditions => ["forum_id = ? && topic_id is ?", @forum.id, nil], :order => "posted_on DESC")
- @replies = Post.find(:all, :conditions => ["topic_id is not null"])
- @users = User.find(:all)
- end
- def add_topic
- @forum_id = params[:id]
- end
- def create_topic
- @post = Post.new(params[:post])
- @post.author_id = session[:user]
- @post.posted_on = Time.now
- if @post.save
- flash[:notice] = 'Post was successfully added.'
- redirect_to :action => 'view_forum', :id => @post.forum_id
- else
- render :action => 'add_topic', :id => @post.forum_id
- end
- end
- def view_topic
- @post = Post.find(params[:id])
- @replies = Post.find(:all, :conditions => ["topic_id = ?", @post.id])
- @forum = Forum.find(@post.forum_id)
- end
- def post_reply
- @topic_id = params[:id]
- end
- def add_reply
- @post = Post.new(params[:post])
- @topic = Post.find_by_id(@post.topic_id) #Added to try and get the forum id to a replied post.
- @post.forum_id = @topic.forum_id #
- @post.author_id = session[:user]
- @post.posted_on = Time.now
- if @post.save
- flash[:notice] = 'Post was successfully added.'
- redirect_to :action => 'view_topic', :id => @post.topic_id
- else
- render :action => 'view_topic', :id => @post.topic_id
- end
- end
- #User Process
- def register
- end
- def register_user
- @user = User.new
- if(params[:password] == "" || params[:password_conf] == "")
- @user.errors.add_to_base( "Password and Password Confirmation cannot be empty")
- render :action => "register"
- elsif(params[:user][:email] == nil )
- @user.errors.add_to_base("Email Address cannot be empty")
- render :action => "register"
- elsif(params[:user][:firstname] == nil || params[:user][:surname] == nil)
- @user.errors.add_to_base("Both Firstname and Surname cannot be empty")
- render :action => "register"
- else
- if(params[:password] == params[:password_conf])
- @user = User.create(:username => params[:user][:username])
- @user.email = params[:user][:email]
- @user.firstname = params[:user][:firstname]
- @user.surname = params[:user][:surname]
- @user.password = params[:password]
- role = Role.find_by_name("Forum User")
- @user.roles << role
- if @user.save
- flash[:notice] = "Registration successful, please login using your username and password."
- render :action => "register"
- else
- render :action => "register"
- end
- else
- @user.errors.add_to_base("Error passwords do not match.")
- render :action => "register"
- end
- end
- end
- #login processing
- def login
- if request.post?
- if (user = User.authenticate(params[:username], params[:password]))
- session[:user] = user.id
- session[:username] = user.username
- redirect_to :action => 'index'
- else
- flash[:notice] = "Invalid username/password combination."
- redirect_to :action => 'register'
- end
- end
- end
- def logout
- session[:user] = nil
- session[:username] = nil
- redirect_to :action => 'index'
- end
- def lost_pass
- if(params[:username])
- @user = User.find(:first, :conditions => ["username = ?", params[:username]])
- @newPass = User.random_string(6)
- @user.password = @newPass
- @user.save
- LostPass.deliver_email_new_password(@user, @newPass)
- flash[:notice] = "Password Reset Details Have Been Emailed."
- redirect_to :action => 'register'
- end
- end
- def change_pass
- if( params[:curr_pass] == nil || params[:new_pass] == nil || params[:conf_new_pass] == nil)
- flash[:notice] = "All fields must be completed to change password."
- redirect_to :action => 'settings'
- else
- if request.post?
- if(params[:new_pass] == params[:conf_new_pass])
- if (user = User.authenticate(User.find(session[:user]).username, params[:curr_pass]))
- user.password = params[:new_pass]
- user.save
- flash[:notice] = "Password Successfully changed."
- redirect_to :action => 'settings'
- else
- flash[:notice] = "Invalid username/password combination."
- redirect_to :action => 'settings'
- end
- else
- flash[:notice] = "New Passwords do not match please try again."
- redirect_to :action => 'settings'
- end
- end
- end
- end
- def settings
- @user = User.find(session[:user])
- end
- def update_user
- @user = User.find(session[:user])
- if @user.update_attributes(params[:user])
- flash[:notice] = 'Your account details have been successfully updated'
- redirect_to :action => 'settings'
- else
- render:action => 'settings'
- end
- end
- end
Add Comment
Please, Sign In to add comment