From 051e61877b4c77a17fd4fa68dfca4d5e74a687df Mon Sep 17 00:00:00 2001 From: tkimia Date: Thu, 3 Apr 2014 17:17:12 -0400 Subject: fixed some of andrews weird stuff with starting a tournament --- app/controllers/tournaments_controller.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 9cf3404..4bba997 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -36,12 +36,7 @@ class TournamentsController < ApplicationController # GET /tournaments/1/edit def edit - if params['close_action'] == 'close' - @tournament.status = 1 - @tournament.save - @tournament.setup(@tournament) - redirect_to "/tournaments" - end + end # POST /tournaments @@ -96,7 +91,10 @@ class TournamentsController < ApplicationController format.html {redirect_to @tournament, notice: 'You were\'t a part of this tournament.' } format.json { render json: "Permission denied", status: :forbidden } end - when "open" + when "start" + @tournament.status = 1 + @tournament.save + @tournament.setup() respond_to do |format| if @tournament.setup format.html { render action: 'show', notice: 'You have joined this tournament.' } @@ -105,8 +103,6 @@ class TournamentsController < ApplicationController format.html { render action: 'permission_denied', status: :forbidden } format.json { render json: "Permission denied", status: :forbidden } end - #when "close" - # TODO else respond_to do |format| format.html { render action: 'show', notice: "Invalid action", status: :unprocessable_entity } -- cgit v1.2.3-2-g168b From 6289593da4b6ad30c893b61caf4ac142b590710a Mon Sep 17 00:00:00 2001 From: DavisLWebb Date: Thu, 3 Apr 2014 17:56:15 -0400 Subject: Captcha --- app/controllers/application_controller.rb | 2 + app/controllers/matches_controller.rb | 111 +++++++++++++++++++++++++++++- app/controllers/users_controller.rb | 21 +++--- 3 files changed, 122 insertions(+), 12 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0ac3486..43ac21f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,4 +5,6 @@ class ApplicationController < ActionController::Base #include sessionhelper for the session controller and view include SessionsHelper + + include SimpleCaptcha::ControllerHelpers end diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index ba6ab16..bb5a876 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -3,10 +3,115 @@ class MatchesController < ApplicationController before_action :set_match, only: [:show, :edit, :update, :destroy] # GET /matches # GET /matches.json - def index - @matches = @tournament.matches - end + require 'httparty' + require 'json' + + def index + @matches = @tournament.matches + end + + def get_riot_info + if signed_in? + + #current user information + response = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/#{current_user.user_name}?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + + id = response["#{current_user.user_name.downcase}"]['id'] + + #recent game information + recent = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{response["#{current_user.user_name.downcase}"]['id']}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + + game_id = recent["games"][0]["gameId"] + + #remote_user_id = 6651654651354 + #remove_user_name = TeslasMind + #How to Add + #how do I access + + #members of most recent game id's + player1 = recent["games"][0]["fellowPlayers"][0]["summonerId"] + player2 = recent["games"][0]["fellowPlayers"][1]["summonerId"] + player3 = recent["games"][0]["fellowPlayers"][2]["summonerId"] + player4 = recent["games"][0]["fellowPlayers"][3]["summonerId"] + player5 = recent["games"][0]["fellowPlayers"][4]["summonerId"] + player6 = recent["games"][0]["fellowPlayers"][5]["summonerId"] + player7 = recent["games"][0]["fellowPlayers"][6]["summonerId"] + player8 = recent["games"][0]["fellowPlayers"][7]["summonerId"] + player9 = recent["games"][0]["fellowPlayers"][8]["summonerId"] + + players_by_id = [player1, player2, player3, player4, player5, player6, player7, player8, player9] + + #collect summoner names + memb1 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player1}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + memb1 = memb1["#{player1}"] + sleep(1); + + memb2 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player2}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + memb2 = memb2["#{player2}"] + sleep(1); + + memb3 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player3}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + memb3 = memb3["#{player3}"] + sleep(1); + + memb4 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player4}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + memb4 = memb4["#{player4}"] + sleep(1); + + memb5 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player5}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + memb5 = memb5["#{player5}"] + sleep(1); + + memb6 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player6}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + memb6 = memb6["#{player6}"] + sleep(1); + + memb7 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player7}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + memb7 = memb7["#{player7}"] + sleep(1); + + memb8 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player8}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + memb8 = memb8["#{player8}"] + sleep(1); + + memb9 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player9}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + memb9 = memb9["#{player9}"] + sleep(1); + + memb10 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{id}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + memb10 = memb10["#{id}"] + + players = ["#{memb1}", "#{memb2}", "#{memb3}", "#{memb4}", "#{memb5}", "#{memb6}", "#{memb7}", "#{memb8}", "#{memb9}", "#{memb10}"] + + sleep(5); + + blue = Hash.new + purple = Hash.new + + for i in 0..8 + current_player = players_by_id[i] + place = players[i] + info = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{current_player}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + + if 100 == info["games"][0]["stats"]["team"] + blue.merge!("#{place}" => info["games"][0]["stats"]) + else + purple.merge!("#{place}" => info["games"][0]["stats"]) + end + sleep(1) + end + + if 100 == recent["games"][0]["stats"]["team"] + blue.merge!("#{players[9]}" => recent["games"][0]["stats"]) + else + purple.merge!("#{players[9]}" => recent["games"][0]["stats"]) + end + + @purp = purple + @blue = blue + end #end if + end #end def # GET /matches/1 # GET /matches/1.json def show diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 60857f1..5de344c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,6 +4,7 @@ class UsersController < ApplicationController before_action :perms_create, only: [:new, :create] # GET /users + # GET /users.json def index @users = User.all @@ -26,15 +27,17 @@ class UsersController < ApplicationController # POST /users # POST /users.json def create - @user = User.new(user_params) - respond_to do |format| - if @user.save - sign_in @user - format.html { redirect_to root_path, notice: 'User was successfully created.' } - format.json { render action: 'show', status: :created, location: @user } - else - format.html { render action: 'new', status: :unprocessable_entity } - format.json { render json: @user.errors, status: :unprocessable_entity } + if simple_captcha_valid? + @user = User.new(user_params) + respond_to do |format| + if @user.save + sign_in @user + format.html { redirect_to root_path, notice: 'User was successfully created.' } + format.json { render action: 'show', status: :created, location: @user } + else + format.html { render action: 'new', status: :unprocessable_entity } + format.json { render json: @user.errors, status: :unprocessable_entity } + end end end end -- cgit v1.2.3-2-g168b From effe4608e808a385bb912fccac26381d0bd0c95a Mon Sep 17 00:00:00 2001 From: tkimia Date: Thu, 3 Apr 2014 18:03:25 -0400 Subject: matches table is back, and a lot of things are fixed --- app/controllers/tournaments_controller.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 4bba997..ae384c1 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -76,7 +76,7 @@ class TournamentsController < ApplicationController when "join" respond_to do |format| if @tournament.join(current_user) - format.html { render action: 'show', notice: 'You have joined this tournament.' } + format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } format.json { head :no_content } end format.html { render action: 'permission_denied', status: :forbidden } @@ -85,7 +85,7 @@ class TournamentsController < ApplicationController when "leave" respond_to do |format| if @tournament.leave(current_user) - format.html {redirect_to tournaments_url, notice: 'You have left the tournament.' } + format.html { redirect_to tournaments_url, notice: 'You have left the tournament.' } format.json { head :no_content } end format.html {redirect_to @tournament, notice: 'You were\'t a part of this tournament.' } @@ -94,10 +94,9 @@ class TournamentsController < ApplicationController when "start" @tournament.status = 1 @tournament.save - @tournament.setup() respond_to do |format| if @tournament.setup - format.html { render action: 'show', notice: 'You have joined this tournament.' } + format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } format.json { head :no_content } end format.html { render action: 'permission_denied', status: :forbidden } @@ -105,7 +104,7 @@ class TournamentsController < ApplicationController end else respond_to do |format| - format.html { render action: 'show', notice: "Invalid action", status: :unprocessable_entity } + format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity } format.json { render json: @tournament.errors, status: :unprocessable_entity } end end -- cgit v1.2.3-2-g168b From d14dcf9af11a0f2eab2609efb7d9e59a9cc18bb0 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 4 Apr 2014 20:39:10 -0400 Subject: re-jigger the TournamentController#update to be all one case block --- app/controllers/tournaments_controller.rb | 67 +++++++++++++++---------------- 1 file changed, 32 insertions(+), 35 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index ae384c1..cc25033 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -59,8 +59,8 @@ class TournamentsController < ApplicationController # PATCH/PUT /tournaments/1 # PATCH/PUT /tournaments/1.json def update - - if params[:update_action].nil? + case params[:update_action] + when nil check_perms respond_to do |format| if @tournament.update(tournament_params) @@ -71,42 +71,39 @@ class TournamentsController < ApplicationController format.json { render json: @tournament.errors, status: :unprocessable_entity } end end - else - case params[:update_action] - when "join" - respond_to do |format| - if @tournament.join(current_user) - format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } - format.json { head :no_content } - end - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } + when "join" + respond_to do |format| + if @tournament.join(current_user) + format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } + format.json { head :no_content } end - when "leave" - respond_to do |format| - if @tournament.leave(current_user) - format.html { redirect_to tournaments_url, notice: 'You have left the tournament.' } - format.json { head :no_content } - end - format.html {redirect_to @tournament, notice: 'You were\'t a part of this tournament.' } - format.json { render json: "Permission denied", status: :forbidden } - end - when "start" - @tournament.status = 1 - @tournament.save - respond_to do |format| - if @tournament.setup - format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } - format.json { head :no_content } - end - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } + end + when "leave" + respond_to do |format| + if @tournament.leave(current_user) + format.html { redirect_to tournaments_url, notice: 'You have left the tournament.' } + format.json { head :no_content } end - else - respond_to do |format| - format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity } - format.json { render json: @tournament.errors, status: :unprocessable_entity } + format.html {redirect_to @tournament, notice: 'You were\'t a part of this tournament.' } + format.json { render json: "Permission denied", status: :forbidden } + end + when "start" + @tournament.status = 1 + @tournament.save + respond_to do |format| + if @tournament.setup + format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } + format.json { head :no_content } end + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } + end + else + respond_to do |format| + format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity } + format.json { render json: @tournament.errors, status: :unprocessable_entity } end end end -- cgit v1.2.3-2-g168b