Example #1
0
File: base.go Project: tangseng/yts
func (this *BaseController) Auth() {
	sessionVal := this.GetSession("sessionVal")
	switch this.ControllerName {
	case "LoginController":
		switch this.ActionName {
		case "Login", "Dologin":
			if sessionVal != nil {
				this.Redirect("/ts", 302)
			}
		}
	case "TSController":
		switch this.ActionName {
		case "PHP", "JS", "Post":
			if sessionVal != nil {
				//this.Redirect("/ts", 302)
			}
		default:
			if sessionVal == nil {
				this.CustomRedirect()
			}
		}
	case "TSKLController":
		switch this.ActionName {
		case "GetKL", "PostKL":
			if sessionVal != nil {
				this.Redirect("/ts", 302)
			}
		default:
			if sessionVal == nil {
				this.CustomRedirect()
			}
		}
	case "SQController":
		switch this.ActionName {
		case "Show", "Create":
			if sessionVal != nil {
				this.Redirect("/ts", 302)
			}
		default:
			if sessionVal == nil {
				this.CustomRedirect()
			}
		}
	default:
		if sessionVal == nil {
			this.CustomRedirect()
		}
	}
	if sessionVal != nil {
		sessionMap := sessionVal.(map[string]string)
		this.User, _ = models.NewUserOption().Get(sessionMap["name"])
		this.Token = sessionMap["token"]
		if this.ControllerName == "UserController" && this.User.Name != "admin" {
			this.CustomRedirect()
		}
		if this.ControllerName == "SQController" && strings.HasPrefix(this.ActionName, "Admin") && this.User.Name != "admin" {
			this.CustomRedirect()
		}
	}
}
Example #2
0
File: user.go Project: tangseng/yts
func (this *UserController) Update() {
	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 || err != nil {
		this.ERR("user")
		return
	}
	user.Password = password
	user.Nick = nick
	err = userOption.Update(user)
	if err != nil {
		this.ERR(err.Error())
		return
	}
	this.OK("ok")
}
Example #3
0
File: user.go Project: 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")
}
Example #4
0
File: user.go Project: tangseng/yts
func (this *UserController) Delete() {
	this.Info = &map[string]string{
		"ok": "删除成功!",
	}
	name := this.GetString("loginName")
	userOption := models.NewUserOption()
	err := userOption.Delete(name)
	if err != nil {
		this.ERR(err.Error())
		return
	}
	this.OK("ok")
}
Example #5
0
File: user.go Project: tangseng/yts
func (this *UserController) Show() {
	users := models.NewUserOption().GetAll()
	for _, v := range users {
		fmt.Printf("%v", v)
	}
	outUsers := make([]map[string]string, len(users))
	for k, v := range users {
		outUsers[k] = map[string]string{
			"name":      v.Nick,
			"loginName": v.Name,
			"loginPass": v.Password,
		}
	}
	this.Data["Persons"] = outUsers
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["Navbar"] = "layout/navbar.html"
	this.Data["Script"] = []string{"app/app", "app/directives/tip", "app/controllers/person/personCtrl"}
	this.TplNames = "user.html"
}
Example #6
0
func (this *LoginController) DoLogin() {
	this.Info = &map[string]string{
		"success": "登录成功",
		"login":   "******",
	}
	name := this.GetString("name")
	password := this.GetString("pass")
	user, err := models.NewUserOption().Get(name)
	if err != nil || user.CheckPass(password) {
		this.ERR("login")
		return
	}
	token := models.NewToken(user, "")
	models.NewTokenOption().Add(token)
	this.SetSession("sessionVal", map[string]string{
		"name":  user.Name,
		"token": token.Token(),
	})
	this.OK("success")
}
Example #7
0
File: sq.go Project: 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")
}