mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-03 03:40:49 +08:00
init project
This commit is contained in:
9
app/forms/gitea/repository_form.rb
Normal file
9
app/forms/gitea/repository_form.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class Gitea::RepositoryForm
|
||||
include ActiveModel::Model
|
||||
attr_accessor :name, :description, :auto_init, :gitignores,
|
||||
:issue_labels, :license, :private, :readme
|
||||
|
||||
validates :name, presence: true
|
||||
# validates :name, uniqueness: true
|
||||
|
||||
end
|
||||
37
app/forms/gitea/user_form.rb
Normal file
37
app/forms/gitea/user_form.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
class Gitea::UserForm
|
||||
include ActiveModel::Model
|
||||
EMAIL_REGEX = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
|
||||
|
||||
include ActiveModel::Model
|
||||
attr_accessor :username, :email, :password
|
||||
|
||||
validates :username, presence: true
|
||||
validates :email, presence: true, format: { with: EMAIL_REGEX, multiline: true }
|
||||
validates :password, presence: true
|
||||
|
||||
validate :check_username, :check_email
|
||||
|
||||
attr_reader :record
|
||||
|
||||
def persist
|
||||
@record = id ? User.find(id) : User.new
|
||||
|
||||
if valid?
|
||||
@record.attributes = attributes.except(:password_confirmation, :id)
|
||||
@record.save!
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def check_username
|
||||
# errors.add(:login, :exist)
|
||||
raise "#{username} 已使用." if User.exists?(login: username.strip)
|
||||
end
|
||||
|
||||
def check_email
|
||||
raise "#{email} 已使用." if User.exists?(mail: email.strip)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user