Private
Public Access
primeros cambios hechos para tener el multitenant
This commit is contained in:
1 parent
34ad4424f9
commit
4e082e8767
132 files changed
+6202
-762
No files matched your search
@@ -0,0 +1,59 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"repuestera_back/jwtutils"
|
||||
)
|
||||
|
||||
// EnviarEmailInvitacion intenta notificar la invitación usando el servicio
|
||||
// comms. Un fallo de email no invalida la invitación: el link se devuelve al
|
||||
// administrador para que pueda compartirlo.
|
||||
func EnviarEmailInvitacion(destino, empresa, rol, link string, creadorID uint) bool {
|
||||
base := strings.TrimRight(os.Getenv("COMMS_URL"), "/")
|
||||
if base == "" {
|
||||
base = "http://comms:8088"
|
||||
}
|
||||
|
||||
token, err := jwtutils.GenerarToken(
|
||||
creadorID, 0, "", true, "", "repuestera", jwtutils.TokenTypeAccess, nil, 5*time.Minute,
|
||||
)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
descripcion := fmt.Sprintf(
|
||||
"<p>Fuiste invitado a <strong>%s</strong> con el rol <strong>%s</strong>.</p>"+
|
||||
"<p><a href=\"%s\">Aceptar invitación</a></p>"+
|
||||
"<p>Si el enlace no funciona, copiá esta dirección: %s</p>",
|
||||
empresa, rol, link, link,
|
||||
)
|
||||
|
||||
cuerpo, _ := json.Marshal(map[string]any{
|
||||
"titulo": "Invitación a " + empresa,
|
||||
"descripcion": descripcion,
|
||||
"items": []string{},
|
||||
"to": []string{destino},
|
||||
})
|
||||
|
||||
cliente := &http.Client{Timeout: 5 * time.Second}
|
||||
req, err := http.NewRequest(http.MethodPost, base+"/email", bytes.NewReader(cuerpo))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
resp, err := cliente.Do(req)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
return resp.StatusCode >= 200 && resp.StatusCode < 300
|
||||
}
|
||||
Reference in new issue
Block a user