コード例 #1
0
ファイル: auth.go プロジェクト: eluleci/dock
	existingPassword := userAsMap["password"].(string)

	passwordError := bcrypt.CompareHashAndPassword([]byte(existingPassword), []byte(password.(string)))
	if passwordError != nil {
		err = &utils.Error{http.StatusUnauthorized, "Existing password is not correct."}
		return
	}

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

	body := map[string]interface{}{"password": string(hashedPassword)}
	response.Body, _, err = adapters.Update(ClassUsers, userAsMap["_id"].(string), body)
	if err != nil {
		return
	}

	return
}

var HandleResetPassword = func(requestWrapper messages.RequestWrapper, dbAdapter *adapters.MongoAdapter) (response messages.Message, err *utils.Error) {

	resetPasswordConfig := config.SystemConfig.ResetPassword
	if resetPasswordConfig == nil {
		err = &utils.Error{http.StatusInternalServerError, "Email reset configuration is not set in configuration file."}
	}

	senderEmail, hasSenderEmail := config.SystemConfig.ResetPassword["senderEmail"]
コード例 #2
0
ファイル: actor.go プロジェクト: eluleci/dock
		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) {

	if strings.EqualFold(a.actorType, ActorTypeCollection) { // put on resources are not allowed
		response.Status = http.StatusBadRequest
	} else if strings.EqualFold(a.actorType, ActorTypeModel) { // update object
		id := requestWrapper.Message.Res[strings.LastIndex(requestWrapper.Message.Res, "/")+1:]
		response.Body, hookBody, err = adapters.Update(a.class, id, requestWrapper.Message.Body)
	}
	return
}

var handleDelete = func(a *Actor, requestWrapper messages.RequestWrapper) (response messages.Message, err *utils.Error) {

	if strings.EqualFold(a.actorType, ActorTypeCollection) { // delete on resources are not allowed
		response.Status = http.StatusBadRequest
	} else if strings.EqualFold(a.actorType, ActorTypeModel) { // delete object
		id := requestWrapper.Message.Res[strings.LastIndex(requestWrapper.Message.Res, "/")+1:]
		response.Body, err = adapters.Delete(a.class, id)
		if err == nil {
			response.Status = http.StatusNoContent
		}
	}