2020-03-09 00:40:16 +08:00
|
|
|
|
class BaseForm
|
|
|
|
|
|
include ActiveModel::Model
|
|
|
|
|
|
|
|
|
|
|
|
def check_project_category(project_category_id)
|
2021-09-17 10:02:42 +08:00
|
|
|
|
unless project_category_id == ''
|
|
|
|
|
|
raise "project_category_id参数值无效." if project_category_id && !ProjectCategory.exists?(project_category_id)
|
|
|
|
|
|
end
|
2020-03-09 00:40:16 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def check_project_language(project_language_id)
|
2021-09-17 10:02:42 +08:00
|
|
|
|
unless project_language_id == ''
|
|
|
|
|
|
raise "project_language_id参数值无效." if project_language_id && !ProjectLanguage.exists?(project_language_id)
|
|
|
|
|
|
end
|
2020-03-09 00:40:16 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def check_repository_name(user_id, repository_name)
|
2021-09-09 13:50:31 +08:00
|
|
|
|
check_reversed_keyword(repository_name)
|
2021-09-10 15:35:57 +08:00
|
|
|
|
raise "项目标识已被使用." if Repository.where(user_id: user_id, identifier: repository_name.strip).exists?
|
2020-03-09 00:40:16 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def check_project_name(user_id, project_name)
|
|
|
|
|
|
raise "项目名称已被使用." if Project.where(user_id: user_id, name: project_name.strip).exists?
|
|
|
|
|
|
end
|
2021-09-09 13:50:31 +08:00
|
|
|
|
|
|
|
|
|
|
def check_reversed_keyword(repository_name)
|
2021-10-27 17:19:39 +08:00
|
|
|
|
raise "项目标识已被占用." if ReversedKeyword.check_exists?(repository_name)
|
2021-09-09 13:50:31 +08:00
|
|
|
|
end
|
2021-11-02 13:39:45 +08:00
|
|
|
|
|
2021-11-24 18:13:15 +08:00
|
|
|
|
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&.effective?
|
|
|
|
|
|
raise VerifiCodeError, "验证码不正确" if verifi_code&.code != code
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2021-11-02 13:39:45 +08:00
|
|
|
|
private
|
|
|
|
|
|
def strip(str)
|
|
|
|
|
|
str.to_s.strip.presence
|
|
|
|
|
|
end
|
2022-01-21 15:50:37 +08:00
|
|
|
|
|
|
|
|
|
|
# 1 手机类型;0 邮箱类型
|
|
|
|
|
|
# 注意新版的login是自动名生成的
|
|
|
|
|
|
def phone_mail_type value
|
|
|
|
|
|
value =~ /^1\d{10}$/ ? 1 : 0
|
|
|
|
|
|
end
|
2020-03-09 00:40:16 +08:00
|
|
|
|
end
|