Skip to content

Commit

Permalink
增加验证码
Browse files Browse the repository at this point in the history
  • Loading branch information
heyunpeng committed Jul 21, 2015
1 parent 34858d6 commit bccdaa3
Show file tree
Hide file tree
Showing 24 changed files with 10,307 additions and 46 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ gem 'sdoc', '~> 0.4.0', group: :doc
gem 'bootstrap-sass', '~> 3.3.4'
gem "rufus-scheduler"

# Captcha
gem 'simple_captcha2', require: 'simple_captcha'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

Expand Down
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
simple_captcha2 (0.3.4)
rails (>= 4.1)
spring (1.3.6)
sprockets (3.2.0)
rack (~> 1.0)
Expand Down Expand Up @@ -158,11 +160,12 @@ DEPENDENCIES
rufus-scheduler
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
simple_captcha2
spring
sqlite3
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)

BUNDLED WITH
1.10.3
1.10.5
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include SessionsHelper
include SimpleCaptcha::ControllerHelpers
end
2 changes: 1 addition & 1 deletion app/controllers/combinationgame_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
@grid = Grid.find_by_gameid(@issue)
end

if @minutes < 0
if @minutes and @minutes < 0
@minutes = 9
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/doublegame_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
@grid = Grid.find_by_gameid(@issue)
end

if @minutes < 0
if @minutes and @minutes < 0
@minutes = 9
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def index
@grid = Grid.find_by_gameid(@issue)
end

if @minutes < 0
if @minutes and @minutes < 0
@minutes = 9
end

Expand Down
66 changes: 40 additions & 26 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,49 @@ def new
end

def create
loginlog = Loginlog.new
curtime = Time.new
loginlog.time = curtime.strftime("%Y-%m-%d %H:%M:%S")

useraccount = params[:session][:account]
userpassword = params[:session][:password]
@user = User.find_by_account(useraccount)
if @user and @user.password == userpassword and @user.action == 1
session[:account] = useraccount

loginlog.username = useraccount
loginlog.action = 1
loginlog.save

session[:userid] = @user.id
if @user.level == 1
redirect_to url_for(:controller => :manage, :action => :index)
else
redirect_to url_for(:controller => :main, :action => :index)
params[:captcha] = params[:session][:captcha];
params[:captcha_key] = params[:session][:captcha_key];

if simple_captcha_valid?
loginlog = Loginlog.new
curtime = Time.new
loginlog.time = curtime.strftime("%Y-%m-%d %H:%M:%S")

useraccount = params[:session][:account]
userpassword = params[:session][:password]
@user = User.find_by_account(useraccount)

if @user and @user.password == userpassword and @user.action == 1
session[:account] = useraccount

loginlog.username = useraccount
loginlog.action = 1
loginlog.save

session[:userid] = @user.id
if @user.level == 1
redirect_to url_for(:controller => :manage, :action => :index)
else
redirect_to url_for(:controller => :main, :action => :index)
end
else

loginlog.username = useraccount
loginlog.action = -1
loginlog.save

@error = "无效的用户名或密码"
@defaultname = {:account => useraccount}
render :template => 'welcome/index'
end
else
@error = "验证码错误"
@defaultname = {:account => useraccount}
render :template => 'welcome/index'
end
else
loginlog.username = useraccount
loginlog.action = -1
loginlog.save

@error = "无效的用户名或密码"
@defaultname = {:account => useraccount}
render :template => 'welcome/index'
end

end

def destroy
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/singlegame_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
@grid = Grid.find_by_gameid(@issue)
end

if @minutes < 0
if @minutes and @minutes < 0
@minutes = 9
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class WelcomeController < ApplicationController

def index
@defaultname = {:account => ""}
session[:userid] = 0
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class User < ActiveRecord::Base
apply_simple_captcha

