init
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type AdminCreate struct {
|
||||
Username string `form:"username" json:"username"`
|
||||
Password string `form:"password" json:"password"`
|
||||
Nickname string `form:"nickname" json:"nickname"`
|
||||
Email string `form:"email" json:"email"`
|
||||
Phone string `form:"phone" json:"phone"`
|
||||
DepartmentID uint `form:"department_id" json:"department_id"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
RoleIDs []uint `form:"role_ids" json:"role_ids"`
|
||||
}
|
||||
|
||||
func (r *AdminCreate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *AdminCreate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"username": "required|min_len:3|max_len:50",
|
||||
"password": "required|min_len:6|max_len:50",
|
||||
"nickname": "max_len:50",
|
||||
"email": "email|max_len:100",
|
||||
"phone": "max_len:20",
|
||||
"status": "in:0,1",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *AdminCreate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"username.required": trans.Get(ctx, "validation_username_required"),
|
||||
"username.min_len": trans.Get(ctx, "validation_username_min"),
|
||||
"username.max_len": trans.Get(ctx, "validation_username_max"),
|
||||
"password.required": trans.Get(ctx, "validation_password_required"),
|
||||
"password.min_len": trans.Get(ctx, "validation_password_min"),
|
||||
"password.max_len": trans.Get(ctx, "validation_password_max"),
|
||||
"nickname.max_len": trans.Get(ctx, "validation_nickname_max"),
|
||||
"email.email": trans.Get(ctx, "validation_email_format"),
|
||||
"email.max_len": trans.Get(ctx, "validation_email_max"),
|
||||
"phone.max_len": trans.Get(ctx, "validation_phone_max"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *AdminCreate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"username": trans.Get(ctx, "validation_username"),
|
||||
"password": trans.Get(ctx, "validation_password"),
|
||||
"nickname": trans.Get(ctx, "validation_nickname"),
|
||||
"email": trans.Get(ctx, "validation_email"),
|
||||
"phone": trans.Get(ctx, "validation_phone"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *AdminCreate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
// 将 status 字段转换为字符串,以便 in 规则能正确验证
|
||||
return helpers.PrepareNumericFieldForValidation(data, "status")
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type AdminUpdate struct {
|
||||
Nickname string `form:"nickname" json:"nickname"`
|
||||
Email string `form:"email" json:"email"`
|
||||
Phone string `form:"phone" json:"phone"`
|
||||
Password string `form:"password" json:"password"`
|
||||
DepartmentID uint `form:"department_id" json:"department_id"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
RoleIDs []uint `form:"role_ids" json:"role_ids"`
|
||||
}
|
||||
|
||||
func (r *AdminUpdate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *AdminUpdate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"nickname": "max_len:50",
|
||||
"email": "email|max_len:100",
|
||||
"phone": "max_len:20",
|
||||
"password": "min_len:6|max_len:50",
|
||||
"status": "in:0,1",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *AdminUpdate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"nickname.max_len": trans.Get(ctx, "validation_nickname_max"),
|
||||
"email.email": trans.Get(ctx, "validation_email_format"),
|
||||
"email.max_len": trans.Get(ctx, "validation_email_max"),
|
||||
"phone.max_len": trans.Get(ctx, "validation_phone_max"),
|
||||
"password.min_len": trans.Get(ctx, "validation_password_min"),
|
||||
"password.max_len": trans.Get(ctx, "validation_password_max"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *AdminUpdate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"nickname": trans.Get(ctx, "validation_nickname"),
|
||||
"email": trans.Get(ctx, "validation_email"),
|
||||
"phone": trans.Get(ctx, "validation_phone"),
|
||||
"password": trans.Get(ctx, "validation_password"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *AdminUpdate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
// 将 status 字段转换为字符串,以便 in 规则能正确验证
|
||||
return helpers.PrepareNumericFieldForValidation(data, "status")
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
)
|
||||
|
||||
type ArticleCreate struct {
|
||||
Name string `form:"name" json:"name"`
|
||||
Status string `form:"status" json:"status"`
|
||||
}
|
||||
|
||||
func (r *ArticleCreate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ArticleCreate) Rules(ctx http.Context) map[string]string {
|
||||
rules := map[string]string{
|
||||
|
||||
"name": "required",
|
||||
"status": "",
|
||||
}
|
||||
return rules
|
||||
}
|
||||
|
||||
func (r *ArticleCreate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
|
||||
"name.required": trans.Get(ctx, "validation_name_required"),
|
||||
"status.required": trans.Get(ctx, "validation_status_required"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ArticleCreate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
|
||||
"name": trans.Get(ctx, "validation_name"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
)
|
||||
|
||||
type ArticleUpdate struct {
|
||||
Name *string `form:"name" json:"name"`
|
||||
Status *string `form:"status" json:"status"`
|
||||
}
|
||||
|
||||
func (r *ArticleUpdate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ArticleUpdate) Rules(ctx http.Context) map[string]string {
|
||||
rules := map[string]string{
|
||||
|
||||
"name": "required",
|
||||
"status": "",
|
||||
}
|
||||
return rules
|
||||
}
|
||||
|
||||
func (r *ArticleUpdate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
|
||||
"name.required": trans.Get(ctx, "validation_name_required"),
|
||||
"status.required": trans.Get(ctx, "validation_status_required"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ArticleUpdate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
|
||||
"name": trans.Get(ctx, "validation_name"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type BlacklistCreate struct {
|
||||
IP string `form:"ip" json:"ip"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
}
|
||||
|
||||
func (r *BlacklistCreate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *BlacklistCreate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"ip": "required",
|
||||
"status": "in:0,1",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *BlacklistCreate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"ip.required": trans.Get(ctx, "ip_address_required"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *BlacklistCreate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"ip": trans.Get(ctx, "validation_ip"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *BlacklistCreate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
return helpers.PrepareNumericFieldForValidation(data, "status")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type BlacklistUpdate struct {
|
||||
IP string `form:"ip" json:"ip"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
}
|
||||
|
||||
func (r *BlacklistUpdate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *BlacklistUpdate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"status": "in:0,1",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *BlacklistUpdate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *BlacklistUpdate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *BlacklistUpdate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
return helpers.PrepareNumericFieldForValidation(data, "status")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type DepartmentCreate struct {
|
||||
ParentID uint `form:"parent_id" json:"parent_id"`
|
||||
Name string `form:"name" json:"name"`
|
||||
Code string `form:"code" json:"code"`
|
||||
Leader string `form:"leader" json:"leader"`
|
||||
Phone string `form:"phone" json:"phone"`
|
||||
Email string `form:"email" json:"email"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
Sort int `form:"sort" json:"sort"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
}
|
||||
|
||||
func (r *DepartmentCreate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *DepartmentCreate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name": "required|max_len:50",
|
||||
"code": "max_len:50",
|
||||
"leader": "max_len:50",
|
||||
"phone": "max_len:20",
|
||||
"email": "email|max_len:100",
|
||||
"status": "in:0,1",
|
||||
"remark": "max_len:500",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DepartmentCreate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name.required": trans.Get(ctx, "department_name_required"),
|
||||
"name.max_len": trans.Get(ctx, "validation_name_max"),
|
||||
"code.max_len": trans.Get(ctx, "validation_code_max"),
|
||||
"leader.max_len": trans.Get(ctx, "validation_leader_max"),
|
||||
"phone.max_len": trans.Get(ctx, "validation_phone_max"),
|
||||
"email.email": trans.Get(ctx, "validation_email_format"),
|
||||
"email.max_len": trans.Get(ctx, "validation_email_max"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
"remark.max_len": trans.Get(ctx, "validation_remark_max"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DepartmentCreate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name": trans.Get(ctx, "validation_name"),
|
||||
"code": trans.Get(ctx, "validation_code"),
|
||||
"leader": trans.Get(ctx, "validation_leader"),
|
||||
"phone": trans.Get(ctx, "validation_phone"),
|
||||
"email": trans.Get(ctx, "validation_email"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
"remark": trans.Get(ctx, "validation_remark"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DepartmentCreate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
return helpers.PrepareNumericFieldForValidation(data, "status")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type DepartmentUpdate struct {
|
||||
ParentID uint `form:"parent_id" json:"parent_id"`
|
||||
Name string `form:"name" json:"name"`
|
||||
Code string `form:"code" json:"code"`
|
||||
Leader string `form:"leader" json:"leader"`
|
||||
Phone string `form:"phone" json:"phone"`
|
||||
Email string `form:"email" json:"email"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
Sort int `form:"sort" json:"sort"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
}
|
||||
|
||||
func (r *DepartmentUpdate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *DepartmentUpdate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name": "max_len:50",
|
||||
"code": "max_len:50",
|
||||
"leader": "max_len:50",
|
||||
"phone": "max_len:20",
|
||||
"email": "email|max_len:100",
|
||||
"status": "in:0,1",
|
||||
"remark": "max_len:500",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DepartmentUpdate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name.max_len": trans.Get(ctx, "validation_name_max"),
|
||||
"code.max_len": trans.Get(ctx, "validation_code_max"),
|
||||
"leader.max_len": trans.Get(ctx, "validation_leader_max"),
|
||||
"phone.max_len": trans.Get(ctx, "validation_phone_max"),
|
||||
"email.email": trans.Get(ctx, "validation_email_format"),
|
||||
"email.max_len": trans.Get(ctx, "validation_email_max"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
"remark.max_len": trans.Get(ctx, "validation_remark_max"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DepartmentUpdate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name": trans.Get(ctx, "validation_name"),
|
||||
"code": trans.Get(ctx, "validation_code"),
|
||||
"leader": trans.Get(ctx, "validation_leader"),
|
||||
"phone": trans.Get(ctx, "validation_phone"),
|
||||
"email": trans.Get(ctx, "validation_email"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
"remark": trans.Get(ctx, "validation_remark"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DepartmentUpdate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
return helpers.PrepareNumericFieldForValidation(data, "status")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type DictionaryCreate struct {
|
||||
Type string `form:"type" json:"type"`
|
||||
Label string `form:"label" json:"label"`
|
||||
Value string `form:"value" json:"value"`
|
||||
TranslationKey string `form:"translation_key" json:"translation_key"`
|
||||
Description string `form:"description" json:"description"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
Sort int `form:"sort" json:"sort"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
}
|
||||
|
||||
func (r *DictionaryCreate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *DictionaryCreate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"type": "required|max_len:50",
|
||||
"label": "required|max_len:50",
|
||||
"value": "required|max_len:100",
|
||||
"translation_key": "max_len:255",
|
||||
"description": "max_len:255",
|
||||
"status": "in:0,1",
|
||||
"remark": "max_len:500",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DictionaryCreate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"type.required": trans.Get(ctx, "dictionary_type_required"),
|
||||
"type.max_len": trans.Get(ctx, "validation_type_max"),
|
||||
"label.required": trans.Get(ctx, "validation_label_required"),
|
||||
"label.max_len": trans.Get(ctx, "validation_label_max"),
|
||||
"value.required": trans.Get(ctx, "validation_value_required"),
|
||||
"value.max_len": trans.Get(ctx, "validation_value_max"),
|
||||
"translation_key.max_len": trans.Get(ctx, "validation_translation_key_max"),
|
||||
"description.max_len": trans.Get(ctx, "validation_description_max"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
"remark.max_len": trans.Get(ctx, "validation_remark_max"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DictionaryCreate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"type": trans.Get(ctx, "validation_type"),
|
||||
"label": trans.Get(ctx, "validation_label"),
|
||||
"value": trans.Get(ctx, "validation_value"),
|
||||
"translation_key": trans.Get(ctx, "validation_translation_key"),
|
||||
"description": trans.Get(ctx, "validation_description"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
"remark": trans.Get(ctx, "validation_remark"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DictionaryCreate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
return helpers.PrepareNumericFieldForValidation(data, "status")
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type DictionaryUpdate struct {
|
||||
Type string `form:"type" json:"type"`
|
||||
Label string `form:"label" json:"label"`
|
||||
Value string `form:"value" json:"value"`
|
||||
TranslationKey string `form:"translation_key" json:"translation_key"`
|
||||
Description string `form:"description" json:"description"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
Sort int `form:"sort" json:"sort"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
}
|
||||
|
||||
func (r *DictionaryUpdate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *DictionaryUpdate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"type": "max_len:50",
|
||||
"label": "max_len:50",
|
||||
"value": "max_len:100",
|
||||
"translation_key": "max_len:255",
|
||||
"description": "max_len:255",
|
||||
"status": "in:0,1",
|
||||
"remark": "max_len:500",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DictionaryUpdate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"type.max_len": trans.Get(ctx, "validation_type_max"),
|
||||
"label.max_len": trans.Get(ctx, "validation_label_max"),
|
||||
"value.max_len": trans.Get(ctx, "validation_value_max"),
|
||||
"translation_key.max_len": trans.Get(ctx, "validation_translation_key_max"),
|
||||
"description.max_len": trans.Get(ctx, "validation_description_max"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
"remark.max_len": trans.Get(ctx, "validation_remark_max"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DictionaryUpdate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"type": trans.Get(ctx, "validation_type"),
|
||||
"label": trans.Get(ctx, "validation_label"),
|
||||
"value": trans.Get(ctx, "validation_value"),
|
||||
"translation_key": trans.Get(ctx, "validation_translation_key"),
|
||||
"description": trans.Get(ctx, "validation_description"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
"remark": trans.Get(ctx, "validation_remark"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DictionaryUpdate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
return helpers.PrepareNumericFieldForValidation(data, "status")
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
)
|
||||
|
||||
type Login struct {
|
||||
Username string `form:"username" json:"username"`
|
||||
Password string `form:"password" json:"password"`
|
||||
CaptchaID string `form:"captcha_id" json:"captcha_id"`
|
||||
CaptchaAnswer string `form:"captcha_answer" json:"captcha_answer"`
|
||||
GoogleCode string `form:"google_code" json:"google_code"` // 谷歌验证码
|
||||
}
|
||||
|
||||
func (r *Login) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Login) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"username": "required",
|
||||
"password": "required|min_len:6",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Login) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"username.required": trans.Get(ctx, "validation_username_required"),
|
||||
"password.required": trans.Get(ctx, "validation_password_required"),
|
||||
"password.min_len": trans.Get(ctx, "validation_password_min"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Login) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"username": trans.Get(ctx, "validation_username"),
|
||||
"password": trans.Get(ctx, "validation_password"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type MenuCreate struct {
|
||||
ParentID uint `form:"parent_id" json:"parent_id"`
|
||||
Title string `form:"title" json:"title"`
|
||||
Slug string `form:"slug" json:"slug"`
|
||||
Icon string `form:"icon" json:"icon"`
|
||||
Path string `form:"path" json:"path"`
|
||||
Component string `form:"component" json:"component"`
|
||||
Permission string `form:"permission" json:"permission"`
|
||||
Type uint8 `form:"type" json:"type"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
Sort int `form:"sort" json:"sort"`
|
||||
IsHidden uint8 `form:"is_hidden" json:"is_hidden"`
|
||||
LinkType uint8 `form:"link_type" json:"link_type"`
|
||||
OpenType uint8 `form:"open_type" json:"open_type"`
|
||||
}
|
||||
|
||||
func (r *MenuCreate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *MenuCreate) Rules(ctx http.Context) map[string]string {
|
||||
rules := map[string]string{
|
||||
"title": "required|max_len:50",
|
||||
"slug": "required|max_len:50",
|
||||
"icon": "max_len:50",
|
||||
"component": "max_len:255",
|
||||
"permission": "max_len:100",
|
||||
"type": "in:1,2,3",
|
||||
"status": "in:0,1",
|
||||
"is_hidden": "in:0,1",
|
||||
"link_type": "in:1,2",
|
||||
"open_type": "in:1,2",
|
||||
}
|
||||
|
||||
// 根据 link_type 动态设置 path 的验证规则
|
||||
linkType := ctx.Request().Input("link_type")
|
||||
if linkType == "2" {
|
||||
// 外部链接:需要验证为完整的 URL
|
||||
rules["path"] = "required|max_len:1000|full_url"
|
||||
} else {
|
||||
// 内部页面:只需要必填和长度验证
|
||||
rules["path"] = "required|max_len:1000"
|
||||
// 内部页面不验证 open_type
|
||||
delete(rules, "open_type")
|
||||
}
|
||||
|
||||
return rules
|
||||
}
|
||||
|
||||
func (r *MenuCreate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"title.required": trans.Get(ctx, "menu_title_required"),
|
||||
"title.max_len": trans.Get(ctx, "validation_title_max"),
|
||||
"slug.required": trans.Get(ctx, "menu_slug_required"),
|
||||
"slug.max_len": trans.Get(ctx, "validation_slug_max"),
|
||||
"icon.max_len": trans.Get(ctx, "validation_icon_max"),
|
||||
"path.required": trans.Get(ctx, "menu_path_required"),
|
||||
"path.max_len": trans.Get(ctx, "validation_path_max"),
|
||||
"path.full_url": trans.Get(ctx, "validation_path_url_invalid"),
|
||||
"component.max_len": trans.Get(ctx, "validation_component_max"),
|
||||
"permission.max_len": trans.Get(ctx, "validation_permission_max"),
|
||||
"type.in": trans.Get(ctx, "validation_menu_type_in"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
"is_hidden.in": trans.Get(ctx, "validation_status_in"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *MenuCreate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"title": trans.Get(ctx, "validation_title"),
|
||||
"slug": trans.Get(ctx, "validation_slug"),
|
||||
"icon": trans.Get(ctx, "validation_icon"),
|
||||
"path": trans.Get(ctx, "validation_path"),
|
||||
"component": trans.Get(ctx, "validation_component"),
|
||||
"permission": trans.Get(ctx, "validation_permission"),
|
||||
"type": trans.Get(ctx, "validation_type"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
"is_hidden": trans.Get(ctx, "validation_is_hidden"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *MenuCreate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
// 将数字字段转换为字符串,以便 in 规则能正确验证
|
||||
if err := helpers.PrepareNumericFieldForValidation(data, "type"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := helpers.PrepareNumericFieldForValidation(data, "status"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := helpers.PrepareNumericFieldForValidation(data, "is_hidden"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := helpers.PrepareNumericFieldForValidation(data, "link_type"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := helpers.PrepareNumericFieldForValidation(data, "open_type"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type MenuUpdate struct {
|
||||
ParentID uint `form:"parent_id" json:"parent_id"`
|
||||
Title string `form:"title" json:"title"`
|
||||
Slug string `form:"slug" json:"slug"`
|
||||
Icon string `form:"icon" json:"icon"`
|
||||
Path string `form:"path" json:"path"`
|
||||
Component string `form:"component" json:"component"`
|
||||
Permission string `form:"permission" json:"permission"`
|
||||
Type uint8 `form:"type" json:"type"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
Sort int `form:"sort" json:"sort"`
|
||||
IsHidden uint8 `form:"is_hidden" json:"is_hidden"`
|
||||
LinkType uint8 `form:"link_type" json:"link_type"`
|
||||
OpenType uint8 `form:"open_type" json:"open_type"`
|
||||
}
|
||||
|
||||
func (r *MenuUpdate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *MenuUpdate) Rules(ctx http.Context) map[string]string {
|
||||
rules := map[string]string{
|
||||
"title": "max_len:50",
|
||||
"slug": "max_len:50",
|
||||
"icon": "max_len:50",
|
||||
"component": "max_len:255",
|
||||
"permission": "max_len:100",
|
||||
"type": "in:1,2,3",
|
||||
"status": "in:0,1",
|
||||
"is_hidden": "in:0,1",
|
||||
"link_type": "in:1,2",
|
||||
"open_type": "in:1,2",
|
||||
}
|
||||
|
||||
// 根据 link_type 动态设置 path 的验证规则
|
||||
linkType := ctx.Request().Input("link_type")
|
||||
if linkType == "2" {
|
||||
// 外部链接:需要验证为完整的 URL
|
||||
rules["path"] = "max_len:1000|full_url"
|
||||
} else {
|
||||
// 内部页面:只需要长度验证
|
||||
rules["path"] = "max_len:1000"
|
||||
// 内部页面不验证 open_type
|
||||
delete(rules, "open_type")
|
||||
}
|
||||
|
||||
return rules
|
||||
}
|
||||
|
||||
func (r *MenuUpdate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"title.max_len": trans.Get(ctx, "validation_title_max"),
|
||||
"slug.max_len": trans.Get(ctx, "validation_slug_max"),
|
||||
"icon.max_len": trans.Get(ctx, "validation_icon_max"),
|
||||
"path.max_len": trans.Get(ctx, "validation_path_max"),
|
||||
"path.full_url": trans.Get(ctx, "validation_path_url_invalid"),
|
||||
"component.max_len": trans.Get(ctx, "validation_component_max"),
|
||||
"permission.max_len": trans.Get(ctx, "validation_permission_max"),
|
||||
"type.in": trans.Get(ctx, "validation_menu_type_in"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
"is_hidden.in": trans.Get(ctx, "validation_status_in"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *MenuUpdate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"title": trans.Get(ctx, "validation_title"),
|
||||
"slug": trans.Get(ctx, "validation_slug"),
|
||||
"icon": trans.Get(ctx, "validation_icon"),
|
||||
"path": trans.Get(ctx, "validation_path"),
|
||||
"component": trans.Get(ctx, "validation_component"),
|
||||
"permission": trans.Get(ctx, "validation_permission"),
|
||||
"type": trans.Get(ctx, "validation_type"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
"is_hidden": trans.Get(ctx, "validation_is_hidden"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *MenuUpdate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
// 将数字字段转换为字符串,以便 in 规则能正确验证
|
||||
if err := helpers.PrepareNumericFieldForValidation(data, "type"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := helpers.PrepareNumericFieldForValidation(data, "status"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := helpers.PrepareNumericFieldForValidation(data, "is_hidden"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := helpers.PrepareNumericFieldForValidation(data, "link_type"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := helpers.PrepareNumericFieldForValidation(data, "open_type"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
)
|
||||
|
||||
type PaymentMethodCreate struct {
|
||||
Name string `form:"name" json:"name"`
|
||||
Code string `form:"code" json:"code"`
|
||||
Type string `form:"type" json:"type"`
|
||||
Config map[string]any `form:"config" json:"config"`
|
||||
IsActive bool `form:"is_active" json:"is_active"`
|
||||
Sort int `form:"sort" json:"sort"`
|
||||
Description string `form:"description" json:"description"`
|
||||
}
|
||||
|
||||
func (r *PaymentMethodCreate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PaymentMethodCreate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name": "required|max_len:50",
|
||||
"code": "required|max_len:20",
|
||||
"type": "required|max_len:20",
|
||||
"config": "required",
|
||||
"is_active": "boolean",
|
||||
"sort": "min:0",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *PaymentMethodCreate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name.required": trans.Get(ctx, "validation_name_required"),
|
||||
"name.max_len": trans.Get(ctx, "validation_name_max"),
|
||||
"code.required": trans.Get(ctx, "validation_code_required"),
|
||||
"code.max_len": trans.Get(ctx, "validation_code_max"),
|
||||
"type.required": trans.Get(ctx, "validation_type_required"),
|
||||
"type.max_len": trans.Get(ctx, "validation_type_max"),
|
||||
"config.required": trans.Get(ctx, "validation_config_required"),
|
||||
"is_active.boolean": trans.Get(ctx, "validation_boolean"),
|
||||
"sort.min": trans.Get(ctx, "validation_min"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *PaymentMethodCreate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name": trans.Get(ctx, "validation_name"),
|
||||
"code": trans.Get(ctx, "validation_code"),
|
||||
"type": trans.Get(ctx, "validation_type"),
|
||||
"config": trans.Get(ctx, "validation_config"),
|
||||
"is_active": trans.Get(ctx, "validation_is_active"),
|
||||
"sort": trans.Get(ctx, "validation_sort"),
|
||||
}
|
||||
}
|
||||
|
||||
// func (r *PaymentMethodCreate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
// // sort 字段使用 integer|min:0 规则,不需要转换为字符串
|
||||
// // 如果 sort 为空或不存在,设置为默认值 0
|
||||
// if val, exist := data.Get("sort"); !exist || val == nil || val == "" {
|
||||
// return data.Set("sort", 0)
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
@@ -0,0 +1,52 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
)
|
||||
|
||||
type PaymentMethodUpdate struct {
|
||||
Name string `form:"name" json:"name"`
|
||||
Config map[string]any `form:"config" json:"config"`
|
||||
IsActive bool `form:"is_active" json:"is_active"`
|
||||
Sort int `form:"sort" json:"sort"`
|
||||
Description string `form:"description" json:"description"`
|
||||
}
|
||||
|
||||
func (r *PaymentMethodUpdate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PaymentMethodUpdate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name": "required|max_len:50",
|
||||
"is_active": "boolean",
|
||||
"sort": "min:0",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *PaymentMethodUpdate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name.required": trans.Get(ctx, "validation_name_required"),
|
||||
"name.max_len": trans.Get(ctx, "validation_name_max"),
|
||||
"is_active.boolean": trans.Get(ctx, "validation_boolean"),
|
||||
"sort.min": trans.Get(ctx, "validation_min"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *PaymentMethodUpdate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name": trans.Get(ctx, "validation_name"),
|
||||
"is_active": trans.Get(ctx, "validation_is_active"),
|
||||
"sort": trans.Get(ctx, "validation_sort"),
|
||||
}
|
||||
}
|
||||
|
||||
// func (r *PaymentMethodUpdate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
// // return helpers.PrepareNumericFieldForValidation(data, "sort")
|
||||
// if val, exist := data.Get("sort"); !exist || val == nil || val == "" {
|
||||
// return data.Set("sort", 0)
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
@@ -0,0 +1,34 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
)
|
||||
|
||||
type ResetPassword struct {
|
||||
Password string `form:"password" json:"password"`
|
||||
}
|
||||
|
||||
func (r *ResetPassword) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ResetPassword) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"password": "required|min_len:6",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ResetPassword) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"password.required": trans.Get(ctx, "validation_password_required"),
|
||||
"password.min_len": trans.Get(ctx, "validation_password_min"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ResetPassword) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"password": trans.Get(ctx, "validation_password"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type RoleCreate struct {
|
||||
Name string `form:"name" json:"name"`
|
||||
Slug string `form:"slug" json:"slug"`
|
||||
Description string `form:"description" json:"description"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
Sort int `form:"sort" json:"sort"`
|
||||
}
|
||||
|
||||
func (r *RoleCreate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RoleCreate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name": "required|max_len:50",
|
||||
"slug": "required|max_len:50",
|
||||
"description": "max_len:255",
|
||||
"status": "in:0,1",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RoleCreate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name.required": trans.Get(ctx, "validation_name_required"),
|
||||
"name.max_len": trans.Get(ctx, "validation_name_max"),
|
||||
"slug.required": trans.Get(ctx, "validation_slug_required"),
|
||||
"slug.max_len": trans.Get(ctx, "validation_slug_max"),
|
||||
"description.max_len": trans.Get(ctx, "validation_description_max"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RoleCreate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name": trans.Get(ctx, "validation_name"),
|
||||
"slug": trans.Get(ctx, "validation_slug"),
|
||||
"description": trans.Get(ctx, "validation_description"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RoleCreate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
return helpers.PrepareNumericFieldForValidation(data, "status")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type RoleUpdate struct {
|
||||
Name string `form:"name" json:"name"`
|
||||
Slug string `form:"slug" json:"slug"`
|
||||
Description string `form:"description" json:"description"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
Sort int `form:"sort" json:"sort"`
|
||||
}
|
||||
|
||||
func (r *RoleUpdate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RoleUpdate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name": "max_len:50",
|
||||
"slug": "max_len:50",
|
||||
"description": "max_len:255",
|
||||
"status": "in:0,1",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RoleUpdate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name.max_len": trans.Get(ctx, "validation_name_max"),
|
||||
"slug.max_len": trans.Get(ctx, "validation_slug_max"),
|
||||
"description.max_len": trans.Get(ctx, "validation_description_max"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RoleUpdate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"name": trans.Get(ctx, "validation_name"),
|
||||
"slug": trans.Get(ctx, "validation_slug"),
|
||||
"description": trans.Get(ctx, "validation_description"),
|
||||
"status": trans.Get(ctx, "validation_status"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RoleUpdate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
return helpers.PrepareNumericFieldForValidation(data, "status")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
)
|
||||
|
||||
type UpdatePassword struct {
|
||||
OldPassword string `form:"old_password" json:"old_password"`
|
||||
NewPassword string `form:"new_password" json:"new_password"`
|
||||
ConfirmPassword string `form:"confirm_password" json:"confirm_password"`
|
||||
}
|
||||
|
||||
func (r *UpdatePassword) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *UpdatePassword) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"old_password": "required",
|
||||
"new_password": "required|min_len:6",
|
||||
"confirm_password": "required|same:new_password",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *UpdatePassword) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"old_password.required": trans.Get(ctx, "validation_old_password_required"),
|
||||
"new_password.required": trans.Get(ctx, "validation_new_password_required"),
|
||||
"new_password.min_len": trans.Get(ctx, "validation_password_min"),
|
||||
"confirm_password.required": trans.Get(ctx, "validation_confirm_password_required"),
|
||||
"confirm_password.same": trans.Get(ctx, "validation_password_not_match"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *UpdatePassword) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"old_password": trans.Get(ctx, "validation_old_password"),
|
||||
"new_password": trans.Get(ctx, "validation_new_password"),
|
||||
"confirm_password": trans.Get(ctx, "validation_confirm_password"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type UserCreate struct {
|
||||
Username string `form:"username" json:"username"`
|
||||
Password string `form:"password" json:"password"`
|
||||
Nickname string `form:"nickname" json:"nickname"`
|
||||
Email string `form:"email" json:"email"`
|
||||
Phone string `form:"phone" json:"phone"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
}
|
||||
|
||||
func (r *UserCreate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *UserCreate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"username": "required|min_len:3|max_len:50|not_exists:users,username",
|
||||
"password": "required|min_len:6|max_len:50",
|
||||
"nickname": "max_len:50",
|
||||
"email": "email|max_len:100|not_exists:users,email",
|
||||
"phone": "max_len:20",
|
||||
"status": "in:0,1",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *UserCreate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"username.required": trans.Get(ctx, "validation_username_required"),
|
||||
"username.min_len": trans.Get(ctx, "validation_username_min"),
|
||||
"username.max_len": trans.Get(ctx, "validation_username_max"),
|
||||
"username.not_exists": trans.Get(ctx, "username_exists"),
|
||||
"password.required": trans.Get(ctx, "validation_password_required"),
|
||||
"password.min_len": trans.Get(ctx, "validation_password_min"),
|
||||
"password.max_len": trans.Get(ctx, "validation_password_max"),
|
||||
"nickname.max_len": trans.Get(ctx, "validation_nickname_max"),
|
||||
"email.email": trans.Get(ctx, "validation_email_format"),
|
||||
"email.max_len": trans.Get(ctx, "validation_email_max"),
|
||||
"email.not_exists": trans.Get(ctx, "email_already_exists"),
|
||||
"phone.max_len": trans.Get(ctx, "validation_phone_max"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *UserCreate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"username": trans.Get(ctx, "attribute_username"),
|
||||
"password": trans.Get(ctx, "attribute_password"),
|
||||
"nickname": trans.Get(ctx, "attribute_nickname"),
|
||||
"email": trans.Get(ctx, "attribute_email"),
|
||||
"phone": trans.Get(ctx, "attribute_phone"),
|
||||
"status": trans.Get(ctx, "attribute_status"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *UserCreate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
return helpers.PrepareNumericFieldForValidation(data, "status")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"goravel/app/http/helpers"
|
||||
"goravel/app/http/trans"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/contracts/validation"
|
||||
)
|
||||
|
||||
type UserUpdate struct {
|
||||
Nickname string `form:"nickname" json:"nickname"`
|
||||
Email string `form:"email" json:"email"`
|
||||
Phone string `form:"phone" json:"phone"`
|
||||
Password string `form:"password" json:"password"`
|
||||
Status uint8 `form:"status" json:"status"`
|
||||
}
|
||||
|
||||
func (r *UserUpdate) Authorize(ctx http.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *UserUpdate) Rules(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"nickname": "max_len:50",
|
||||
"email": "email|max_len:100",
|
||||
"phone": "max_len:20",
|
||||
"password": "min_len:6|max_len:50",
|
||||
"status": "in:0,1",
|
||||
}
|
||||
}
|
||||
|
||||
func (r *UserUpdate) Messages(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"nickname.max_len": trans.Get(ctx, "validation_nickname_max"),
|
||||
"email.email": trans.Get(ctx, "validation_email_format"),
|
||||
"email.max_len": trans.Get(ctx, "validation_email_max"),
|
||||
"phone.max_len": trans.Get(ctx, "validation_phone_max"),
|
||||
"password.min_len": trans.Get(ctx, "validation_password_min"),
|
||||
"password.max_len": trans.Get(ctx, "validation_password_max"),
|
||||
"status.in": trans.Get(ctx, "validation_status_in"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *UserUpdate) Attributes(ctx http.Context) map[string]string {
|
||||
return map[string]string{
|
||||
"nickname": trans.Get(ctx, "attribute_nickname"),
|
||||
"email": trans.Get(ctx, "attribute_email"),
|
||||
"phone": trans.Get(ctx, "attribute_phone"),
|
||||
"password": trans.Get(ctx, "attribute_password"),
|
||||
"status": trans.Get(ctx, "attribute_status"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *UserUpdate) PrepareForValidation(ctx http.Context, data validation.Data) error {
|
||||
return helpers.PrepareNumericFieldForValidation(data, "status")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user