Esempio n. 1
0
func GetAuth(req *http.Request) (couchdb.Auth, error) {
	//Check if we have a session cookie first
	sessCookie, err := req.Cookie("AuthSession")
	if err != nil {
		return nil, err
	} else if sessCookie.Value == "" {
		return nil, http.ErrNoCookie
	}
	//Attempt to load auth from auth service
	authEndpoint, err := registry.GetServiceLocation("auth")
	if err != nil {
		return nil, err
	}
	reqUrl := authEndpoint + "/api/v1/auth"
	request, err := http.NewRequest("GET", reqUrl, nil)
	if err != nil {
		return nil, err
	}
	client := &http.Client{}
	request.AddCookie(sessCookie)
	request.Header.Add("Accept", "application/json")
	resp, err := client.Do(request)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	//The response body should contain our Auth object
	auth := WikifeatAuth{}
	if err = util.DecodeJsonData(resp.Body, &auth); err != nil {
		return nil, err
	} else {
		return &auth, nil
	}
}
Esempio n. 2
0
func wikiHandler(w http.ResponseWriter, r *http.Request) {
	if endpoint, err := registry.GetServiceLocation("wikis"); err != nil {
		log.Println("No Available Wiki Services!")
		w.WriteHeader(http.StatusServiceUnavailable)
	} else {
		reverseProxy(endpoint, w, r)
	}
}
Esempio n. 3
0
//Request a password reset (forgot password, etc).
func (um *UserManager) RequestPasswordReset(id string) error {
	//Read the user
	user := User{}
	userDb := Connection.SelectDB(UserDbName, AdminAuth)
	rev, err := userDb.Read(UserPrefix+id, &user, nil)
	if err != nil {
		return err
	}
	//Generate a token
	tok := util.GenToken()
	//Set token expiration time
	nowTime := time.Now().UTC()
	//Tokens are good for 4 hours
	hours := time.Duration(4) * time.Hour
	expireTime := nowTime.Add(hours)
	user.PassResetToken.Token = tok
	user.PassResetToken.Expires = expireTime
	//Now save the user
	log.Println("Saving reset token to user document")
	rev, err = um.Update(id, rev, &user, GetAdminUser())
	if err != nil {
		return err
	}
	//Now we need to send an email to the user containing our token
	notifEndpoint, err := registry.GetServiceLocation("notifications")
	if err != nil {
		return err
	}
	nr := NotificationRequest{
		To:      user.Public.Contact.Email,
		Subject: "Reset Password Request",
		Data: map[string]string{
			"user": user.Public.FirstName,
			"uri": "/reset_password?user="******"&token=" + tok,
		},
	}
	nrJson, _, err := util.EncodeJsonData(&nr)
	if err != nil {
		return err
	}
	//Assemble the request
	reqUrl := notifEndpoint + "/api/v1/notifications/reset_password/send"
	client := &http.Client{}
	request, err := http.NewRequest("POST", reqUrl, nrJson)
	if err != nil {
		return err
	}
	request.Header.Add("Content-Type", "application/json")
	resp, err := client.Do(request)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	return nil
}