Guest User

Untitled

a guest
Mar 6th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.15 KB | None | 0 0
  1. #require 'gruff'
  2.  
  3. class FrontController < ApplicationController
  4.  
  5. before_filter :get_stuff,
  6. :except => [:login]
  7.  
  8. before_filter :check_authentication,
  9. :check_authorization,
  10. :only => [:add_topic, :post_reply, :post_photo_comment, :settings]
  11.  
  12.  
  13. def index
  14. @pics = Gallery.find(:all)
  15. @welcome = Welcome.find(:first)
  16. @news = News.find(:all, :order => "date DESC")
  17. @sponsors = Sponsor.find(:all, :order => "image_url DESC")
  18. @fixtures = Fixture.find(:all, :order => "date ASC" )
  19. @nextFixture
  20. for fixture in @fixtures do
  21. if(fixture.date.to_date >= Time.now.to_date)
  22. @nextFixture = fixture
  23. break
  24. end
  25. end
  26. @fiveFixtures = Array.new
  27. for fixture in @fixtures
  28. if(fixture.date > Time.now)
  29. @fiveFixtures << fixture
  30. end
  31. if @fiveFixtures.length == 5
  32. break
  33. end
  34. end
  35. @results = Result.find(:all)
  36. @lastFix
  37. for fixture in @fixtures do
  38. if(fixture.date < Time.now)
  39. @lastFix = fixture
  40. break
  41. end
  42. end
  43. @lastResult = Result.find(:first, :conditions => "fixture_id = #{@lastFix.id}")
  44. @fiveResults = Array.new
  45. for result in @results
  46. @fiveResults << result
  47. if @fiveResults.length == 5
  48. break
  49. end
  50. end
  51. end
  52.  
  53. #News
  54. def news
  55. @news = News.find(:all, :order => "date DESC")
  56. end
  57.  
  58. def showNews
  59. @article = News.find(params[:id])
  60. end
  61.  
  62. #Players
  63. def players
  64.  
  65. end
  66.  
  67. def show_player
  68. @player = Player.find(params[:id])
  69. end
  70.  
  71. #Polls
  72. def polls
  73.  
  74. end
  75.  
  76. def addVote
  77. if cookies[:voted] != "true"
  78. @answers = PollAnswer.find(:all, :conditions => "poll_id = #{params[:poll_id]}")
  79. @vote = PollVote.new
  80. @vote.answer_id = params[:poll_vote][:answer_id]
  81. @vote.poll_id = params[:poll_id]
  82. @vote.save
  83. cookies[:voted] = "true"
  84. redirect_to :action => 'polls'
  85. else
  86. flash[:notice] = "You have already voted!"
  87. redirect_to :action => 'polls'
  88. end
  89. end
  90.  
  91. def showResults
  92. @total_votes = PollVote.count(["poll_id = ?", params[:id]])
  93. @q= PollQuestion.find(:first, :conditions => ["id = ? ", params[:id]])
  94. @answers = PollAnswer.find(:all, :conditions =>["poll_id = ?", @q.id])
  95. @votes = PollVote.find(:all, :conditions =>["poll_id = ?", @q.id])
  96. @poll = PollQuestion.find(:all, :conditions => "poll_open = 1")
  97. if @poll.length > 0
  98. @answers = PollAnswer.find(:all, :conditions =>["poll_id = ?", @poll[0].id])
  99. end
  100. end
  101.  
  102. def sponsors
  103.  
  104. end
  105.  
  106. def contact
  107.  
  108. end
  109.  
  110. def links
  111. @links = Link.find(:all)
  112. end
  113.  
  114. def videos
  115. @videos = Video.find(:all)
  116.  
  117. end
  118.  
  119. def fixtures
  120. @fixtures = Fixture.find(:all, :order => "date")
  121. end
  122.  
  123. #Results
  124. def results
  125. @fixtures = Fixture.find(:all, :order => "date")
  126. @results = Result.find(:all)
  127. @reports = Report.find(:all)
  128. end
  129.  
  130. def show_report
  131. @fixtures = Fixture.find(:all, :order => "date")
  132. @report = Report.find(params[:id])
  133. @result = Result.find(@report.result_id)
  134. @fix = Fixture.find(@result.fixture_id)
  135. end
  136.  
  137. #gallery
  138. def galleries
  139. @galleries = Gallery.find(:all)
  140. @comments = GalleryComment.find(:all)
  141. end
  142.  
  143. def view_photo
  144. @photo = Gallery.find(params[:id])
  145. @comments = GalleryComment.find(:all, :conditions => ["gallery_id = ?", params[:id]], :order => "date DESC")
  146. end
  147.  
  148. def post_photo_comment
  149. @photo = Gallery.find(params[:id])
  150. end
  151.  
  152. def add_comment
  153. @gallery_comment = GalleryComment.new(params[:gallery_comment])
  154. @gallery_comment.gallery_id = params[:gallery_id]
  155. @gallery_comment.member_id = session[:user]
  156. @gallery_comment.date = Time.now
  157. @photo = Gallery.find(params[:gallery_id])
  158. if @gallery_comment.save
  159. flash[:notice] = 'Comment was successfully added.'
  160. redirect_to :action => 'view_photo', :controller => 'front', :id => @gallery_comment.gallery_id
  161. else
  162. render :action => 'post_photo_comment', :controller => 'front', :id => @gallery_comment.gallery_id
  163. end
  164. end
  165.  
  166. #Events
  167. def events
  168. @events = Event.find(:all, :order => "date ASC")
  169. end
  170.  
  171. #Forum
  172. def forum
  173. @forums = Forum.find(:all)
  174. @posts = Post.find(:all)
  175. end
  176.  
  177. def view_forum
  178. @forum = Forum.find(params[:id])
  179. @posts = Post.find(:all, :conditions => ["forum_id = ? && topic_id is ?", @forum.id, nil], :order => "posted_on DESC")
  180. @replies = Post.find(:all, :conditions => ["topic_id is not null"])
  181. @users = User.find(:all)
  182. end
  183.  
  184. def add_topic
  185. @forum_id = params[:id]
  186. end
  187.  
  188. def create_topic
  189. @post = Post.new(params[:post])
  190. @post.author_id = session[:user]
  191. @post.posted_on = Time.now
  192. if @post.save
  193. flash[:notice] = 'Post was successfully added.'
  194. redirect_to :action => 'view_forum', :id => @post.forum_id
  195. else
  196. render :action => 'add_topic', :id => @post.forum_id
  197. end
  198. end
  199.  
  200. def view_topic
  201. @post = Post.find(params[:id])
  202. @replies = Post.find(:all, :conditions => ["topic_id = ?", @post.id])
  203. @forum = Forum.find(@post.forum_id)
  204. end
  205.  
  206. def post_reply
  207. @topic_id = params[:id]
  208. end
  209.  
  210. def add_reply
  211. @post = Post.new(params[:post])
  212. @topic = Post.find_by_id(@post.topic_id) #Added to try and get the forum id to a replied post.
  213.  
  214. @post.forum_id = @topic.forum_id #
  215. @post.author_id = session[:user]
  216. @post.posted_on = Time.now
  217. if @post.save
  218. flash[:notice] = 'Post was successfully added.'
  219. redirect_to :action => 'view_topic', :id => @post.topic_id
  220. else
  221. render :action => 'view_topic', :id => @post.topic_id
  222. end
  223. end
  224.  
  225. #User Process
  226. def register
  227.  
  228. end
  229.  
  230. def register_user
  231. @user = User.new
  232. if(params[:password] == "" || params[:password_conf] == "")
  233. @user.errors.add_to_base( "Password and Password Confirmation cannot be empty")
  234. render :action => "register"
  235. elsif(params[:user][:email] == nil )
  236. @user.errors.add_to_base("Email Address cannot be empty")
  237. render :action => "register"
  238. elsif(params[:user][:firstname] == nil || params[:user][:surname] == nil)
  239. @user.errors.add_to_base("Both Firstname and Surname cannot be empty")
  240. render :action => "register"
  241. else
  242. if(params[:password] == params[:password_conf])
  243. @user = User.create(:username => params[:user][:username])
  244. @user.email = params[:user][:email]
  245. @user.firstname = params[:user][:firstname]
  246. @user.surname = params[:user][:surname]
  247. @user.password = params[:password]
  248. role = Role.find_by_name("Forum User")
  249. @user.roles << role
  250. if @user.save
  251. flash[:notice] = "Registration successful, please login using your username and password."
  252. render :action => "register"
  253. else
  254. render :action => "register"
  255. end
  256.  
  257. else
  258. @user.errors.add_to_base("Error passwords do not match.")
  259. render :action => "register"
  260. end
  261. end
  262. end
  263.  
  264. #login processing
  265. def login
  266. if request.post?
  267. if (user = User.authenticate(params[:username], params[:password]))
  268. session[:user] = user.id
  269. session[:username] = user.username
  270. redirect_to :action => 'index'
  271. else
  272. flash[:notice] = "Invalid username/password combination."
  273. redirect_to :action => 'register'
  274. end
  275. end
  276. end
  277.  
  278. def logout
  279. session[:user] = nil
  280. session[:username] = nil
  281. redirect_to :action => 'index'
  282. end
  283.  
  284. def lost_pass
  285. if(params[:username])
  286. @user = User.find(:first, :conditions => ["username = ?", params[:username]])
  287. @newPass = User.random_string(6)
  288. @user.password = @newPass
  289. @user.save
  290. LostPass.deliver_email_new_password(@user, @newPass)
  291. flash[:notice] = "Password Reset Details Have Been Emailed."
  292. redirect_to :action => 'register'
  293. end
  294. end
  295.  
  296. def change_pass
  297. if( params[:curr_pass] == nil || params[:new_pass] == nil || params[:conf_new_pass] == nil)
  298. flash[:notice] = "All fields must be completed to change password."
  299. redirect_to :action => 'settings'
  300. else
  301. if request.post?
  302. if(params[:new_pass] == params[:conf_new_pass])
  303. if (user = User.authenticate(User.find(session[:user]).username, params[:curr_pass]))
  304. user.password = params[:new_pass]
  305. user.save
  306. flash[:notice] = "Password Successfully changed."
  307. redirect_to :action => 'settings'
  308. else
  309. flash[:notice] = "Invalid username/password combination."
  310. redirect_to :action => 'settings'
  311. end
  312. else
  313. flash[:notice] = "New Passwords do not match please try again."
  314. redirect_to :action => 'settings'
  315. end
  316. end
  317. end
  318. end
  319.  
  320. def settings
  321. @user = User.find(session[:user])
  322. end
  323.  
  324. def update_user
  325. @user = User.find(session[:user])
  326. if @user.update_attributes(params[:user])
  327. flash[:notice] = 'Your account details have been successfully updated'
  328. redirect_to :action => 'settings'
  329. else
  330. render:action => 'settings'
  331. end
  332. end
  333. end
Add Comment
Please, Sign In to add comment