// UpdatePassword helps to update the password of the user, it acts as a resetPassword when isAdminBeingReset is set to true
UpdatePassword helps to update the password of the user, it acts as a resetPassword when isAdminBeingReset is set to true
// UpdatePassword helps to update the password of the user it acts as a resetPassword when isAdminBeingReset is set to true
func (r repository) UpdatePassword(userPassword *entities.UserPassword, isAdminBeingReset bool, ctx context.Context) error {
	var result = entities.User{}
	result.UserName = userPassword.Username
	findOneErr := r.Collection.FindOne(ctx, bson.M{
		"username": result.UserName,
	}).Decode(&result)
	if findOneErr != nil {
		return findOneErr
	}
	if isAdminBeingReset {
		err := bcrypt.CompareHashAndPassword([]byte(result.Password), []byte(userPassword.OldPassword))
		if err != nil {
			return err
		}
	}
	newHashedPassword, err := bcrypt.GenerateFromPassword([]byte(userPassword.NewPassword), utils.PasswordEncryptionCost)
	_, err = r.Collection.UpdateOne(context.Background(), bson.M{"_id": result.ID}, bson.M{"$set": bson.M{
		"password": string(newHashedPassword),
	}})
	if err != nil {
		return err
	}
	return nil
}
func ( r repository ) UpdatePassword ( userPassword * entities . UserPassword , isAdminBeingReset bool , ctx context . Context ) error { var result = entities . User { } result . UserName = userPassword . Username findOneErr := r . Collection . FindOne ( ctx , bson . M { " " : result . UserName , } ) . Decode ( & result ) if findOneErr != nil { return findOneErr } if isAdminBeingReset { err := bcrypt . CompareHashAndPassword ( [ ] byte ( result . Password ) , [ ] byte ( userPassword . OldPassword ) ) if err != nil { return err } } newHashedPassword , err := bcrypt . GenerateFromPassword ( [ ] byte ( userPassword . NewPassword ) , utils . PasswordEncryptionCost ) _ , err = r . Collection . UpdateOne ( context . Background ( ) , bson . M { " " : result . ID } , bson . M { " " : bson . M { " " : string ( newHashedPassword ) , } } ) if err != nil { return err } return nil }
UpdatePassword helps to update the password of the user, it acts as a resetPassword when isAdminBeingReset is set to true
UpdatePassword helps to update the password of the user it acts as a resetPassword when isAdminBeingReset is set to true