Commit e2481da7 authored by zh99998's avatar zh99998

用户信息页

parent fe697aec
......@@ -4,6 +4,7 @@ gem 'rails', '3.2.2'
gem "activerecord-import", ">= 0.2.0"
gem 'will_paginate'
gem 'will-paginate-i18n'
gem "paperclip", "~> 3.0"
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
......
......@@ -33,6 +33,7 @@ GEM
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.0)
cocaine (0.2.1)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
......@@ -58,6 +59,12 @@ GEM
multi_json (1.1.0)
mysql2 (0.3.11)
mysql2 (0.3.11-x86-mingw32)
paperclip (3.0.1)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (>= 0.0.2)
mime-types
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
......@@ -114,6 +121,7 @@ DEPENDENCIES
coffee-rails (~> 3.2.1)
jquery-rails
mysql2
paperclip (~> 3.0)
rails (= 3.2.2)
sass-rails (~> 3.2.3)
uglifier (>= 1.0.3)
......
body {
background: url(http://sh.convnet.net:7955/images/duel%20ranking.jpg) no-repeat top center #000000;
background: image-url("ygologo.jpg") no-repeat top center #000000;
margin: 0px;
font-size:14px;
color: white
......
......@@ -55,6 +55,7 @@ class DuelsController < ApplicationController
@duel.version = params[:duel][:version]
@duel.user1 = User.find_or_create_by_name params[:duel][:user1_name] if params[:duel][:user1_name]
@duel.user2 = User.find_or_create_by_name params[:duel][:user2_name] if params[:duel][:user2_name]
return if @duel.user1 == @duel.user2
[params[:duel][:user1_main], params[:duel][:user1_extra], params[:duel][:user2_main], params[:duel][:user2_extra]].each_with_index do |cards, index|
user = index / 2 == 0 ? @duel.user1 : @duel.user2
main = index % 2 == 0
......@@ -68,16 +69,24 @@ class DuelsController < ApplicationController
if params[:duel][:credits] == "true"
if @duel.winner == @duel.user1
@duel.user1_credits = 10
@duel.user2_credits = -10
@duel.user2_credits = -8
else
@duel.user1_credits = -10
@duel.user1_credits = -8
@duel.user2_credits = 10
end
else
@duel.user1_credits = 0
@duel.user2_credits = 0
@duel.user1_credits = 1
@duel.user2_credits = 1
end
@duel.created_at = Time.zone.parse params[:duel][:created_at]#.to_i
if @duel.user1
@duel.user1.credits += @duel.user1_credits
@duel.user1.save
end
if @duel.user2
@duel.user2.credits += @duel.user2_credits
@duel.user2.save
end
@duel.created_at = Time.zone.parse params[:duel][:created_at]
respond_to do |format|
if @duel.save
format.html { redirect_to @duel, notice: 'Duel was successfully created.' }
......
......@@ -19,11 +19,12 @@ class UsersController < ApplicationController
# GET /users/1
# GET /users/1.xml
def show
@user = User.find(params[:id])
@user = User.find_by_id(params[:id]) || User.find_by_name(params[:id])
@actions = [{"YGO战网" => users_path}, @user]
respond_to do |format|
format.html # show.html.erb
#format.xml { render :xml => @user }
format.png {redirect_to @user.avatar.url(:middle)}
end
end
......@@ -41,7 +42,20 @@ class UsersController < ApplicationController
# GET /users/1/edit
def edit
if @current_user != User::Guest
@user = User.find(params[:id])
@actions = [@user, "修改头像"]
if @current_user != @user
respond_to do |format|
format.html {redirect_to(edit_user_path(@current_user), :notice => '请先登录.')}
end
end
else
respond_to do |format|
format.html {redirect_to(:login, :notice => '请先登录.')}
end
end
end
# POST /users
......@@ -91,6 +105,7 @@ class UsersController < ApplicationController
# PUT /users/1.xml
def update
@user = User.find(params[:id])
if @user == @current_user
if !params[:user][:theme].blank? && @site[:themes].has_key?(params[:theme])
cookies[:user][:theme] = params[:theme]
end
......@@ -103,6 +118,11 @@ class UsersController < ApplicationController
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
else
respond_to do |format|
format.html { redirect_to(:back, :notice => '只能修改自己的头像') }
end
end
end
# DELETE /users/1
......
......@@ -12,6 +12,9 @@ class Duel < ActiveRecord::Base
result = cards.where('user_id=? and main = ?', user, main)
result.order("field(card_type, #{(main ? main_order : extra_order).collect{|type|"'#{type}'"}.join(',')})", 'cards.id')
end
def replay
"http://140.113.242.66/#{super}"
end
def user1
super || User::Guest
end
......
#encoding: UTF-8
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :middle => ["120x120#", :png], :small => ["48x48#", :png] }, :default_url => lambda { |avatar| "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(avatar.instance.email.strip.downcase)}?size=#{120}" }
#has_and_belongs_to_many :cards, :table_name => :duels_users_cards
has_many :duel_user_cards
has_many :cards, :through => :duel_user_cards
......@@ -29,17 +31,17 @@ class User < ActiveRecord::Base
def to_s
"<a href=\"/users/#{id}\">#{name}</a>".html_safe
end
def avatar(size=nil)
size = case size
when :small
48
when Integer
size
else
120
end
"<a href=\"/users/#{id}\"><img src=\"http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.strip.downcase)}?size=#{size}\" /></a>".html_safe
end
# def avatar(size=nil)
# size = case size
# when :small
# 48
# when Integer
# size
# else
# 120
# end
# "<a href=\"/users/#{id}\"><img src=\"http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.strip.downcase)}?size=#{size}\" /></a>".html_safe
# end
class <<self #TODO
......
<p>
<b>常用怪兽:</b>
<%= render @cards.main_monsters.top(10) %>
</p>
<p>
<b>常用额外:</b>
<%= render @cards.extra.top(5) %>
</p>
<p>
<b>常用魔法:</b>
<%= render @cards.magics.top(5) %>
</p>
<p>
<b>常用陷阱:</b>
<%= render @cards.traps.top(5) %>
</p>
<style>
.card {float:left; padding-left:10px; padding-bottom:9px;}
.card img{width:40px; height:50px; border:0px;}
.user{ width:330px; font-size:20px; color:#ffcc66; float:left; cursor:pointer; line-height:40px;padding-left: 12px;font-weight: bold;}
.user_act{ width:330px; font-size:20px; color:#ffcc66; float:left; cursor:pointer; background-color:#111111; line-height:40px;padding-left: 12px;font-weight: bold;}
#cards{background-color:#111111; overflow:hidden; padding:12px;text-align: left}
</style>
<div id="cards">
<p><b>常用怪兽:</b> </p>
<% @cards.main_monsters.top(10).each do |card| %>
<div class="card">
<%= link_to image_tag(card.image, :title => card.name), card %>
</div>
<% end %>
<div style="clear:both"></div>
<p><b>常用额外:</b> </p>
<% @cards.extra.top(5).each do |card| %>
<div class="card">
<%= link_to image_tag(card.image, :title => card.name), card %>
</div>
<% end %>
<div style="clear:both"></div>
<p><b>常用魔法:</b> </p>
<% @cards.magics.top(5).each do |card| %>
<div class="card">
<%= link_to image_tag(card.image, :title => card.name), card %>
</div>
<% end %>
<div style="clear:both"></div>
<p><b>常用陷阱:</b> </p>
<% @cards.traps.top(5).each do |card| %>
<div class="card">
<%= link_to image_tag(card.image, :title => card.name), card %>
</div>
<% end %>
</div>
\ No newline at end of file
<div id="replay"><a href="#">录像下载</a></div>
<div id="replay"><%= link_to '录像下载', @duel.replay %></div>
<style type="text/css">
<!--
......
......@@ -5,7 +5,7 @@
<%= post.user %>
</div>
<div>
<div class="avatar" onmouseover="showauthor(this, 'userinfo751931')"><%= post.user.avatar %></div>
<div class="avatar" onmouseover="showauthor(this, 'userinfo751931')"><%= image_tag post.user.avatar.url(:middle) %></div>
<p><%= post.user.role %></p>
<p><em><%= post.user.nickname %></em></p>
......
......@@ -65,7 +65,7 @@
<table cellspacing="0" cellpadding="0">
<tbody><tr>
<td class="postauthor">
<div class="avatar"><%= @current_user.avatar %></td>
<div class="avatar"><%= image_tag @current_user.avatar.url(:middle) %></td>
<td class="postcontent">
<!--<input type="hidden" name="formhash" value="ba0236f6">
<input type="hidden" name="subject" value="">
......
<h1>Editing user</h1>
当前头像:<%= image_tag @user.avatar.url(:middle) %>
<%= form_for @user, :url => user_path, :html => { :multipart => true } do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<%= render 'form' %>
<%= link_to 'Show', @user %> |
<%= link_to 'Back', users_path %>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.file_field :avatar %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
\ No newline at end of file
......@@ -3,6 +3,7 @@
#users thead {line-height:25px; background-color:#1c1b1b; height:25px; color:#d6edff; font-weight:bold;}
#users tbody {line-height:25px; padding-top:3px; font-weight:bold; }
#users .index {color:#d6edff}
#users .me {color:deepskyblue}
#users .name a {color:#FFE793}
#users .credits {color:#FF6468}
#users .ratio {color:#58DB3E; text-align:right}
......@@ -17,7 +18,9 @@
<th>名次</th>
<th>决斗者</th>
<th>积分</th>
<th colspan="3">胜率/胜/负</th>
<th>胜率</th>
<th></th>
<th></th>
<th>得分纪录</th>
</tr>
</thead>
......@@ -29,12 +32,18 @@
<% end %>
<% top_users.each_with_index do |user, index| %>
<tr>
<td class="index"><%= user == @current_user ? my_index : index.next %></td>
<% if user == @current_user %>
<td class="index me"><%= my_index %></td>
<% else %>
<td class="index"><%= index.next %></td>
<% end %>
<td class="name"><%= link_to user.name, user %></td>
<td class="credits"><%= user.credits %></td>
<td class="ratio"><%= user.win.zero? && user.lost.zero? ? 0 : user.win * 100 / (user.win + user.lost) %>%</td>
<td class="win"><%= user.win %></td>
<td class="lost"><%= user.lost %></td>
<% win = user.wins.count %>
<% all = user.duels.count %>
<td class="ratio"><%= all.zero? ? 0 : 100 * win / all %>%</td>
<td class="win"><%= win %></td>
<td class="lost"><%= all - win %></td>
<td class="show"><%= link_to '详情', user %></td>
</tr>
<% end %>
......
......@@ -6,32 +6,78 @@
#duels .win {color:#58db3e}
#duels .lose {color:red}
#duels .current {color:red}
#user p {text-align: left}
#user #avatar{float:right}
.card {float:left; padding-left:10px; padding-bottom:9px;}
.card img{width:40px; height:50px; border:0px;}
.user{ width:330px; font-size:20px; color:#ffcc66; float:left; cursor:pointer; line-height:40px;padding-left: 12px;font-weight: bold;}
.user_act{ width:330px; font-size:20px; color:#ffcc66; float:left; cursor:pointer; background-color:#111111; line-height:40px;padding-left: 12px;font-weight: bold;}
#cards{background-color:#111111; overflow:hidden; padding:12px;text-align: left}
</style>
<div id="user">
<%= form_for @user, :url => user_path, :html => { :multipart => true } do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<div id="duels">
<%= @user.wins.count %>:负<%= @user.losts.count %> 总场次:<%= @user.duels.count %>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div id="avatar">
<div><%= image_tag @user.avatar.url(:middle) %></div>
<% if @user == @current_user %>
<div><%= f.file_field :avatar, style:"width:120px", onchange: "submit(); this.disabled=true;" %></div>
<% end %>
</div>
<p>用户名: <%= @user.name %></p>
<p>id: <%= @user.id %></p>
<p>邮箱: <%= @user.email %></p>
<p>注册时间: <%=l @user.created_at, :format => :long %></p>
<p>决斗统计:胜<%= @user.wins.count %>:负<%= @user.losts.count %> 总场次:<%= @user.duels.count %></p>
<% end %>
</div>
<div style="clear:both"></div>
<div id="cards">
<p>
<b>常用怪兽:</b>
<%= render @user.cards.main_monsters.top(10) %>
</p>
<p>
<b>常用额外:</b>
<%= render @user.cards.extra.top(5) %>
</p>
<p>
<b>常用魔法:</b>
<%= render @user.cards.magics.top(5) %>
</p>
<p>
<b>常用陷阱:</b>
<%= render @user.cards.traps.top(5) %>
</p>
<p><b>常用怪兽:</b> </p>
<% @user.cards.main_monsters.top(10).each do |card| %>
<div class="card">
<%= link_to image_tag(card.image, :title => card.name), card %>
</div>
<% end %>
<div style="clear:both"></div>
<p><b>常用额外:</b> </p>
<% @user.cards.extra.top(5).each do |card| %>
<div class="card">
<%= link_to image_tag(card.image, :title => card.name), card %>
</div>
<% end %>
<div style="clear:both"></div>
<p><b>常用魔法:</b> </p>
<% @user.cards.magics.top(5).each do |card| %>
<div class="card">
<%= link_to image_tag(card.image, :title => card.name), card %>
</div>
<% end %>
<div style="clear:both"></div>
<p><b>常用陷阱:</b> </p>
<% @user.cards.traps.top(5).each do |card| %>
<div class="card">
<%= link_to image_tag(card.image, :title => card.name), card %>
</div>
<% end %>
</div>
<table id="duels">
<thead>
<tr>
......
class AddAttachmentAvatarToUser < ActiveRecord::Migration
def self.up
add_column :users, :avatar_file_name, :string
add_column :users, :avatar_content_type, :string
add_column :users, :avatar_file_size, :integer
add_column :users, :avatar_updated_at, :datetime
end
def self.down
remove_column :users, :avatar_file_name
remove_column :users, :avatar_content_type
remove_column :users, :avatar_file_size
remove_column :users, :avatar_updated_at
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120309231620) do
ActiveRecord::Schema.define(:version => 20120402031416) do
create_table "boards", :force => true do |t|
t.string "name", :default => "", :null => false
......@@ -60,10 +60,13 @@ ActiveRecord::Schema.define(:version => 20120309231620) do
t.integer "user1_id"
t.integer "user2_id"
t.integer "winner_id"
t.integer "winreason"
t.string "replay"
t.integer "user1_credits"
t.integer "user2_credits"
t.integer "winreason", :default => 0, :null => false
t.string "replay", :default => "", :null => false
t.integer "user1_credits", :default => 0, :null => false
t.integer "user2_credits", :default => 0, :null => false
t.integer "version"
t.boolean "user1_public", :default => true, :null => false
t.boolean "user2_public", :default => true, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
......@@ -179,7 +182,7 @@ ActiveRecord::Schema.define(:version => 20120309231620) do
create_table "users", :force => true do |t|
t.string "name", :null => false
t.string "password"
t.string "email"
t.string "email", :default => "", :null => false
t.string "nickname", :default => "", :null => false
t.text "signature"
t.integer "credits", :default => 0, :null => false
......@@ -203,6 +206,10 @@ ActiveRecord::Schema.define(:version => 20120309231620) do
t.string "theme"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "avatar_file_name"
t.string "avatar_content_type"
t.integer "avatar_file_size"
t.datetime "avatar_updated_at"
end
add_index "users", ["name"], :name => "index_users_on_name"
......
......@@ -9,9 +9,9 @@ mycard ygocore 服务器测试主页 <br />
<br /><br /><br />
以功能开发中,可能会出现程序出错、界面乱糟糟等情况 请自备氪金狗眼<br />
<a href="users">用户排行</a> <br />
<a href="users/5">用户个人信息统计</a> <br />
<a href="users/94">用户个人信息统计</a> <br />
<a href="cards">卡片排行</a> <br />
<a href="cards/2067">卡片信息</a> <br />
<a href="duels/582">决斗详情</a> <br />
<a href="duels/1922">决斗详情</a> <br />
<a href="boards">论坛</a> <br />
<a href="api">API</a> <br />
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment