示例#1
0
func (this *LogoutController) Get() {
	_, err := lib.GetUserByCookie(this.Ctx)
	if err == true {
		lib.SetCookie(this.Ctx, "", "", -1)
	}
	this.Redirect("/", 301)
}
示例#2
0
func (this *RegisterController) Post() {
	username := this.Input().Get("username")
	_, h, img_err := this.GetFile("user-header")

	password := this.Input().Get("password")
	email := this.Input().Get("email")
	gender := this.Input().Get("gender")
	age := this.Input().Get("age")

	valid_user := existUsername(username)
	if valid_user == false {
		this.Redirect("/register", 302)
		return
	}

	var path = getPath() + "static/img/head/"
	var img_header string = ""
	if img_err == nil {
		img_header = fmt.Sprint(path, h.Filename)
		this.SaveToFile("user-header", img_header)
	}

	int_age, _ := strconv.Atoi(age)
	int_gender, _ := strconv.Atoi(gender)

	var userObj *models.User = new(models.User)
	userObj.Add(username, email, password, img_header, int_gender, int_age)
	lib.SetCookie(this.Ctx, username, password, contains.SmallCookieTime)
	this.Redirect("/", 302)
}
示例#3
0
func (this *LoginController) Post() {
	username := this.Input().Get("username")
	password := this.Input().Get("password")
	remenber := this.Input().Get("remenber")
	if username == "" || password == "" {
		this.Redirect("/", 302)
		return
	}
	var user []*models.User
	o := orm.NewOrm()
	o.QueryTable("user").Filter("Name", username).Filter("Password", models.HashPassword(password)).One(&user)

	if len(user) == 0 {
		this.Redirect("/login", 302)
		return
	}
	fmt.Println(user)
	if remenber == "true" {
		lib.SetCookie(this.Ctx, username, password, contains.MiddleCookieTime)
	} else {
		lib.SetCookie(this.Ctx, username, password, contains.SmallCookieTime)
	}
	this.Redirect("/", 301)
}