add: project update valid and user login valid
This commit is contained in:
parent
d867823f01
commit
411c10e8f3
|
@ -169,6 +169,7 @@ class AccountsController < ApplicationController
|
|||
|
||||
# 用户登录
|
||||
def login
|
||||
Users::LoginForm.new(account_params).validate!
|
||||
@user = User.try_to_login(params[:login], params[:password])
|
||||
|
||||
return normal_status(-2, "错误的账号或密码") if @user.blank?
|
||||
|
@ -345,4 +346,7 @@ class AccountsController < ApplicationController
|
|||
params.require(:user).permit(:login, :email, :phone)
|
||||
end
|
||||
|
||||
def account_params
|
||||
params.require(:account).permit(:login, :password)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -106,7 +106,7 @@ class ProjectsController < ApplicationController
|
|||
|
||||
def update
|
||||
ActiveRecord::Base.transaction do
|
||||
# Projects::CreateForm.new(project_params).validate!
|
||||
Projects::UpdateForm.new(project_params).validate!
|
||||
private = params[:private] || false
|
||||
|
||||
new_project_params = project_params.except(:private).merge(is_public: !private)
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
class Projects::UpdateForm < BaseForm
|
||||
attr_reader :name, :description, :repository_name, :project_category_id
|
||||
attr_accessor :name, :description, :project_category_id, :project_language_id, :private
|
||||
validates :name, :description, :project_category_id, :project_language_id, presence: true
|
||||
validates :name, length: { maximum: 50 }
|
||||
validates :description, length: { maximum: 200 }
|
||||
validate do
|
||||
check_project_category(project_category_id)
|
||||
check_project_language(project_language_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
class Users::LoginForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :password, :login
|
||||
|
||||
validates :login, presence: true
|
||||
validates :password, presence: true, length: { minimum: 8, maximum: 16 }, format: { with: CustomRegexp::PASSWORD, message: "8~16位,支持字母数字和符号" }
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
'zh-CN':
|
||||
activemodel:
|
||||
attributes:
|
||||
projects/update_form:
|
||||
name: 项目名称
|
||||
description: 项目简介
|
||||
project_category_id: 项目类别
|
||||
project_language_id: 项目语言
|
|
@ -0,0 +1,6 @@
|
|||
'zh-CN':
|
||||
activemodel:
|
||||
attributes:
|
||||
users/login_form:
|
||||
login: 用户名
|
||||
password: 密码
|
Loading…
Reference in New Issue