当前位置: 首页>>代码示例>>Golang>>正文


Golang Validation.MaxSize方法代码示例

本文整理汇总了Golang中github.com/astaxie/beego/validation.Validation.MaxSize方法的典型用法代码示例。如果您正苦于以下问题:Golang Validation.MaxSize方法的具体用法?Golang Validation.MaxSize怎么用?Golang Validation.MaxSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/astaxie/beego/validation.Validation的用法示例。


在下文中一共展示了Validation.MaxSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Login

//用户登录
func (this *User) Login() {
	json := this.ReqJson()
	if json != nil {
		email := json.Get("email").MustString()
		password := json.Get("password").MustString()

		valid := validation.Validation{}
		valid.Email(email, "email")
		valid.MinSize(password, 6, "passwordMin")
		valid.MaxSize(password, 12, "passwordMax")

		if valid.HasErrors() {
			this.CustomAbort(enum.BadRequest.Code(), enum.BadRequest.Str())
		}

		u := user.GetUserByEmail(email)
		if u == nil {
			//用户不存在
			this.RespJson(enum.UserNotExist, nil)
		} else if util.Md5(u.Salt+password) != u.Password {
			//密码错误
			this.RespJson(enum.PasswordIncorrect, nil)
		} else {
			this.SetSession("uId", u.Id.Hex())
			user.SetToken(u.Id, this.StartSession().SessionID()) //using cookie as token
			this.RespJson(enum.OK, map[string]interface{}{"url": "/"})
		}
	}
}
开发者ID:elvizlai,项目名称:MGBlog,代码行数:30,代码来源:user.go

示例2: Signup

/**
 * 登录接收
 */
func (this *UserController) Signup() {
	//errmsg := make(map[string]string)
	requestEmail := this.GetString("email")
	requestPassword := this.GetString("password")

	svalid := validation.Validation{}

	svalid.Required(requestEmail, "email")
	svalid.MaxSize(requestEmail, 40, "email")
	svalid.Required(requestPassword, "password")

	if svalid.HasErrors() {
		for _, err := range svalid.Errors {
			//fmt.Println(err.Key, err.Message)
			this.showmsg("Error Message", "["+err.Key+"]"+err.Message)
		}
	}

	var user models.User
	user.Email = requestEmail
	user.Password = models.Md5([]byte(requestPassword))

	var Ru models.ReturnUser
	Ru = user.Select()

	if Ru.Id > 0 {
		this.SetSession("nickname", Ru.Nickname)
		this.SetSession("email", Ru.Email)
		this.SetSession("isadmin", Ru.Isadmin)
		this.Redirect("/", 302)
	} else {
		this.showmsg("Error", "Email OR Password IS WRONG")
	}
}
开发者ID:lvzhongyi,项目名称:canku,代码行数:37,代码来源:user.go

示例3: ValidUserAdd

// Valid user add
func (u *User) ValidUserAdd() *validation.Validation {
	valid := validation.Validation{}

	u.Username = strings.TrimSpace(u.Username)
	u.Password = strings.TrimSpace(u.Password)

	valid.Required(u.Username, "UsernameReq").Message("用户名不能为空")
	valid.MinSize(u.Username, 6, "UsernameMixSize").Message("用户名不能小于6个字符")
	valid.MaxSize(u.Username, 10, "UsernameMaxSize").Message("用户姓名不能大于10个字符")

	valid.MinSize(u.Password, 6, "PasswordMinSize").Message("用户密码不能小于6为字符")
	valid.MaxSize(u.Password, 10, "PasswordMaxSize").Message("用户密码不能大于10个字符")

	// uLen := len(strings.TrimSpace(u.Username))
	// if uLen < 6 || uLen > 10 {
	// valid.SetError("Username", "用户不能为空,长度大于6小于10")
	// }

	// pLen := len(strings.TrimSpace(u.Password))
	// if pLen < 6 || pLen > 10 {
	// valid.SetError("Password", "用户密码不能为空,长度大于6小于10")
	// }

	return &valid
}
开发者ID:11101171,项目名称:violence,代码行数:26,代码来源:user.go

示例4: Register

