2023-08-08 10:28:43 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
2024-10-31 19:32:54 +00:00
|
|
|
|
|
|
|
"git.coopgo.io/coopgo-apps/silvermobi/models"
|
2023-08-08 10:28:43 +00:00
|
|
|
)
|
|
|
|
|
2024-10-31 19:32:54 +00:00
|
|
|
func (h *SilverMobiHandler) Login(ctx context.Context, username string, password string) (jwt string, err error) {
|
|
|
|
var (
|
|
|
|
account *models.Account
|
|
|
|
pTTL time.Duration
|
|
|
|
)
|
|
|
|
|
|
|
|
if account, err = h.Services.MobilityAccounts.Login(ctx, username, password, "silvermobi"); err != nil {
|
2023-08-08 10:28:43 +00:00
|
|
|
return
|
|
|
|
}
|
2024-10-31 19:32:54 +00:00
|
|
|
|
2023-08-08 10:28:43 +00:00
|
|
|
key := h.Config.GetString("identification.local.jwt_secret")
|
|
|
|
ttl := h.Config.GetString("identification.local.ttl")
|
2024-10-31 19:32:54 +00:00
|
|
|
|
|
|
|
if pTTL, err = time.ParseDuration(ttl); err != nil {
|
2023-08-08 10:28:43 +00:00
|
|
|
return "", err
|
|
|
|
}
|
2024-10-31 19:32:54 +00:00
|
|
|
|
|
|
|
return account.CreateToken(pTTL, key)
|
2023-08-08 10:28:43 +00:00
|
|
|
}
|
|
|
|
|
2024-10-31 19:32:54 +00:00
|
|
|
func (h *SilverMobiHandler) Register(ctx context.Context, username string, password string, email string,
|
2024-11-01 00:23:34 +00:00
|
|
|
phoneNumber string, firstName string, lastName string) (jwt string, err error) {
|
2024-10-31 19:32:54 +00:00
|
|
|
|
|
|
|
var (
|
|
|
|
account *models.Account
|
|
|
|
pTTL time.Duration
|
|
|
|
)
|
|
|
|
|
|
|
|
if account, err = h.Services.MobilityAccounts.Register(
|
2023-08-08 10:28:43 +00:00
|
|
|
ctx,
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
email,
|
2024-11-01 00:23:34 +00:00
|
|
|
phoneNumber,
|
2023-08-08 10:28:43 +00:00
|
|
|
map[string]any{
|
2024-11-01 00:23:34 +00:00
|
|
|
"first_name": firstName,
|
|
|
|
"last_name": lastName,
|
2023-08-08 10:28:43 +00:00
|
|
|
"email": email,
|
2024-11-01 00:23:34 +00:00
|
|
|
"phone_number": phoneNumber,
|
2023-08-08 10:28:43 +00:00
|
|
|
},
|
|
|
|
"silvermobi",
|
2024-10-31 19:32:54 +00:00
|
|
|
); err != nil {
|
2023-08-08 10:28:43 +00:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
key := h.Config.GetString("identification.local.jwt_secret")
|
|
|
|
ttl := h.Config.GetString("identification.local.ttl")
|
|
|
|
|
2024-10-31 19:32:54 +00:00
|
|
|
if pTTL, err = time.ParseDuration(ttl); err != nil {
|
2023-08-08 10:28:43 +00:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2024-10-31 19:32:54 +00:00
|
|
|
return account.CreateToken(pTTL, key)
|
2023-08-08 10:28:43 +00:00
|
|
|
}
|