Esempio n. 1
0
func checkGodLevel(ctx *web.Context) bool {
	godlevel, _ := ctx.GetSecureCookie("godlevel")
	godlevel = godHash(godlevel)
	if godlevel == admin_pass {
		return true
	}
	return false
}
Esempio n. 2
0
func index(ctx *web.Context) string {
	cookie, ok := ctx.GetSecureCookie(cookieName)
	var top string
	if !ok {
		top = fmt.Sprintf(notice, "The cookie has not been set")
	} else {
		var val = html.EscapeString(cookie)
		top = fmt.Sprintf(notice, "The value of the cookie is '"+val+"'.")
	}
	return top + form
}
Esempio n. 3
0
// Update database for articles and render main page
func updateArt(wr *web.Context) {
	loginUser, err := wr.GetSecureCookie("user")
	if err {
		log.Println("DEBUG User logged updating article: ", loginUser)
		jailgo.Updateart(wr.Params["title"], wr.Params["description"])

		// Redirect to the main page which will show the specified art
		wr.Redirect(303, "/jail")

		// We could show this art directly using show(wr, art_num)
		// but see: http://en.wikipedia.org/wiki/Post/Redirect/Get
	} else {
		wr.Redirect(303, "/jail?check=err")
	}
}
Esempio n. 4
0
func admin(wr *web.Context) {
	loginUser, err := wr.GetSecureCookie("user")
	if err == true && loginUser != "off" {

		// Log username to control and render Admin page
		log.Println("DEBUG User logged accessing administration: ", loginUser)
		adminshow.Exec(wr)
		getdeleteart(wr)
		adminshow2.Exec(wr)
		getalldeletentry(wr)
		adminshow3.Exec(wr)
		check := ""
		foot1.Exec(wr, ViewCtxLogin{BlogLogin(wr, check), vinfo()})
		last(wr)
		foot2.Exec(wr)
	} else {
		wr.Redirect(303, "/jail?check=err")
	}
}
Esempio n. 5
0
func GetCSS(ctx *web.Context) (css string, ok bool) {
	css, ok = ctx.GetSecureCookie("css")
	return
}
Esempio n. 6
0
func (sm *SessionManager) LoggedIn(ctx *web.Context) bool {
	if id, ok := ctx.GetSecureCookie("TDB-user"); ok && sm.SessionExists(id) {
		return true
	}
	return false
}
Esempio n. 7
0
func BlogLogin(wr *web.Context, check string) *LoginBox {
	if check != "" {
		if check == "err" {
			return &LoginBox{
				Invalid:    "<p><font color='#FF0000'><b>INVALID USER</b></font></p>",
				Userid:     "<p>User:  <input maxlength='15' size='16' name='username'></input></p>",
				Passwordid: "<p>Password: <input maxlength='10' size='13' type='password' name='password'></input></p>",
				InputLogin: "******",
				InputReset: "<input type='reset'></input></p>",
			}
		} else if check == "ok" {
			loginUser, err := wr.GetSecureCookie("user")

			// check cookie if you logout and backward in your browser
			if err && loginUser != "off" {
				log.Println("DEBUG Login check Secure Cookie: ", loginUser)
				return &LoginBox{
					Invalid:    "<p><input name='logout' value='on' type='hidden'></p>",
					Userid:     "<p>You are logged as: " + loginUser + "</p>",
					Passwordid: "",
					InputLogin: "******",
					InputReset: "<p><li><a href='admin'>Administration</a></li></p>",
				}
			} else {

				// You logged out or trying to pass check=ok by hand
				return &LoginBox{
					Invalid:    "<p><font color='#FF0000'><b>INVALID USER</b></font></p>",
					Userid:     "<p>User:  <input maxlength='15' size='16' name='username'></input></p>",
					Passwordid: "<p>Password: <input maxlength='10' size='13' type='password' name='password'></input></p>",
					InputLogin: "******",
					InputReset: "<input type='reset'></input></p>",
				}
			}
		} else if check == "out" {
			return &LoginBox{
				Invalid:    "<p><font color='#FF0000'><b>Logout</b></font></p>",
				Userid:     "<p>User:  <input maxlength='15' size='16' name='username'></input></p>",
				Passwordid: "<p>Password: <input maxlength='10' size='13' type='password' name='password'></input></p>",
				InputLogin: "******",
				InputReset: "<input type='reset'></input></p>",
			}
		}
	}

	// Trying to look for if you're already logged
	loginUser, err := wr.GetSecureCookie("user")
	if err && loginUser != "off" {
		log.Println("DEBUG Login check Secure Cookie: ", loginUser)
		return &LoginBox{
			Invalid:    "<p><input name='logout' value='on' type='hidden'></p>",
			Userid:     "<p>You are logged as: " + loginUser + "</p>",
			Passwordid: "",
			InputLogin: "******",
			InputReset: "<p><li><a href='admin'>Administration</a></li></p>",
		}
	} else {
		return &LoginBox{
			Userid:     "<p>User:  <input maxlength='15' size='16' name='username'></input></p>",
			Passwordid: "<p>Password: <input maxlength='10' size='13' type='password' name='password'></input></p>",
			InputLogin: "******",
			InputReset: "<input type='reset'></input></p>",
		}
	}

	// Default (It can only be succeded one time at primary load of index)
	return &LoginBox{
		Userid:     "<p>User:  <input maxlength='15' size='16' name='username'></input></p>",
		Passwordid: "<p>Password: <input maxlength='10' size='13' type='password' name='password'></input></p>",
		InputLogin: "******",
		InputReset: "<input type='reset'></input></p>",
	}
}