Exemplo n.º 1
0
Arquivo: auth.go Projeto: eluleci/dock
	}

	existingAccount, _ := getAccountData(requestWrapper, dbAdapter)
	if existingAccount != nil {
		err = &utils.Error{http.StatusConflict, "User with same email-username already exists."}
		return
	}

	hashedPassword, hashErr := bcrypt.GenerateFromPassword([]byte(password.(string)), bcrypt.DefaultCost)
	if hashErr != nil {
		err = &utils.Error{http.StatusInternalServerError, "Hashing password failed."}
		return
	}
	requestWrapper.Message.Body["password"] = string(hashedPassword)

	response, hookBody, err = adapters.Create(ClassUsers, requestWrapper.Message.Body)
	return
}

var handleFacebookAuth = func(requestWrapper messages.RequestWrapper, dbAdapter *adapters.MongoAdapter, HTTPClient *http.Client) (response map[string]interface{}, hookBody map[string]interface{}, err *utils.Error) {

	facebookData, _ := requestWrapper.Message.Body["facebook"]
	facebookDataAsMap := facebookData.(map[string]interface{})

	userId, hasId := facebookDataAsMap["id"]
	accessToken, hasAccessToken := facebookDataAsMap["accessToken"]

	if !hasId || !hasAccessToken {
		err = &utils.Error{http.StatusBadRequest, "Facebook data must contain id and access token."}
		return
	}
Exemplo n.º 2
0
var handlePost = func(a *Actor, requestWrapper messages.RequestWrapper, user interface{}) (response messages.Message, hookBody map[string]interface{}, err *utils.Error) {

	if strings.EqualFold(a.res, ResourceRegister) { // sign up request
		response, hookBody, err = auth.HandleSignUp(requestWrapper, a.adapter)
	} else if strings.EqualFold(a.res, ResourceLogin) { // login request
		response, err = auth.HandleLogin(requestWrapper, a.adapter)
	} else if strings.EqualFold(a.res, ResourceChangePassword) { // reset password
		response, err = auth.HandleChangePassword(requestWrapper, a.adapter, user)
	} else if strings.EqualFold(a.res, ResourceResetPassword) { // reset password
		response, err = auth.HandleResetPassword(requestWrapper, a.adapter)
	} else if strings.EqualFold(a.res, ResourceTypeUsers) { // post on users not allowed
		response.Status = http.StatusMethodNotAllowed
	} else if strings.EqualFold(a.actorType, ActorTypeCollection) { // create object request
		if !strings.EqualFold(a.class, ClassFiles) {
			response.Body, hookBody, err = adapters.Create(a.class, requestWrapper.Message.Body)
		} else {
			response.Body, hookBody, err = adapters.CreateFile(requestWrapper.Message.ReqBodyRaw)
		}

		if err == nil {
			response.Status = http.StatusCreated
		}
	} else if strings.EqualFold(a.actorType, ActorTypeModel) { // post on objects are not allowed
		response.Status = http.StatusBadRequest
	}
	return
}

var handlePut = func(a *Actor, requestWrapper messages.RequestWrapper) (response messages.Message, hookBody map[string]interface{}, err *utils.Error) {