|
|
|
@ -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 "注册用户"
|
|
|
|
|