|
|
|
@ -34,8 +34,8 @@ class AccountsController < ApplicationController
|
|
|
|
|
# check_code = (verifi_code.try(:code) == code.strip && (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60)
|
|
|
|
|
# todo 上线前请删除万能验证码"513231"
|
|
|
|
|
if code != "513231"
|
|
|
|
|
tip_exception(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
|
|
|
|
|
tip_exception(-2, "验证码已失效") if (Time.now.to_i - verifi_code.created_at.to_i) > 10*60
|
|
|
|
|
return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
|
|
|
|
|
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
code = generate_identifier User, 8
|
|
|
|
@ -55,6 +55,10 @@ class AccountsController < ApplicationController
|
|
|
|
|
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("注册成功")
|
|
|
|
@ -68,6 +72,15 @@ class AccountsController < ApplicationController
|
|
|
|
|
# 用户登录
|
|
|
|
|
def login
|
|
|
|
|
@user = User.try_to_login(params[:login], params[:password])
|
|
|
|
|
|
|
|
|
|
if @user
|
|
|
|
|
# user is already in local database
|
|
|
|
|
return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked?
|
|
|
|
|
return normal_status(-2, "错误的账号或密码") unless @user.check_password?(params[:password].to_s)
|
|
|
|
|
else
|
|
|
|
|
return normal_status(-2, "错误的账号或密码")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@user.update_column(:last_login_on, Time.now)
|
|
|
|
|
|
|
|
|
|
successful_authentication(@user)
|
|
|
|
@ -90,8 +103,8 @@ class AccountsController < ApplicationController
|
|
|
|
|
verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last
|
|
|
|
|
user = User.find_by_mail(email) #这里有问题,应该是为email,而不是mail 6.13-hs
|
|
|
|
|
end
|
|
|
|
|
tip_exception(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
|
|
|
|
|
tip_exception(-2, "验证码已失效") if (Time.now.to_i - verifi_code.created_at.to_i) > 10*60
|
|
|
|
|
return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
|
|
|
|
|
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
|
|
|
|
|
|
|
|
|
|
user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
|
|
|
|
if user.save!
|
|
|
|
@ -110,7 +123,7 @@ class AccountsController < ApplicationController
|
|
|
|
|
# generate a key and set cookie if autologin
|
|
|
|
|
|
|
|
|
|
set_autologin_cookie(user)
|
|
|
|
|
UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id))
|
|
|
|
|
UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id), :ip => request.remote_ip)
|
|
|
|
|
|
|
|
|
|
# 注册完成后有一天的试用申请
|
|
|
|
|
UserDayCertification.create(user_id: user.id, status: 1)
|
|
|
|
@ -133,7 +146,7 @@ class AccountsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def logout
|
|
|
|
|
UserAction.create(action_id: User.current.id, action_type: "Logout", user_id: User.current.id)
|
|
|
|
|
UserAction.create(action_id: User.current.id, action_type: "Logout", user_id: User.current.id, :ip => request.remote_ip)
|
|
|
|
|
session[:user_id] = nil
|
|
|
|
|
logout_user
|
|
|
|
|
render :json => {status: 1, message: "退出成功!"}
|
|
|
|
|