//用户注册
func (this *User) Register() {
	req := this.ReqJson()
	if req != nil {
		email := req.Get("email").MustString()
		nickName := req.Get("nickName").MustString()
		password := req.Get("password").MustString()

		valid := validation.Validation{}
		valid.Email(email, "email")
		valid.MinSize(nickName, 6, "nickNameMin")
		valid.MaxSize(nickName, 12, "nickNameMax")
		valid.MinSize(password, 6, "passwordMin")
		valid.MaxSize(password, 12, "passwordMax")

		if valid.HasErrors() {
			this.CustomAbort(enum.BadRequest.Code(), enum.BadRequest.Str())
		}

		err := user.AddUser(email, nickName, password)
		if err == nil {
			this.RespJson(enum.OK, nil)
		} else {
			if strings.Contains(err.Error(), "email") {
				this.RespJson(enum.EmailAlreadyExist, nil)
			} else if strings.Contains(err.Error(), "nickname") {
				this.RespJson(enum.NickNameAlreadyExist, nil)
			} else {
				beego.Error(err)
			}
		}
	}
}
开发者ID:elvizlai,项目名称:MGBlog,代码行数:33,代码来源:user.go

示例5: Login

func (this *UserController) Login() {
	if this.Ctx.Input.Method() == "GET" {
		if this.GetSession("user") != nil {
			this.Redirect("/", 302)
		}
		this.TplNames = "console/login.html"
		return
	}

	json := this.ReqJson()
	email := json.Get("email").MustString()
	password := json.Get("password").MustString()

	valid := validation.Validation{}
	valid.Email(email, "email")
	valid.MinSize(password, 6, "passwordMin")
	valid.MaxSize(password, 12, "passwordMax")

	if valid.HasErrors() {
		this.CustomAbort(enum.RespCode.BadRequest.Code(), enum.RespCode.BadRequest.Str())
	}

	user := user.GetUserByEmail(email)
	if user == nil {
		//用户不存在
		this.RespJson(enum.RespCode.UserNotExist, nil)
	} else if util.Md5(user.Salt+password) != user.Password {
		//密码错误
		this.RespJson(enum.RespCode.PasswordIncorrect, nil)
	} else {
		this.SetSession("user", user)
		this.RespJson(enum.RespCode.OK, map[string]interface{}{"url": "/"})
	}
}
开发者ID:elvizlai,项目名称:Blog,代码行数:34,代码来源:userController.go

示例6: ValidCmdAdd

// Valid cmdForm add
func (this *Cmd) ValidCmdAdd() *validation.Validation {
	valid := validation.Validation{}

	valid.Required(this.Shell, "ShellReq").Message("脚本不能为空")
	valid.MinSize(this.Shell, 1, "ShellMixSize").Message("脚本不能小于1个字符")
	valid.MaxSize(this.Shell, 225, "ShellMaxSize").Message("脚本不能大于225个字符")

	valid.Required(this.AgentId, "AgentIdReq").Message("主机不能为空")

	return &valid
}
开发者ID:11101171,项目名称:violence,代码行数:12,代码来源:cmd.go

示例7: ValidAgentAdd

// Valid userForm add
func (a *Agent) ValidAgentAdd() *validation.Validation {
	valid := validation.Validation{}

	a.Host = strings.TrimSpace(a.Host)
	a.Port = strings.TrimSpace(a.Port)
	a.LoginName = strings.TrimSpace(a.LoginName)
	a.LoginPass = strings.TrimSpace(a.LoginPass)

	valid.Required(a.Host, "HostReq").Message("远程地址不能为空")
	valid.MinSize(a.Host, 10, "HostMixSize").Message("远程地址不能小于10个字符")
	valid.MaxSize(a.Host, 225, "HostMaxSize").Message("远程地址不能大于225个字符")

	valid.Required(a.Port, "PortReq").Message("端口不能为空")
	valid.MinSize(a.Port, 2, "PortMixSize").Message("端口不能小于2个字符")
	valid.MaxSize(a.Port, 6, "PortMaxSize").Message("端口不能大于6个字符")

	valid.Required(a.LoginName, "LoginNameReq").Message("登录用户名不能为空")
	valid.MinSize(a.LoginName, 1, "LoginNameMixSize").Message("登录用户名不能小于1个字符")
	valid.MaxSize(a.LoginName, 225, "LoginNameMaxSize").Message("登录用户名不能大于225个字符")

	valid.Required(a.LoginPass, "LoginPassReq").Message("登录密码不能为空")
	valid.MinSize(a.LoginPass, 1, "LoginPassMixSize").Message("登录密码不能小于1个字符")
	valid.MaxSize(a.LoginPass, 225, "LoginPassMaxSize").Message("登录密码不能大于225个字符")

	return &valid
}
开发者ID:11101171,项目名称:violence,代码行数:27,代码来源:agent.go

