绑定用户迁移到接口
This commit is contained in:
parent
7aec37bb3a
commit
a0c0a65d18
|
@ -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 "注册用户"
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in New Issue