示例#1
0
// Checks login
func login(wr *web.Context) {

	// Login user
	if wr.Params["username"] != "" && wr.Params["password"] != "" {
		username := wr.Params["username"]
		password := wr.Params["password"]
		loginName := jailgo.Authenticate(username, password)

		// If you have a valid user
		if loginName != nil {
			log.Println("DEBUG Controller *Username type: ", loginName.User)
			wr.SetSecureCookie("user", loginName.User, 20000) //15 minutes for session
			wr.Redirect(303, "/jail?check=ok")

			// If you haven't
		} else {
			wr.Redirect(303, "/jail?check=err")
		}

		// Maybe you're going out
	} else if wr.Params["logout"] != "" {
		wr.SetSecureCookie("user", "off", 0)
		wr.Redirect(303, "/jail?check=out")
	} else {

		// If you wrote nothing
		log.Println("DEBUG Controller user: "******"username"])
		log.Println("DEBUG Controller pass: "******"password"])
		wr.Redirect(303, "/jail?check=err")
	}
}
示例#2
0
func update(ctx *web.Context) {
	if ctx.Params["submit"] == "Delete" {
		ctx.SetCookie(web.NewCookie(cookieName, "", -1))
	} else {
		ctx.SetSecureCookie(cookieName, ctx.Params["cookie"], 0)
	}
	ctx.Redirect(301, "/")
}
示例#3
0
func (sm *SessionManager) Login(ctx *web.Context, user, pass string) bool {
	sm.removeExpired()
	if sm.LoggedIn(ctx) {
		return true
	}
	if pHash, ok := sm.users[user]; ok && bcrypt.CompareHashAndPassword([]byte(pHash), []byte(pass)) == nil {
		s := session{makeSessionId(), time.Now().Add(2 * time.Minute)}
		sm.sessions = append(sm.sessions, s)
		ctx.SetSecureCookie("TDB-user", s.id, 120)
		return true
	}
	return false
}
示例#4
0
func adminPost(ctx *web.Context) {
	level := ctx.Params["godlevel"]
	godlevel := godHash(level)

	if ctx.Params["what"] == "login" {
		if godlevel == admin_pass {
			ctx.SetSecureCookie("godlevel", level, 3600)
			ctx.Redirect(301, "/admin")
			return
		}
		ctx.SetSecureCookie("godlevel", "fefe", 3600)
		ctx.Redirect(301, "/")
		return
	}

	if !checkGodLevel(ctx) {
		ctx.SetSecureCookie("godlevel", "fefe", 3600)
		ctx.Redirect(301, "/")
		return
	}

	if ctx.Params["what"] == "post" {
		err := createNewPost(ctx.Params["content"])
		if err != nil {
			ctx.WriteString("couldn't post: " + err.Error())
			ctx.WriteString("<br><br><A href='/'>Index</a>")
			return
		}
		ctx.WriteString(successpage)
		return
	}
}
示例#5
0
func SetCSS(ctx *web.Context, css string) {
	ctx.SetSecureCookie("css", css, 31556926)
}