示例8: ValidEmail

func (c *TUserController) ValidEmail() {
	email := c.GetString("email")
	valid := validation.Validation{}
	valid.Email(email, "Email")
	valid.MaxSize(email, 50, "Email")
	if valid.HasErrors() {
		c.Data["json"] = map[string]string{"error": "邮箱不正确"}
	} else {
		err := models.ValidEmail(email)
		if err == nil {
			c.Data["json"] = map[string]string{"error": "邮箱已经存在"}
		} else {
			c.Data["json"] = map[string]string{"message": "这个邮箱未被注册"}
		}
	}
	c.ServeJson()
}
开发者ID:langziguilai,项目名称:HSNet,代码行数:17,代码来源:t_user.go

示例9: Valid

// We will check if the user data are valid
func (u User) Valid() bool {
	v := validation.Validation{}
	v.Required(u.Name, "name")
	v.MaxSize(u.Name, 20, "nameMax")
	v.Required(u.Pass, "pass")
	v.MaxSize(u.Pass, 30, "passMax")
	v.Email(u.Email, "email")

	if v.HasErrors() {
		for _, e := range v.Errors {
			log.Println("Check valid user data:", e)
		}
		return false
	}

	return true
}
开发者ID:Jackgris,项目名称:mstock,代码行数:18,代码来源:users.go

示例10: ValidUserName

func (c *TUserController) ValidUserName() {
	username := c.GetString("username")
	valid := validation.Validation{}
	re, _ := regexp.Compile(`[\p{Han},\w]+`)
	valid.Match(username, re, "用户名")
	valid.MinSize(username, 4, "用户名")
	valid.MaxSize(username, 16, "用户名")
	if valid.HasErrors() {
		c.Data["json"] = map[string]string{"error": "用户名不正确"}
	} else {
		err := models.ValidUserName(username)
		if err == nil {
			c.Data["json"] = map[string]string{"error": "用户名已经存在"}
		} else {
			c.Data["json"] = map[string]string{"message": "你可以使用此用户名"}
		}
	}
	c.ServeJson()
}
开发者ID:langziguilai,项目名称:HSNet,代码行数:19,代码来源:t_user.go

示例11: Get

// @router /home [get]
func (this *HomeController) Get() {
	// this.Ctx.WriteString("HomeController")
	this.Abort("404")
	valid := validation.Validation{}
	u := user{20}

	valid.MaxSize(u.Age, 15, "ageMax")

	if valid.HasErrors() {
		for _, err := range valid.Errors {
			log.Println(err.Key, err.Message)
		}
	}

	if v := valid.Max(u.Age, 12, "age"); !v.Ok {
		log.Println(v.Error.Key, v.Error.Message)
	}

	this.TplNames = "addUser.html"
}
开发者ID:lcbyz,项目名称:Go,代码行数:21,代码来源:HomeController.go

示例12: main

func main() {
	u := User{"man", 14}
	valid := validation.Validation{}
	valid.Required(u.Name, "name")
	valid.MaxSize(u.Name, 15, "nameMax")
	//	valid.Range(u.Age, 0, 18, "age")
	//	if valid.HasErrors() {
	//		for _, err := range valid.Errors {
	//			log.Println(err.Key, err.Message)
	//		}
	//	}

	//	if v := valid.Max(u.Age, 140, "age"); !v.Ok {
	//		log.Println(v.Error.Key, v.Error.Message)
	//	}
	minAge := 18
	valid.Min(u.Age, minAge, "age").Message("少儿不宜!")
	// 错误信息格式化
	valid.Min(u.Age, minAge, "age").Message("%d不禁", minAge)
}
开发者ID:crazygit,项目名称:go-gist,代码行数:20,代码来源:validation.go

示例13: Join

/**
 * 注册逻辑处理
 * @param  {[type]} this *UserController) Join( [description]
 * @return {[type]}      [description]
 */
