Exemplo n.º 1
0
Arquivo: user.go Projeto: tangseng/yts
func (this *UserController) Create() {
	this.Info = &map[string]string{
		"fail": "信息不全",
		"user": "******",
		"ok":   "成功啦!",
	}
	name := this.GetString("loginName")
	password := this.GetString("loginPass")
	nick := this.GetString("name")
	if len(name) == 0 || len(password) == 0 || len(nick) == 0 {
		this.ERR("fail")
		return
	}
	userOption := models.NewUserOption()
	user, err := userOption.Get(name)
	if user != nil {
		this.ERR("user")
		return
	}
	salt := models.RandStr2(5)
	user = models.NewUser(name, nick, password, salt, 0)
	err = userOption.Create(user)
	if err != nil {
		this.ERR(err.Error())
		return
	}
	this.OK("ok")
}
Exemplo n.º 2
0
Arquivo: sq.go Projeto: tangseng/yts
func (this *SQController) AdminStatus() {
	this.Info = &map[string]string{
		"user": "******",
		"ok":   "OK!",
	}
	name := this.GetString("name")
	status, _ := this.GetInt8("status")
	sqOption := models.NewSQOption()
	sq, err := sqOption.Get(name)
	if err != nil {
		this.ERR(err.Error())
		return
	}
	if status == 1 {
		userOption := models.NewUserOption()
		user, uerr := userOption.Get(name)
		if uerr == nil || user != nil {
			this.ERR("user")
			return
		}
		salt := models.RandStr2(5)
		user = models.NewUser(sq.Name, sq.Nick, sq.Password, salt, 0)
		err = userOption.Create(user)
		if err != nil {
			this.ERR(err.Error())
			return
		}
	}
	sq.Status = status
	err = sqOption.Set(sq)
	if err != nil {
		this.ERR(err.Error())
		return
	}
	this.OK("ok")
}