validates :account, presence: true, length: {minimum: 3}, uniqueness: true
validates :password, presence: true
validates :coin, numericality: {only_integer:true, greater_than: 0}
Expand Down
Binary file modified app/views/.DS_Store
Binary file not shown.
9 changes: 5 additions & 4 deletions app/views/combinationgame/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@ function updateTotal(totalcoin){
</tbody>
<tfoot>
<tr><td colspan="7" align="center">
<div>快捷投注:<input size="6" type="text" id="defaultcoin" />总投注额:
<span style="color:red" id="coinTotal">0</span>
<div><font color="green">快捷下注 金额:<input size="6" type="text" id="defaultcoin" style="margin-right:10px"/></font>
总投注额:<span style="color:red;margin-right:10px" id="coinTotal">0</span>
<%= f.hidden_field :totalcoin, id:"cointotal", value:0 %>
<%= f.submit "确认"%>
</div></td> </tr>
<button type="button", style="height:20px;width:60px;margin-right:10px", onclick="reset()">重填</button>
<%= f.submit "下注", style:"height:20px;width:60px"%>
</div></td>
</tfoot>
<%end%>
</table>
8 changes: 5 additions & 3 deletions app/views/doublegame/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ function updateTotal(totalcoin){
</tbody>
<tfoot>
<tr><td colspan="7" align="center">
<div>快捷投注 金额:<input size="6" type="text" id="defaultcoin" />总投注额:<span style="color:red" id="coinTotal">0</span>
<div><font color="green">快捷下注 金额:<input size="6" type="text" id="defaultcoin" style="margin-right:10px"/></font>
总投注额:<span style="color:red;margin-right:10px" id="coinTotal">0</span>
<%= f.hidden_field :totalcoin, id:"cointotal", value:0 %>
<%= f.submit "确认"%>
</div></td> </tr>
<button type="button", style="height:20px;width:60px;margin-right:10px", onclick="reset()">重填</button>
<%= f.submit "下注", style:"height:20px;width:60px"%>
</div></td>
</tfoot>
<%end%>
</table>
Binary file added app/views/simple_captcha/.DS_Store
Binary file not shown.
10 changes: 10 additions & 0 deletions app/views/simple_captcha/_simple_captcha.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div>
<div style="width:120px; height:40px; float:left; margin-top:20px">
<%= simple_captcha_options[:image] %>
</div>

<div style="width:40px; height:40px; float:left; margin-top:20px">
<%= simple_captcha_options[:field] %>
</div>

<div style="clear:both;"></div>
24 changes: 18 additions & 6 deletions app/views/singlegame/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ $(".reccheck").blur(function(){
{
coin = parseInt(coinitems[i].value)
if (!isNaN(coin))
total += coin
total += coin
}
updateTotal(total);
}
Expand All @@ -64,10 +64,19 @@ $(".reccheck").focus(function(){
this.value = coin
}
);
function updateTotal(totalcoin){
$("#coinTotal").text(totalcoin.toString());
document.getElementById("cointotal").value = totalcoin;
function reset(){
document.getElementById("coinTotal").innerHTML = '0';
var coinitems = document.getElementsByClassName("reccheck");
var total = 0;
for (i = 0; i < coinitems.length; i++)
{
coinitems[i].value = '';
}
}
function updateTotal(totalcoin){
$("#coinTotal").text(totalcoin.toString());
document.getElementById("cointotal").value = totalcoin;
}
<% end %>

<div class="lot-table" id="history">
Expand All @@ -80,6 +89,7 @@ $(".reccheck").focus(function(){
牌面
</td>
</tr>
<div>
<%= form_for :tracelogs, url: tracelogs_single_path do |f| %>
<tr class="even">
<td>
Expand Down Expand Up @@ -273,9 +283,11 @@ $(".reccheck").focus(function(){
</tbody>
<tfoot>
<tr><td colspan="7" align="center">
<div>快捷投注:<input size="6" type="text" id="defaultcoin" />总投注额:<span style="color:red" id="coinTotal">0</span>
<div><font color="green">快捷下注 金额:<input size="6" type="text" id="defaultcoin" style="margin-right:10px"/></font>
总投注额:<span style="color:red;margin-right:10px" id="coinTotal">0</span>
<%= f.hidden_field :totalcoin, id:"cointotal", value:0 %>
<%= f.submit "确认"%>
<button type="button", style="height:20px;width:60px;margin-right:10px", onclick="reset()">重填</button>
<%= f.submit "下注", style:"height:20px;width:60px"%>
</div></td>
</tr>
</tfoot>
Expand Down
Binary file added app/views/welcome/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<%= f.password_field :password, class: "form-control", placeholder: "請輸入密碼", required: true,
style: "margin:0 0 0 45px;"%>
</span>

<%= f.simple_captcha%>
<div class="vipC_checkBox">
<span class="leftCheckbox">
<label>
Expand Down
8 changes: 8 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@

en:
hello: "Hello world"

en:
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"
Binary file modified db/development.sqlite3
Binary file not shown.
6 changes: 6 additions & 0 deletions db/migrate/20150611111116_changeall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Changeall < ActiveRecord::Migration
def change
add_column :users, :todaycoin, :integer
add_column :users, :everylimit, :integer
end
end
15 changes: 15 additions & 0 deletions db/migrate/20150721152640_create_simple_captcha_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CreateSimpleCaptchaData < ActiveRecord::Migration
def self.up
create_table :simple_captcha_data do |t|
t.string :key, :limit => 40
t.string :value, :limit => 6
t.timestamps
end

add_index :simple_captcha_data, :key, :name => "idx_key"
end

def self.down
drop_table :simple_captcha_data
end
end
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150630015537) do
ActiveRecord::Schema.define(version: 20150721152640) do

create_table "gridconfigs", force: :cascade do |t|
t.integer "gridtype"
Expand Down Expand Up @@ -55,6 +55,15 @@
t.datetime "updated_at", null: false
end

create_table "simple_captcha_data", force: :cascade 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 "tasklogs", force: :cascade do |t|
t.integer "totalbar"
t.integer "currentbar"
Expand Down
Loading

0 comments on commit bccdaa3

Please sign in to comment.