func (this *UserController) Join() {
	beego.AutoRender = false
	errmsg := make(map[string]string)
	requestEmail := this.GetString("email")
	requestNickname := this.GetString("nickname")
	requestPassword := this.GetString("password")

	jvalid := validation.Validation{}

	jvalid.Required(requestEmail, "email")
	jvalid.MaxSize(requestEmail, 40, "email")
	jvalid.Required(requestNickname, "nickname")
	jvalid.MaxSize(requestNickname, 20, "nickname")
	jvalid.Required(requestPassword, "password")

	fmt.Println(jvalid.HasErrors())

	if jvalid.HasErrors() {
		for _, err := range jvalid.Errors {
			//fmt.Println(err.Key, err.Message)
			this.showmsg("Error Message", "["+err.Key+"]"+err.Message)
		}
	}

	if len(errmsg) == 0 {
		var user models.User
		user.Email = requestEmail
		user.Nickname = requestNickname
		user.Password = models.Md5([]byte(requestPassword))
		user.Lastlogin = time.Now().Unix()
		if err := user.Insert(); err != nil {
			this.Ctx.WriteString(err.Error())
		}
	}
	this.SetSession("nickname", requestNickname)
	this.SetSession("email", requestEmail)
	this.SetSession("isadmin", 0)
	this.Redirect("/", 302)
}
开发者ID:lvzhongyi,项目名称:canku,代码行数:44,代码来源:user.go

示例14: Register

func (this *UserController) Register() {
	if this.Ctx.Input.Method() == "GET" {
		if can, err := beego.AppConfig.Bool("CanBeRegister"); err == nil && can {
			this.Data["CanBeRegister"] = true
		}
		this.TplNames = "console/register.html"
		return
	}

	req := this.ReqJson()
	email := req.Get("email").MustString()
	nickName := req.Get("nickName").MustString()
	password := req.Get("password").MustString()

	valid := validation.Validation{}
	valid.Email(email, "email")
	valid.MinSize(nickName, 6, "nickNameMin")
	valid.MaxSize(nickName, 12, "nickNameMax")
	valid.MinSize(password, 6, "passwordMin")
	valid.MaxSize(password, 12, "passwordMax")

	if valid.HasErrors() {
		this.CustomAbort(enum.RespCode.BadRequest.Code(), enum.RespCode.BadRequest.Str())
	}

	err := user.AddUser(email, nickName, password)
	if err == nil {
		this.RespJson(enum.RespCode.OK, nil)
	} else {
		if strings.Contains(err.Error(), "email") {
			this.RespJson(enum.RespCode.EmailExist, nil)
		} else if strings.Contains(err.Error(), "nick_name") {
			this.RespJson(enum.RespCode.NickNameExist, nil)
		} else {
			beego.Error(err)
		}
	}
}
开发者ID:elvizlai,项目名称:Blog,代码行数:38,代码来源:userController.go

示例15: Add

//添加用户
func (this *UserController) Add() {
	input := make(map[string]string)
	errmsg := make(map[string]string)
	if this.Ctx.Request.Method == "POST" {
		username := strings.TrimSpace(this.GetString("username"))
		password := strings.TrimSpace(this.GetString("password"))
		password2 := strings.TrimSpace(this.GetString("password2"))
		email := strings.TrimSpace(this.GetString("email"))
		active, _ := this.GetInt("active")

		input["username"] = username
		input["password"] = password
		input["password2"] = password2
		input["email"] = email

		valid := validation.Validation{}

		if v := valid.Required(username, "username"); !v.Ok {
			errmsg["username"] = "请输入用户名"
		} else if v := valid.MaxSize(username, 15, "username"); !v.Ok {
			errmsg["username"] = "用户名长度不能大于15个字符"
		}

		if v := valid.Required(password, "password"); !v.Ok {
			errmsg["password"] = "请输入密码"
		}

		if v := valid.Required(password2, "password2"); !v.Ok {
			errmsg["password2"] = "请再次输入密码"
		} else if password != password2 {
			errmsg["password2"] = "两次输入的密码不一致"
		}

		if v := valid.Required(email, "email"); !v.Ok {
			errmsg["email"] = "请输入email地址"
		} else if v := valid.Email(email, "email"); !v.Ok {
			errmsg["email"] = "Email无效"
		}

		if active > 0 {
			active = 1
		} else {
			active = 0
		}

		if len(errmsg) == 0 {
			var user models.User
			user.Username = username
			user.Password = models.Md5([]byte(password))
			user.Email = email
			user.Active = int8(active)
			if err := user.Insert(); err != nil {
				this.showmsg(err.Error())
			}
			this.Redirect("/admin/user/list", 302)
		}

	}

	this.Data["input"] = input
	this.Data["errmsg"] = errmsg
	this.display()
}
开发者ID:cnitfarmer,项目名称:blog,代码行数:64,代码来源:user.go


注:本文中的github.com/astaxie/beego/validation.Validation.MaxSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。