Update local register method

This commit is contained in:
Jasder 2020-11-24 11:22:32 +08:00
parent 69f2fd2fbb
commit 8f9e12a5e0
1 changed files with 15 additions and 17 deletions

View File

@ -110,6 +110,7 @@ class AccountsController < ApplicationController
# params[:login] 邮箱或者手机号
# params[:code] 验证码
# code_type 1注册手机验证码 8邮箱注册验证码
# 本地forge注册入口
def register
begin
# 查询验证码是否正确;type只可能是1或者8
@ -145,23 +146,20 @@ class AccountsController < ApplicationController
# 现在因为是验证码,所以在注册的时候就可以激活
@user.activate
# 必须要用save操作密码的保存是在users中
if @user.save!
# todo user_extension
UserExtension.create!(user_id: @user.id)
# 注册完成手机号或邮箱想可以奖励500金币
# RewardGradeService.call(
# @user,
# container_id: @user.id,
# container_type: pre == 'p' ? 'Phone' : 'Mail',
# score: 500
# )
# 注册时,记录是否是引流用户
ip = request.remote_ip
ua = UserAgent.find_by_ip(ip)
ua.update_column(:agent_type, UserAgent::USER_REGISTER) if ua
successful_authentication(@user)
# session[:user_id] = @user.id
normal_status("注册成功")
interactor = Gitea::RegisterInteractor.call({username: login, email: email, password: params[:password]})
if interactor.success?
gitea_user = interactor.result
result = Gitea::User::GenerateTokenService.new(username, params[:password]).call
@user.gitea_token = result['sha1']
@user.gitea_uid = gitea_user['id']
if user.save!
UserExtension.create!(user_id: user.id)
successful_authentication(@user)
normal_status("注册成功")
end
else
tip_exception(-1, interactor.error)
end
rescue Exception => e
uid_logger_error(e.message)