Exemple #1
0
func WebPanelKeysPost(w http.ResponseWriter, r *http.Request, ctx *WebContext) (err error) {

	key, secret := domain.GenerateKeyPair(ctx.User)

	ctx.User.AddKey(key)

	bytes, _ := json.Marshal(ctx.User)
	userRepository.SaveUserById(ctx.User.Id, string(bytes))
	userRepository.SaveSecretByKey(key, secret)

	http.Redirect(w, r, "/webapp/panel", http.StatusFound)
	return
}
Exemple #2
0
func KeyCreate(w rest.ResponseWriter, r *rest.Request) {

	user := r.Env["USER"].(*domain.User)

	key, secret := domain.GenerateKeyPair(user)
	user.AddKey(key)

	go func(user *domain.User, key, secret string) {
		bytes, _ := json.Marshal(user)
		userRepository.SaveUserById(user.Id, string(bytes))
		userRepository.SaveSecretByKey(key, secret)
	}(user, key, secret)

	userClone := user.Clone()
	userClone.Pass = ""
	w.WriteHeader(http.StatusCreated)
	w.WriteJson(userClone)
}