summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorLuke Shumaker <shumakl@purdue.edu>2014-04-04 20:44:43 -0400
committerLuke Shumaker <shumakl@purdue.edu>2014-04-04 20:44:43 -0400
commit38d6960be1efdb6345445ab293a8cd605193785f (patch)
treedf37e79b5744b570aded5aa4d7fe38cd772a49fe /app
parentbcfa571b0328a4b3e94479a31c027621ceb86ad5 (diff)
parentd14dcf9af11a0f2eab2609efb7d9e59a9cc18bb0 (diff)
Merge branch 'master' into luke
Conflicts: app/controllers/application_controller.rb app/controllers/tournaments_controller.rb
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/application.css5
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--app/controllers/matches_controller.rb111
-rw-r--r--app/controllers/tournaments_controller.rb13
-rw-r--r--app/controllers/users_controller.rb21
-rw-r--r--app/helpers/sessions_helper.rb4
-rw-r--r--app/models/match.rb3
-rw-r--r--app/models/tournament.rb12
-rw-r--r--app/models/user.rb2
-rw-r--r--app/views/matches/index.html.erb22
-rw-r--r--app/views/matches/show.html.erb19
-rw-r--r--app/views/tournaments/index.html.erb2
-rw-r--r--app/views/tournaments/show.html.erb37
-rw-r--r--app/views/users/new.html.erb2
14 files changed, 183 insertions, 72 deletions
diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css
index b3f5d46..dd7588a 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -23,3 +23,8 @@
.navbar{
background-color: white;
}
+
+footer {
+ clear: both;
+ margin-top: 10px;
+} \ No newline at end of file
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 85fc5b0..d5752aa 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -11,6 +11,8 @@ class ApplicationController < ActionController::Base
#include sessionhelper for the session controller and view
include SessionsHelper
+ include SimpleCaptcha::ControllerHelpers
+
def check_permission(verb, object=nil)
unless current_user.can?((verb.to_s+"_"+noun).to_sym) or (!object.nil? and is_owner?(object))
respond_to do |format|
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index 474ae04..31fc9ad 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -3,10 +3,115 @@ class MatchesController < ApplicationController
# 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/tournaments_controller.rb b/app/controllers/tournaments_controller.rb
index 2d63068..d1a926b 100644
--- a/app/controllers/tournaments_controller.rb
+++ b/app/controllers/tournaments_controller.rb
@@ -69,12 +69,11 @@ class TournamentsController < ApplicationController
format.json { render json: @tournament.errors, status: :unprocessable_entity }
end
end
-
when "join"
check_permission(: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 }
@@ -83,17 +82,19 @@ 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.' }
format.json { render json: "Permission denied", status: :forbidden }
end
- when "open"
+ when "start"
check_permission(:edit, @tournament)
+ @tournament.status = 1
+ @tournament.save
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 }
@@ -101,7 +102,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/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 82edae7..bcb45aa 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,6 +1,7 @@
class UsersController < ApplicationController
# GET /users
+
# GET /users.json
def index
@users = User.all
@@ -23,15 +24,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/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb
index 05a29f1..8bace9e 100644
--- a/app/helpers/sessions_helper.rb
+++ b/app/helpers/sessions_helper.rb
@@ -7,8 +7,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/models/tournament.rb b/app/models/tournament.rb
index ecd551b..22711b1 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -20,22 +20,22 @@ 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)
- num_teams = (self.players.count/self.max_players_per_team).floor
+ def setup()
+ 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(tournament.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 % 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
diff --git a/app/models/user.rb b/app/models/user.rb
index 1d0879b..d1698bd 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/matches/index.html.erb b/app/views/matches/index.html.erb
index 0f86da6..d4ddb0e 100644
--- a/app/views/matches/index.html.erb
+++ b/app/views/matches/index.html.erb
@@ -1,35 +1,30 @@
-<h1><%= @tournament.name %> Matches</h1>
+<h1><%= @tournament.name %> - Matches</h1>
-<!--
-<table>
+
+<table class="table">
<thead>
<tr>
<th>Status</th>
- <th>Tournament</th>
<th>Name</th>
<th>Winner</th>
- <th>Remote</th>
- <th></th>
- <th></th>
<th></th>
</tr>
</thead>
- <tbody>
+ <tbody class="table-hover">
<% @tournament.matches.each do |match| %>
<tr>
- <td><%= match.tournament.id %></td>
<td><%= match.status %></td>
- <td><%= match.tournament %></td>
+ <td><%= match.id%></td>
<td><%= match.name %></td>
- <td><%= match.winner %></td>
+ <td><%= link_to "Show", tournament_match_path(@tournament, match) %>
</tr>
<% end %>
</tbody>
</table>
<br>
--->
+
<SVG version="1.1"
baseProfile="full"
@@ -37,7 +32,8 @@
xmlns="http://www.w3.org/2000/svg">
<% (1..@matches.count).each do |i| %>
- <g class="svg-match" >
+ <g class="svg-match">
+ <rect rx="10"
</g>
<% 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 @@
<strong>Name:</strong>
<%= @match.name %>
</p>
+<!--
+ Match Status 0 => Pairings Stage
+ Match Status 1 => Match Active
+ Match Status 2 => Match Finished (Peer Review Starts)
+ Match Status 3 => Match Completed (Scores Completed OR Results Page)
+ Four views:- (status is Match status)
+ A. Pairings, when status is 0 for either Host or Player Or when status is 1 for player
+ B. A page the host will see if status is 1 OR 2
+ C. The Peer review page that the players will see if status is 2.
+ D. The page everyone will see when status is 3.
+
+ Note:- The change of status from 1 to 2 is coming from League Data Pull (RIOT API)
+
+-->
+<!--
+ This is what the HOST will see when the Match Status is NOT 3
+-->
<% if (@tournament.hosts.include?(current_user) and @match.winner.nil?) %>
<%= form_for([@tournament, @match], method: "put") do |f| %>
<ul>
@@ -25,6 +42,8 @@
<% end %>
<% end %>
+
+
<% unless @match.winner.nil? %>
<p>
<strong>Winner:</strong>
diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb
index 6a86955..e174de7 100644
--- a/app/views/tournaments/index.html.erb
+++ b/app/views/tournaments/index.html.erb
@@ -6,7 +6,7 @@
<%# Each tournament has a div for its listing %>
<% @tournaments.each do |t| %>
<div class="row tournament-listing">
- <div class="col-md-2 ">Gravatar of Host Goes Here</div>
+ <div class="col-md-2 "><%= image_tag 'http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(t.hosts.first.email) + '?s=100&d=mm' %></div>
<div class="col-md-8">
diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb
index d246f7a..b654804 100644
--- a/app/views/tournaments/show.html.erb
+++ b/app/views/tournaments/show.html.erb
@@ -40,35 +40,6 @@
<%= @tournament.max_teams_per_match %>
</p>
-<p>
- <strong>Set rounds:</strong>
- <%= @tournament.set_rounds %>
-</p>
-
-<p>
- <strong>Min players per team:</strong>
- <%= @tournament.min_players_per_team %>
-</p>
-
-<p>
- <strong>Max players per team:</strong>
- <%= @tournament.max_players_per_team %>
-</p>
-
-<p>
- <strong>Min teams per match:</strong>
- <%= @tournament.min_teams_per_match %>
-</p>
-
-<p>
- <strong>Max teams per match:</strong>
- <%= @tournament.max_teams_per_match %>
-</p>
-
-<p>
- <strong>Set rounds:</strong>
- <%= @tournament.set_rounds %>
-</p>
<p>
<strong>Randomized teams:</strong>
@@ -108,8 +79,8 @@
<%# If user is the host, let them start the tournment %>
<% if @tournament.hosts.include?(current_user) %>
- <%= form_tag(tournaments_path.to_s + "/" + @tournament.id.to_s + "/edit", method: "get") do %>
- <input type="hidden" name="close_action" value="close">
+ <%= form_tag(tournament_path(@tournament), method: "put") do %>
+ <input type="hidden" name="update_action" value="start">
<% if @tournament.players.count >= @tournament.min_players_per_team * @tournament.min_teams_per_match %>
<%= submit_tag("Start Tournament") %>
<% else %>
@@ -146,8 +117,10 @@ function donehandle( tournament ) {
//if there are enough players to start, enable the button, else disable it.
$("input[value=\"Start Tournament\"]").prop('disabled', (pct_complete >= 1)? false : true);
+ if (tournament["status"] == 1)
+ window.location.reload(true);
}
- setTimeout(function(){$.ajax({url: "<%= url_for @tournament %>.json"}).done(donehandle)}, 3000);
+ setTimeout(function(){$.ajax({url: "<%= url_for @tournament %>.json"}).done(donehandle)}, 2000);
}
$.ajax({url: "<%= url_for @tournament %>.json"})
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 %>