Browse Source

Merge branch 'standalone_develop' into pre_trustie_server

pull/306/head
yystopf 4 years ago
parent
commit
d4d00b30bf
4 changed files with 44 additions and 7 deletions
  1. +6
    -1
      app/controllers/accounts_controller.rb
  2. +18
    -6
      app/forms/register/base_form.rb
  3. +19
    -0
      app/forms/register/login_check_columns_form.rb
  4. +1
    -0
      config/routes.rb

+ 6
- 1
app/controllers/accounts_controller.rb View File

@@ -1,5 +1,5 @@
class AccountsController < ApplicationController
before_action :require_login, only: [:simple_update]
before_action :require_login, only: [:login_check, :simple_update]
include ApplicationHelper

#skip_before_action :check_account, :only => [:logout]
@@ -334,6 +334,11 @@ class AccountsController < ApplicationController
Register::CheckColumnsForm.new(check_params).validate!
render_ok
end

def login_check
Register::LoginCheckColumnsForm.new(check_params.merge(user: current_user)).validate!
render_ok
end
private



+ 18
- 6
app/forms/register/base_form.rb View File

@@ -3,28 +3,40 @@ module Register
include ActiveModel::Model
private
def check_login(login)
def check_login(login, user=nil)
login = strip(login)
raise LoginError, "登录名格式有误" unless login =~ CustomRegexp::LOGIN

login_exist = Owner.exists?(login: login) || ReversedKeyword.check_exists?(login)
raise LoginError, '登录名已被使用' if login_exist
if user.present?
raise LoginError, '登录名已被使用' if login_exist && login != user&.login
else
raise LoginError, '登录名已被使用' if login_exist
end
end

def check_mail(mail)
def check_mail(mail, user=nil)
mail = strip(mail)
raise EmailError, "邮件格式有误" unless mail =~ CustomRegexp::EMAIL
mail_exist = Owner.exists?(mail: mail)
raise EmailError, '邮箱已被使用' if mail_exist
if user.present?
raise EmailError, '邮箱已被使用' if mail_exist && mail != user&.mail
else
raise EmailError, '邮箱已被使用' if mail_exist
end
end
def check_phone(phone)
def check_phone(phone, user=nil)
phone = strip(phone)
raise PhoneError, "手机号格式有误" unless phone =~ CustomRegexp::PHONE

phone_exist = Owner.exists?(phone: phone)
raise PhoneError, '手机号已被使用' if phone_exist
if user.present?
raise PhoneError, '手机号已被使用' if phone_exist && phone != user&.phone
else
raise PhoneError, '手机号已被使用' if phone_exist
end
end
end
end

+ 19
- 0
app/forms/register/login_check_columns_form.rb View File

@@ -0,0 +1,19 @@
module Register
class LoginCheckColumnsForm < Register::BaseForm
attr_accessor :type, :value, :user

validates :type, presence: true, numericality: true
validates :value, presence: true
validate :check!
def check!
# params[:type] 为事件类型 1:登录名(login) 2:email(邮箱) 3:phone(手机号)
case strip(type).to_i
when 1 then check_login(strip(value), user)
when 2 then check_mail(strip(value), user)
when 3 then check_phone(strip(value), user)
else raise("type值无效")
end
end
end
end

+ 1
- 0
config/routes.rb View File

@@ -214,6 +214,7 @@ Rails.application.routes.draw do
post :remote_password
post :change_password
post :check
post :login_check
post :simple_update
end
end


Loading…
Cancel
Save