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/models/tournament.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 4483535..6d92f3d 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -20,12 +20,12 @@ class Tournament < ActiveRecord::Base end def leave(user) - if players.include?(user) + if players.include?(user) && status == 0 players.delete(user) end end - def setup(tournament) + def setup() num_teams = (self.players.count/self.max_players_per_team).floor num_matches = num_teams - 1 for i in 1..num_matches @@ -33,9 +33,9 @@ class Tournament < ActiveRecord::Base end match_num = 0 team_num = 0 - self.players.each_slice(tournament.max_players_per_team) do |players| + self.players.each_slice(max_players_per_team) do |players| self.matches[match_num].teams.push(Team.create(users: players)) - if (team_num != 0 and team_num % tournament.max_teams_per_match == 0) + if (team_num != 0 and team_num % max_teams_per_match == 0) match_num += 1 team_num = 0 else -- cgit v1.2.3-54-g00ecf From 6289593da4b6ad30c893b61caf4ac142b590710a Mon Sep 17 00:00:00 2001 From: DavisLWebb Date: Thu, 3 Apr 2014 17:56:15 -0400 Subject: Captcha --- Gemfile | 6 ++ Gemfile.lock | 31 ++++++--- app/controllers/application_controller.rb | 2 + app/controllers/matches_controller.rb | 111 +++++++++++++++++++++++++++++- app/controllers/users_controller.rb | 21 +++--- app/models/user.rb | 2 + app/views/users/new.html.erb | 2 + config/locales/en.yml | 8 +++ config/routes.rb | 2 + db/schema.rb | 11 ++- 10 files changed, 173 insertions(+), 23 deletions(-) (limited to 'app/models') diff --git a/Gemfile b/Gemfile index 688063a..fadfd18 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,12 @@ gem 'rails', '4.0.2' # bcrypt is used for password digesting gem 'bcrypt-ruby', '3.1.2' +gem 'httparty' + +gem 'simple_captcha2', require: 'simple_captcha' + +gem 'rmagick' + group :development, :test do # Use sqlite3 as the database for Active Record gem 'sqlite3' diff --git a/Gemfile.lock b/Gemfile.lock index 83f5525..a2d2578 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -26,7 +26,7 @@ GEM thread_safe (~> 0.1) tzinfo (~> 0.3.37) arel (4.0.2) - atomic (1.1.15) + atomic (1.1.16) bcrypt-ruby (3.1.2) bootstrap-sass (3.1.1.0) sass (~> 3.2) @@ -43,6 +43,9 @@ GEM erubis (2.7.0) execjs (2.0.2) hike (1.2.3) + httparty (0.13.0) + json (~> 1.8) + multi_xml (>= 0.5.2) i18n (0.6.9) jbuilder (1.5.3) activesupport (>= 3.0.0) @@ -57,7 +60,8 @@ GEM treetop (~> 1.4.8) mime-types (1.25.1) minitest (4.7.5) - multi_json (1.8.4) + multi_json (1.9.2) + multi_xml (0.5.5) polyglot (0.3.4) rack (1.5.2) rack-test (0.6.2) @@ -75,18 +79,22 @@ GEM activesupport (= 4.0.2) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.1.1) + rake (10.2.2) rdoc (4.1.1) json (~> 1.4) ref (1.0.5) - sass (3.2.14) - sass-rails (4.0.1) + rmagick (2.13.2) + sass (3.2.18) + sass-rails (4.0.2) railties (>= 4.0.0, < 5.0) - sass (>= 3.1.10) + sass (~> 3.2.0) + sprockets (~> 2.8, <= 2.11.0) sprockets-rails (~> 2.0.0) sdoc (0.4.0) json (~> 1.8) rdoc (~> 4.0, < 5.0) + simple_captcha2 (0.2.1) + rails (>= 3.1) sprockets (2.11.0) hike (~> 1.2) multi_json (~> 1.0) @@ -100,8 +108,8 @@ GEM therubyracer (0.12.1) libv8 (~> 3.16.14.0) ref - thor (0.18.1) - thread_safe (0.2.0) + thor (0.19.1) + thread_safe (0.3.1) atomic (>= 1.1.7, < 2) tilt (1.4.1) treetop (1.4.15) @@ -109,8 +117,8 @@ GEM polyglot (>= 0.3.1) turbolinks (2.2.1) coffee-rails - tzinfo (0.3.38) - uglifier (2.4.0) + tzinfo (0.3.39) + uglifier (2.5.0) execjs (>= 0.3.0) json (>= 1.8.0) @@ -122,11 +130,14 @@ DEPENDENCIES bootstrap-sass coffee-rails (~> 4.0.0) delayed_job + httparty jbuilder (~> 1.2) jquery-rails rails (= 4.0.2) + rmagick sass-rails (~> 4.0.0) sdoc + simple_captcha2 sqlite3 therubyracer turbolinks 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 277d885..7c8ae84 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 %>

+ <%= show_simple_captcha %> + <%= f.submit("Be a Leaguer", :class => "signup") %>

