Beispiel #1
0
func UserLogin(ctx *ink.Context) {
	mail := getParam(ctx, "mail").(string)
	pass := getParam(ctx, "pass").(string)
	user := userLogin(mail, pass)
	if user != nil {
		userId := user.Id.Hex()
		token := ctx.TokenNew()
		ctx.TokenSet("id", userId)
		returnRet(ctx, true, Map{
			"token": token,
		})
		return
	}
	returnRet(ctx, false, "账户或密码错误")
}
Beispiel #2
0
func UserRegister(ctx *ink.Context) {
	defer exceptHandle(ctx)
	mail := getParam(ctx, "mail").(string)
	pass := getParam(ctx, "pass").(string)
	if !validType("mail", mail) {
		panic("邮箱格式不正确")
	}
	if passLen := len(pass); passLen < 6 || passLen > 16 {
		panic("密码位数在6-16之间")
	}
	if userExist(mail) {
		panic("账户已被使用")
	}
	if userId := userRegister(mail, pass); userId != "" {
		token := ctx.TokenNew()
		ctx.TokenSet("id", userId)
		returnRet(ctx, true, Map{
			"token": token,
		})
		return
	}
	panic("注册失败,内部错误")
}