init project

This commit is contained in:
Jasder
2020-03-09 00:40:16 +08:00
commit 2937b2a94d
6549 changed files with 7215173 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
class Users::ApplyAuthenticationForm
include ActiveModel::Model
attr_accessor :name, :show_realname, :id_number, :gender, :upload_image, :attachment_ids
validates :name, presence: true, length: { minimum: 2, maximum: 10 }, format: { with: CustomRegexp::LASTNAME, message: "2-10位中英文、数字" }
validate :validate_ID_number
validate :validate_attachment_ids
def validate_ID_number
unless id_number =~ User::VALID_NUMBER_REGEX
raise("身份证格式不对")
end
end
def validate_attachment_ids
unless attachment_ids.is_a?(Array) || attachment_ids.length != 1
raise("图片参数不对")
end
end
end

View File

@@ -0,0 +1,17 @@
class Users::ApplyProfessionalAuthForm
include ActiveModel::Model
attr_accessor :school_id, :department_id, :identity, :extra, :upload_image, :attachment_ids
validates :school_id, presence: true, numericality: { only_integer: true, greater_than: 0 }
validates :department_id, numericality: { only_integer: true, greater_than: 0 }, allow_blank: true
validates :identity, presence: true, inclusion: { in: %w(student teacher professional) }
validates :extra, presence: true
validate :validate_attachment_ids
def validate_attachment_ids
unless attachment_ids.is_a?(Array) || attachment_ids.length != 1
raise("图片参数不对")
end
end
end

View File

@@ -0,0 +1,16 @@
class Users::ApplyTrailForm
include ActiveModel::Model
attr_accessor :user, :phone, :code, :reason
validates :reason, presence: true
validates :phone, presence: true, format: { with: CustomRegexp::PHONE }, unless: -> { user.phone_binded? }
validates :code, presence: true, unless: -> { user.phone_binded? }
validate :check_user_certification
def check_user_certification
return if user.certification != 1
errors.add(:user, :already_trial)
end
end

View File

@@ -0,0 +1,8 @@
class Users::BindEmailForm
include ActiveModel::Model
attr_accessor :email, :code
validates :email, presence: true#, format: { with: CustomRegexp::EMAIL }
validates :code, presence: true
end

View File

@@ -0,0 +1,8 @@
class Users::BindPhoneForm
include ActiveModel::Model
attr_accessor :phone, :code
validates :phone, presence: true, format: { with: CustomRegexp::PHONE }
validates :code, presence: true
end

View File

@@ -0,0 +1,33 @@
class Users::UpdateAccountForm
include ActiveModel::Model
attr_accessor :user
attr_accessor :nickname, :name, :show_realname, :gender, :location, :location_city,
:identity, :student_id, :technical_title, :school_id, :department_id
validates :nickname, presence: true, length: { minimum: 2, maximum: 20 }, format: { with: CustomRegexp::NICKNAME, message: "2-20位中英文、数字及下划线" }
validates :name, presence: true, length: { minimum: 2, maximum: 10 }, format: { with: CustomRegexp::LASTNAME, message: "2-10位中英文、数字" }
validates :gender, presence: true, numericality: { only_integer: true }, inclusion: { in: [0, 1] }
validates :location, presence: true
validates :location_city, presence: true
validates :identity, presence: true, inclusion: { in: %w[teacher student professional ] }
validates :technical_title, presence: true, unless: -> { identity.to_s == 'student' }
validates :student_id, presence: true, if: -> { identity.to_s == 'student' }
validates :school_id, presence: true
validate :check_school_exist
def check_school_exist
return if school_id.blank?
unless School.exists?(id: school_id)
errors.add(:school_id, :not_exist)
end
end
validate :check_department_exist
def check_department_exist
return if department_id.blank?
unless Department.exists?(id: department_id)
errors.add(:department_id, :not_exist)
end
end
end

View File

@@ -0,0 +1,7 @@
class Users::UpdatePasswordForm
include ActiveModel::Model
attr_accessor :password, :old_password
validates :password, presence: true, length: { minimum: 8, maximum: 16 }, format: { with: CustomRegexp::PASSWORD, message: "8~16位密码支持字母数字和符号" }
end