Example #1
0
func (httpContext *httpContextDef) handleGameRequest(res http.ResponseWriter, req *http.Request) {
	var act string

	req.ParseForm()

	act = req.Form.Get(_actParam)

	switch act {
	case "":
		httpContext.handleGameInitial(res, req)
		return
	default:
		gklog.LogError("unknown act")
		httpContext.redirectToError("unknown act", res, req)
		return
	}
}
Example #2
0
func (httpContext *httpContextDef) ServeHTTP(res http.ResponseWriter, req *http.Request) {
	if _gameTemplate == nil {
		gklog.LogError("missing call to gameInit")
	}

	path := req.URL.Path

	gklog.LogTrace(req.Method)
	gklog.LogTrace(path)

	if req.Method == _methodGet || req.Method == _methodPost {
		if gknet.RequestMatches(path, _gameRequest) {
			httpContext.handleGameRequest(res, req)
		} else {
			http.NotFound(res, req)
		}
	} else {
		http.NotFound(res, req)
	}
}
Example #3
0
func (loginConfig *loginConfigDef) ServeHTTP(res http.ResponseWriter, req *http.Request) {
	if _loginTemplate == nil {
		gklog.LogError("missing call to loginInit")
	}

	path := req.URL.Path

	gklog.LogTrace(req.Method)
	gklog.LogTrace(path)

	if req.Method == _methodGet || req.Method == _methodPost {
		if gknet.RequestMatches(path, _loginServer) {
			handleLogin(loginConfig, res, req)
		} else {
			http.NotFound(res, req)
		}
	} else {
		http.NotFound(res, req)
	}

}
Example #4
0
func handleLogin(loginConfig *loginConfigDef, res http.ResponseWriter, req *http.Request) {
	var act string
	var userName string
	var password string
	var email string
	var token string

	req.ParseForm()

	act = req.Form.Get(_actParam)
	userName = req.Form.Get(_userNameParam)
	password = req.Form.Get(_passwordParam)
	email = req.Form.Get(_emailParam)
	token = req.Form.Get(_tokenParam)

	// for security sleep on password attempt
	time.Sleep(sec.GetSleepDurationPasswordAttempt())

	gklog.LogTrace("act: " + act)

	switch act {
	case "":
		var login string

		login = req.Form.Get(_loginParam)

		if login != "" {
			handleLoginLogin(loginConfig, res, req, userName, password)
			return
		}

		handleLoginInitial(loginConfig, res, req)
		return
	case "login":
		var register string
		var forgotPassword string

		register = req.Form.Get(_registerParam)
		forgotPassword = req.Form.Get(_forgotPasswordParam)

		if register != "" {
			handleLoginRegisterInitial(loginConfig, res, req, userName)
			return
		}

		if forgotPassword != "" {
			handleLoginForgotPasswordInitial(loginConfig, res, req)
			return
		}

		if userName == "" {
			handleLoginInitial(loginConfig, res, req)
			return
		}
		handleLoginLogin(loginConfig, res, req, userName, password)
		return
	case "register":
		handleLoginRegister(loginConfig, res, req, userName, password, email)
	case "forgot_password":
		handleLoginForgotPassword(loginConfig, res, req, userName)
	case "reset_password":
		handleLoginResetPassword(loginConfig, res, req, token, userName, password)
	default:
		gklog.LogError("unknown act")
		redirectToError("unknown act", res, req)
		return
	}
}