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 %> +
+