绑定认证接口 bind

This commit is contained in:
guange 2016-01-19 14:28:13 +08:00
parent 96d0b2e717
commit 8e66ab6a41
2 changed files with 45 additions and 4 deletions

View File

@ -1,8 +1,6 @@
class WechatsController < ActionController::Base
wechat_responder
# default text responder when no other match
on :text do |request, content|
request.reply.text "echo: #{content}" # Just echo
@ -134,11 +132,22 @@ class WechatsController < ActionController::Base
end
def bind
begin
raise "非法操作, 微信ID不存在" unless params[:openid]
user, last_login_on = User.try_to_login(params[:username], params[:password])
raise "用户名或密码错误,请重新登录" unless user
#补全用户信息
puts wechat.user(request[:openid])
user.user_wechat = UserWechat.new(openid: params[:openid])
user.save!
rescue Exception=>e
@wechat_bind_errors = e.message
render :login
end
end
def login
@openid = request[:FromUserName] #TODO 安全性
end
private

View File

@ -0,0 +1,32 @@
<div class="loginIn">
<div>
<p class="wechat-error">
<%= @wechat_bind_errors %>
</p>
</div>
<%= form_tag(bind_wechat_path,:id=>'main_login_form',:method=>'post') do %>
<div class="mb20">
<%= text_field_tag 'username', params[:username], :tabindex => '1' ,
:class=>'loginSignBox',:placeholder=>'请输入邮箱地址或昵称', :onkeypress => "user_name_keypress(event);"%>
<!--<input type="text" placeholder="请输入邮箱地址或昵称" class="loginSignBox" />-->
</div>
<% if Setting.openid? %>
<div class="mb20">
<%= text_field_tag "openid_url", nil, :tabindex => '3',:placeholder=>'请输入OpenId URL' %>
</div>
<% end %>
<div>
<!--<input type="text" placeholder="请输密码" class="loginSignBox" />-->
<%= password_field_tag 'password', nil, :tabindex => '2',:class=>'loginSignBox' ,:placeholder=>'请输密码', :onkeypress => "user_name_keypress(event);"%>
</div>
<input type="hidden" value="<%=@openid%>" name="openid">
<div class="loginInButton" >
<%= submit_tag '绑定' %>
</div>
<% end %>
</div>