Esempio n. 1
0
//ShowRegistrationForm shows the user registration page
func (service *Service) ShowRegistrationForm(w http.ResponseWriter, request *http.Request) {
	validationErrors := make([]string, 0, 0)

	token, err := totp.NewToken()
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	totpsession, err := service.GetSession(request, SessionForRegistration, "totp")
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	totpsession.Values["secret"] = token.Secret

	service.renderRegistrationFrom(w, request, validationErrors, token.Secret)
}
Esempio n. 2
0
func (service *Service) GetConfig(w http.ResponseWriter, request *http.Request) {
	token, err := totp.NewToken()
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	totpsession, err := service.GetSession(request, SessionForRegistration, "totp")
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	totpsession.Values["secret"] = token.Secret
	sessions.Save(request, w)
	data := struct {
		TotpSecret       string `json:"totpsecret"`
		GithubClientId   string `json:"githubclientid"`
		FacebookClientId string `json:"facebookclientid"`
	}{}
	data.TotpSecret = token.Secret
	data.GithubClientId, _ = identityservice.GetOauthClientID("github")
	data.FacebookClientId, _ = identityservice.GetOauthClientID("facebook")
	json.NewEncoder(w).Encode(&data)
}