diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/application_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/matches_controller.rb | 111 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 21 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/views/users/new.html.erb | 2 |
5 files changed, 126 insertions, 12 deletions
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 diff --git a/app/models/user.rb b/app/models/user.rb index 016c155..9a0948f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +4,8 @@ class User < ActiveRecord::Base has_and_belongs_to_many :teams has_many :sessions + apply_simple_captcha + before_save { self.email = email.downcase } before_save { self.user_name = user_name } diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index c23f76d..5e369ac 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -23,6 +23,8 @@ <%= f.password_field :password_confirmation %> </p> <p> + <%= show_simple_captcha %> + <%= f.submit("Be a Leaguer", :class => "signup") %> </p> <% end %> |