|
|
@ -18,18 +18,22 @@ class Oauth::CreateOrFindWechatAccountService < ApplicationService
|
|
|
|
|
|
|
|
|
|
|
|
# 存在该用户
|
|
|
|
# 存在该用户
|
|
|
|
open_user = OpenUsers::Wechat.find_by(uid: result['unionid'])
|
|
|
|
open_user = OpenUsers::Wechat.find_by(uid: result['unionid'])
|
|
|
|
return [open_user.user, new_user] if open_user.present?
|
|
|
|
return [open_user.user, new_user] if open_user.present? && open_user.user.present?
|
|
|
|
|
|
|
|
|
|
|
|
if user.blank? || !user.logged?
|
|
|
|
if user.blank? || !user.logged?
|
|
|
|
new_user = true
|
|
|
|
new_user = true
|
|
|
|
# 新用户
|
|
|
|
# 新用户
|
|
|
|
login = User.generate_login('w')
|
|
|
|
# login = User.generate_login('w')
|
|
|
|
# result['nickname'] = regix_emoji(result['nickname'])
|
|
|
|
# result['nickname'] = regix_emoji(result['nickname'])
|
|
|
|
@user = User.new(login: login, type: 'User', status: User::STATUS_ACTIVE)
|
|
|
|
# @user = User.new(login: login, type: 'User', status: User::STATUS_ACTIVE)
|
|
|
|
# @user = User.new(login: login, nickname: result['nickname'], type: 'User', status: User::STATUS_ACTIVE)
|
|
|
|
# @user = User.new(login: login, nickname: result['nickname'], type: 'User', status: User::STATUS_ACTIVE)
|
|
|
|
|
|
|
|
set_session_openid(result['openid'])
|
|
|
|
|
|
|
|
set_session_unionid(result['unionid'])
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
OpenUsers::Wechat.create!(user: user, uid: result['unionid'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=begin
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
if new_user
|
|
|
|
if new_user
|
|
|
|
user.save!
|
|
|
|
user.save!
|
|
|
@ -46,6 +50,7 @@ class Oauth::CreateOrFindWechatAccountService < ApplicationService
|
|
|
|
|
|
|
|
|
|
|
|
Rails.cache.write(new_open_user.can_bind_cache_key, 1, expires_in: 1.hours) if new_user # 方便后面进行账号绑定
|
|
|
|
Rails.cache.write(new_open_user.can_bind_cache_key, 1, expires_in: 1.hours) if new_user # 方便后面进行账号绑定
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
|
|
|
|
[user, new_user]
|
|
|
|
[user, new_user]
|
|
|
|
rescue WechatOauth::Error => ex
|
|
|
|
rescue WechatOauth::Error => ex
|
|
|
|