<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 0653957..9b7f013 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -21,3 +21,11 @@ en: hello: "Hello world" + + simple_captcha: + placeholder: "Enter the image value" + label: "Enter the code in the box:" + + message: + default: "Secret Code did not match with the Image" + user: "The secret Image and code were different" diff --git a/config/routes.rb b/config/routes.rb index 571e629..01a63e9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,8 @@ Leaguer::Application.routes.draw do resource :server, only: [:show, :edit, :update] + #match 'simple_captcha/:id', :to => 'simple_captcha#show', :as => :simple_captcha + resources :teams resources :tournaments do resources :matches diff --git a/db/schema.rb b/db/schema.rb index 113f16d..30ac1af 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140403155049) do +ActiveRecord::Schema.define(version: 20140403171427) do create_table "alerts", force: true do |t| t.integer "author_id" @@ -129,6 +129,15 @@ ActiveRecord::Schema.define(version: 20140403155049) do add_index "sessions", ["token"], name: "index_sessions_on_token", unique: true add_index "sessions", ["user_id"], name: "index_sessions_on_user_id" + create_table "simple_captcha_data", force: true do |t| + t.string "key", limit: 40 + t.string "value", limit: 6 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "simple_captcha_data", ["key"], name: "idx_key" + create_table "teams", force: true do |t| t.integer "match_id" t.datetime "created_at" -- cgit v1.2.3-54-g00ecf 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 ++++----- app/models/tournament.rb | 6 +++--- app/views/matches/index.html.erb | 18 +++++++----------- 3 files changed, 14 insertions(+), 19 deletions(-) (limited to 'app/models') 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 diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 6d92f3d..f1d533d 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -26,14 +26,14 @@ class Tournament < ActiveRecord::Base end def setup() - num_teams = (self.players.count/self.max_players_per_team).floor + num_teams = (self.players.count/self.min_players_per_team).floor num_matches = num_teams - 1 for i in 1..num_matches - self.matches.create(name: "Match #{i}") + self.matches.create(name: "Match #{i}", status: 0) end match_num = 0 team_num = 0 - self.players.each_slice(max_players_per_team) do |players| + self.players.each_slice(min_players_per_team) do |players| self.matches[match_num].teams.push(Team.create(users: players)) if (team_num != 0 and team_num % max_teams_per_match == 0) match_num += 1 diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index babf45e..d4ddb0e 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -1,28 +1,23 @@ -

<%= @tournament.name %> Matches

+

<%= @tournament.name %> - Matches

- +
- - - - - + <% @tournament.matches.each do |match| %> - - + - + <% end %> @@ -37,7 +32,8 @@ xmlns="http://www.w3.org/2000/svg"> <% (1..@matches.count).each do |i| %> - + + <% end %> -- cgit v1.2.3-54-g00ecf From cb1e09a7ef061cd3c1ca7cf5793d09b2aacb1536 Mon Sep 17 00:00:00 2001 From: guntasgrewal Date: Fri, 4 Apr 2014 18:35:40 -0400 Subject: Cookie size 20 minutes --- Gemfile | 2 +- Gemfile.lock | 2 -- app/helpers/sessions_helper.rb | 4 ++-- app/models/match.rb | 3 +++ app/views/matches/show.html.erb | 19 +++++++++++++++++++ 5 files changed, 25 insertions(+), 5 deletions(-) (limited to 'app/models') diff --git a/Gemfile b/Gemfile index fadfd18..a34b0a6 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'httparty' gem 'simple_captcha2', require: 'simple_captcha' -gem 'rmagick' +#gem 'rmagick' group :development, :test do # Use sqlite3 as the database for Active Record diff --git a/Gemfile.lock b/Gemfile.lock index a2d2578..51e29e7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -83,7 +83,6 @@ GEM rdoc (4.1.1) json (~> 1.4) ref (1.0.5) - rmagick (2.13.2) sass (3.2.18) sass-rails (4.0.2) railties (>= 4.0.0, < 5.0) @@ -134,7 +133,6 @@ DEPENDENCIES jbuilder (~> 1.2) jquery-rails rails (= 4.0.2) - rmagick sass-rails (~> 4.0.0) sdoc simple_captcha2 diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb index 89e5ef3..60ddfa6 100644 --- a/app/helpers/sessions_helper.rb +++ b/app/helpers/sessions_helper.rb @@ -5,8 +5,8 @@ module SessionsHelper @session.save # FIXME: error handling @token = Session.hash_token(raw_token) - cookies.permanent[:remember_token] = raw_token - + #cookies.permanent[:remember_token] = raw_token + cookies.permanent[:remember_token] = { value: remember_token, expires: 20.minutes.from_now.utc } #set the current user to be the given user @current_user = user end diff --git a/app/models/match.rb b/app/models/match.rb index 35deb20..c596ced 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -5,4 +5,7 @@ class Match < ActiveRecord::Base belongs_to :winner, class_name: "Team" + def setup() + + end end diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index 53c3b38..4973dc3 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -12,7 +12,24 @@ Name: <%= @match.name %>

+ + <% if (@tournament.hosts.include?(current_user) and @match.winner.nil?) %> <%= form_for([@tournament, @match], method: "put") do |f| %>
    @@ -25,6 +42,8 @@ <% end %> <% end %> + + <% unless @match.winner.nil? %>

    Winner: -- cgit v1.2.3-54-g00ecf

StatusTournament Name WinnerRemote
<%= match.tournament.id %> <%= match.status %><%= match.tournament %><%= match.id%> <%= match.name %><%= match.winner %><%= link_to "Show", tournament_match_path(@tournament, match) %>