From a0c0a65d18d4c62b4e4139bb5802ba6d14fe32ad Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Fri, 17 Jun 2016 18:37:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=91=E5=AE=9A=E7=94=A8=E6=88=B7=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E5=88=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/users.rb | 21 ++++++++++++++++++- .../javascripts/wechat/controllers/login.js | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 7800382ad..ab2ba49b4 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -12,7 +12,26 @@ module Mobile requires :password, type: String, desc: 'password' end post '/bindwx' do - + code = params[:code] || session[:wechat_code] + openid = get_openid_from_code(code) + + raise "无法获取到openid,请在微信中打开本页面" unless openid + raise "此微信号已绑定用户, 不能重复绑定" if user_binded?(openid) + + user, last_login_on = User.try_to_login(params[:username], params[:password]) + raise "用户名或密码错误,请重新输入" unless user + #补全用户信息 + + raise "此用户已经绑定过公众号, 请换一个帐户试试" if user.user_wechat + + UserWechat.create!( + openid: openid, + user: user + ) + ws = WechatService.new + ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now)) + present status: 0 + present message: '绑定成功' end desc "注册用户" diff --git a/public/javascripts/wechat/controllers/login.js b/public/javascripts/wechat/controllers/login.js index 011f11baa..e8efad177 100644 --- a/public/javascripts/wechat/controllers/login.js +++ b/public/javascripts/wechat/controllers/login.js @@ -22,7 +22,7 @@ app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams console.log(apiUrl + "auth"); auth.getOpenId().then( - function(){ + function(openid){ return $http.post( config.rootUrl + "wxbind", {login: user.login, password: user.password, openid: openid}