mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 12:45:46 +08:00
FIX 完善重置密码功能
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
class BaseForm
|
||||
include ActiveModel::Model
|
||||
|
||||
Error = Class.new(StandardError)
|
||||
EmailError = Class.new(Error)
|
||||
LoginError = Class.new(Error)
|
||||
PhoneError = Class.new(Error)
|
||||
PasswordFormatError = Class.new(Error)
|
||||
VerifiCodeError = Class.new(Error)
|
||||
PasswordConfirmationError = Class.new(Error)
|
||||
|
||||
def check_project_category(project_category_id)
|
||||
unless project_category_id == ''
|
||||
raise "project_category_id参数值无效." if project_category_id && !ProjectCategory.exists?(project_category_id)
|
||||
@@ -26,8 +34,35 @@ class BaseForm
|
||||
raise "项目标识已被占用." if ReversedKeyword.check_exists?(repository_name)
|
||||
end
|
||||
|
||||
def check_password(password)
|
||||
password = strip(password)
|
||||
raise PasswordFormatError, "密码8~16位密码,支持字母数字和符号" unless password =~ CustomRegexp::PASSWORD
|
||||
end
|
||||
|
||||
def check_password_confirmation(password, password_confirmation)
|
||||
password = strip(password)
|
||||
password_confirmation = strip(password_confirmation)
|
||||
|
||||
raise PasswordFormatError, "确认密码为8~16位密码,支持字母数字和符号" unless password_confirmation =~ CustomRegexp::PASSWORD
|
||||
raise PasswordConfirmationError, "两次输入的密码不一致" unless password == password_confirmation
|
||||
end
|
||||
|
||||
def check_verifi_code(verifi_code, code)
|
||||
code = strip(code)
|
||||
# return if code == "123123" # TODO 万能验证码,用于测试
|
||||
|
||||
raise VerifiCodeError, "验证码不正确" if verifi_code&.code != code
|
||||
raise VerifiCodeError, "验证码已失效" if !verifi_code&.effective?
|
||||
end
|
||||
|
||||
private
|
||||
def strip(str)
|
||||
str.to_s.strip.presence
|
||||
end
|
||||
|
||||
# 1 手机类型;0 邮箱类型
|
||||
# 注意新版的login是自动名生成的
|
||||
def phone_mail_type value
|
||||
value =~ /^1\d{10}$/ ? 1 : 0
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user