|
|
@ -8,15 +8,13 @@ module Mobile
|
|
|
|
desc "绑定微信用户"
|
|
|
|
desc "绑定微信用户"
|
|
|
|
params do
|
|
|
|
params do
|
|
|
|
requires :login, type: String, desc: 'username'
|
|
|
|
requires :login, type: String, desc: 'username'
|
|
|
|
requires :mail, type: String, desc: 'mail'
|
|
|
|
|
|
|
|
requires :password, type: String, desc: 'password'
|
|
|
|
requires :password, type: String, desc: 'password'
|
|
|
|
|
|
|
|
requires :openid, type: String, desc: 'wechat openid'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
post 'wxbind' do
|
|
|
|
post 'wxbind' do
|
|
|
|
code = params[:code] || session[:wechat_code]
|
|
|
|
openid = params[:openid]
|
|
|
|
openid = get_openid_from_code(code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
raise "无法获取到openid,请在微信中打开本页面" unless openid
|
|
|
|
raise "无法获取到openid,请在微信中打开本页面" unless openid
|
|
|
|
raise "此微信号已绑定用户, 不能重复绑定" if user_binded?(openid)
|
|
|
|
raise "此微信号已绑定用户, 不能重复绑定" if UserWechat.where(openid: openid).first
|
|
|
|
|
|
|
|
|
|
|
|
user, last_login_on = User.try_to_login(params[:username], params[:password])
|
|
|
|
user, last_login_on = User.try_to_login(params[:username], params[:password])
|
|
|
|
raise "用户名或密码错误,请重新输入" unless user
|
|
|
|
raise "用户名或密码错误,请重新输入" unless user
|
|
|
|