✨ User able to re-send the confirm register email
This commit is contained in:
parent
bcb2cd2f9c
commit
45dd50ccba
@ -14,8 +14,9 @@ const (
|
|||||||
type MagicToken struct {
|
type MagicToken struct {
|
||||||
BaseModel
|
BaseModel
|
||||||
|
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Type int8 `json:"type"`
|
Type int8 `json:"type"`
|
||||||
AccountID *uint `json:"account_id"`
|
AccountID *uint `json:"account_id"`
|
||||||
ExpiredAt *time.Time `json:"expired_at"`
|
ExpiredAt *time.Time `json:"expired_at"`
|
||||||
|
LastNotifiedAt *time.Time `json:"last_notified_at"`
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,11 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/localize"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.solsynth.dev/hypernet/nexus/pkg/nex/localize"
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||||
"git.solsynth.dev/hypernet/passport/pkg/internal/gap"
|
"git.solsynth.dev/hypernet/passport/pkg/internal/gap"
|
||||||
"git.solsynth.dev/hypernet/pusher/pkg/pushkit"
|
"git.solsynth.dev/hypernet/pusher/pkg/pushkit"
|
||||||
@ -46,10 +47,15 @@ func NewMagicToken(mode models.MagicTokenType, assignTo *models.Account, expired
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NotifyMagicToken(token models.MagicToken) error {
|
func NotifyMagicToken(token models.MagicToken, skipCheck ...bool) error {
|
||||||
if token.AccountID == nil {
|
if token.AccountID == nil {
|
||||||
return fmt.Errorf("could notify a non-assign magic token")
|
return fmt.Errorf("could notify a non-assign magic token")
|
||||||
}
|
}
|
||||||
|
if token.LastNotifiedAt != nil && (len(skipCheck) == 0 || !skipCheck[0]) {
|
||||||
|
if token.LastNotifiedAt.Unix() >= time.Now().Add(-60*time.Minute).Unix() {
|
||||||
|
return fmt.Errorf("magic token has been notified in an hour")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var user models.Account
|
var user models.Account
|
||||||
if err := database.C.Where(&models.Account{
|
if err := database.C.Where(&models.Account{
|
||||||
@ -93,5 +99,10 @@ func NotifyMagicToken(token models.MagicToken) error {
|
|||||||
HTML: &content,
|
HTML: &content,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
database.C.Model(&token).Update("last_notified_at", time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -265,6 +265,24 @@ func doRegisterConfirm(c *fiber.Ctx) error {
|
|||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reNotifyRegisterConfirm(c *fiber.Ctx) error {
|
||||||
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
|
var magicToken models.MagicToken
|
||||||
|
if err := database.C.Where("account_id = ? AND type = ?", user.ID, models.ConfirmMagicToken).First(&magicToken).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := services.NotifyMagicToken(magicToken); err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
func requestDeleteAccount(c *fiber.Ctx) error {
|
func requestDeleteAccount(c *fiber.Ctx) error {
|
||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -71,9 +71,10 @@ func MapControllers(app *fiber.App, baseURL string) {
|
|||||||
me.Put("/language", updateAccountLanguage)
|
me.Put("/language", updateAccountLanguage)
|
||||||
me.Get("/events", getEvents)
|
me.Get("/events", getEvents)
|
||||||
me.Get("/tickets", getTickets)
|
me.Get("/tickets", getTickets)
|
||||||
me.Delete("/tickets/:ticketId", killTicket)
|
me.Delete("/tickets/:ticketId", deleteTicket)
|
||||||
|
|
||||||
me.Post("/confirm", doRegisterConfirm)
|
me.Post("/confirm", doRegisterConfirm)
|
||||||
|
me.Patch("/confirm", reNotifyRegisterConfirm)
|
||||||
|
|
||||||
me.Get("/status", getMyselfStatus)
|
me.Get("/status", getMyselfStatus)
|
||||||
me.Post("/status", setStatus)
|
me.Post("/status", setStatus)
|
||||||
|
@ -39,7 +39,7 @@ func getTickets(c *fiber.Ctx) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func killTicket(c *fiber.Ctx) error {
|
func deleteTicket(c *fiber.Ctx) error {
|
||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user