diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 24de889a8..40c7d5ff5 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -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 diff --git a/app/views/wechats/login.html.erb b/app/views/wechats/login.html.erb new file mode 100644 index 000000000..44fc1da32 --- /dev/null +++ b/app/views/wechats/login.html.erb @@ -0,0 +1,32 @@ +
+
+

+ <%= @wechat_bind_errors %> +

+
+ <%= form_tag(bind_wechat_path,:id=>'main_login_form',:method=>'post') do %> + +
+ <%= text_field_tag 'username', params[:username], :tabindex => '1' , + :class=>'loginSignBox',:placeholder=>'请输入邮箱地址或昵称', :onkeypress => "user_name_keypress(event);"%> + +
+ <% if Setting.openid? %> +
+ <%= text_field_tag "openid_url", nil, :tabindex => '3',:placeholder=>'请输入OpenId URL' %> +
+ <% end %> +
+ + <%= password_field_tag 'password', nil, :tabindex => '2',:class=>'loginSignBox' ,:placeholder=>'请输密码', :onkeypress => "user_name_keypress(event);"%> +
+ + + +
+ <%= submit_tag '绑定' %> +
+ + <% end %> + +
\ No newline at end of file