Compare commits
No commits in common. "0fac34edfbae1373b19fb9831d70d3ca2e543d55" and "378c60cef8b704527d587507e40a8840c3afa38a" have entirely different histories.
0fac34edfb
...
378c60cef8
@ -17,6 +17,7 @@ type Account struct {
|
|||||||
|
|
||||||
Name string `json:"name" gorm:"uniqueIndex"`
|
Name string `json:"name" gorm:"uniqueIndex"`
|
||||||
Nick string `json:"nick"`
|
Nick string `json:"nick"`
|
||||||
|
Description string `json:"description"`
|
||||||
Avatar *string `json:"avatar"`
|
Avatar *string `json:"avatar"`
|
||||||
Banner *string `json:"banner"`
|
Banner *string `json:"banner"`
|
||||||
ConfirmedAt *time.Time `json:"confirmed_at"`
|
ConfirmedAt *time.Time `json:"confirmed_at"`
|
||||||
@ -38,9 +39,6 @@ type Account struct {
|
|||||||
Factors []AuthFactor `json:"factors,omitempty"`
|
Factors []AuthFactor `json:"factors,omitempty"`
|
||||||
|
|
||||||
Relations []AccountRelationship `json:"relations,omitempty" gorm:"foreignKey:AccountID"`
|
Relations []AccountRelationship `json:"relations,omitempty" gorm:"foreignKey:AccountID"`
|
||||||
|
|
||||||
// Keep this for backward compability
|
|
||||||
Description string `json:"description" gorm:"-"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v Account) GetAvatar() *string {
|
func (v Account) GetAvatar() *string {
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AuthConfig struct {
|
type AuthConfig struct {
|
||||||
AlwaysRisky bool `json:"always_risky"`
|
|
||||||
MaximumAuthSteps int `json:"maximum_auth_steps" validate:"required,min=1,max=99"`
|
MaximumAuthSteps int `json:"maximum_auth_steps" validate:"required,min=1,max=99"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,5 @@ type Badge struct {
|
|||||||
|
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Metadata datatypes.JSONMap `json:"metadata"`
|
Metadata datatypes.JSONMap `json:"metadata"`
|
||||||
IsActive bool `json:"is_active"`
|
|
||||||
AccountID uint `json:"account_id"`
|
AccountID uint `json:"account_id"`
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gorm.io/datatypes"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccountProfile struct {
|
type AccountProfile struct {
|
||||||
@ -11,21 +9,8 @@ type AccountProfile struct {
|
|||||||
|
|
||||||
FirstName string `json:"first_name"`
|
FirstName string `json:"first_name"`
|
||||||
LastName string `json:"last_name"`
|
LastName string `json:"last_name"`
|
||||||
Description string `json:"description"`
|
|
||||||
TimeZone string `json:"time_zone"`
|
|
||||||
Location string `json:"location"`
|
|
||||||
Pronouns string `json:"pronouns"`
|
|
||||||
Gender string `json:"gender"`
|
|
||||||
Links datatypes.JSONMap `json:"links"`
|
|
||||||
Experience uint64 `json:"experience"`
|
Experience uint64 `json:"experience"`
|
||||||
LastSeenAt *time.Time `json:"last_seen_at"`
|
LastSeenAt *time.Time `json:"last_seen_at"`
|
||||||
Birthday *time.Time `json:"birthday"`
|
Birthday *time.Time `json:"birthday"`
|
||||||
AccountID uint `json:"account_id"`
|
AccountID uint `json:"account_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountPage struct {
|
|
||||||
BaseModel
|
|
||||||
|
|
||||||
Content string `json:"content"`
|
|
||||||
AccountID uint `json:"account_id"`
|
|
||||||
}
|
|
||||||
|
@ -13,23 +13,3 @@ func GrantBadge(user models.Account, badge models.Badge) error {
|
|||||||
func RevokeBadge(badge models.Badge) error {
|
func RevokeBadge(badge models.Badge) error {
|
||||||
return database.C.Delete(&badge).Error
|
return database.C.Delete(&badge).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func ActiveBadge(badge models.Badge) error {
|
|
||||||
accountId := badge.AccountID
|
|
||||||
tx := database.C.Begin()
|
|
||||||
|
|
||||||
if err := tx.Model(&badge).Where("account_id = ?", accountId).Update("is_active", false).Error; err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := tx.Model(&badge).Where("id = ?", badge.ID).Update("is_active", true).Error; err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := tx.Commit().Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -123,11 +123,6 @@ func updateUserinfo(c *fiber.Ctx) error {
|
|||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
FirstName string `json:"first_name"`
|
FirstName string `json:"first_name"`
|
||||||
LastName string `json:"last_name"`
|
LastName string `json:"last_name"`
|
||||||
Location string `json:"location"`
|
|
||||||
TimeZone string `json:"time_zone"`
|
|
||||||
Gender string `json:"gender"`
|
|
||||||
Pronouns string `json:"pronouns"`
|
|
||||||
Links map[string]string `json:"links"`
|
|
||||||
Birthday time.Time `json:"birthday"`
|
Birthday time.Time `json:"birthday"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,18 +143,8 @@ func updateUserinfo(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var links = make(map[string]any)
|
|
||||||
for k, v := range data.Links {
|
|
||||||
links[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
account.Nick = data.Nick
|
account.Nick = data.Nick
|
||||||
account.Profile.Gender = data.Gender
|
account.Description = data.Description
|
||||||
account.Profile.Pronouns = data.Pronouns
|
|
||||||
account.Profile.Location = data.Location
|
|
||||||
account.Profile.TimeZone = data.TimeZone
|
|
||||||
account.Profile.Links = links
|
|
||||||
account.Profile.Description = data.Description
|
|
||||||
account.Profile.FirstName = data.FirstName
|
account.Profile.FirstName = data.FirstName
|
||||||
account.Profile.LastName = data.LastName
|
account.Profile.LastName = data.LastName
|
||||||
account.Profile.Birthday = &data.Birthday
|
account.Profile.Birthday = &data.Birthday
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
|
||||||
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
|
|
||||||
"git.solsynth.dev/hypernet/passport/pkg/internal/services"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
func listUserBadge(c *fiber.Ctx) error {
|
|
||||||
if err := sec.EnsureAuthenticated(c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
user := c.Locals("user").(models.Account)
|
|
||||||
|
|
||||||
var badges []models.Badge
|
|
||||||
if err := database.C.Where("account_id = ?", user.ID).Find(&badges).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(badges)
|
|
||||||
}
|
|
||||||
|
|
||||||
func activeUserBadge(c *fiber.Ctx) error {
|
|
||||||
if err := sec.EnsureAuthenticated(c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
user := c.Locals("user").(models.Account)
|
|
||||||
|
|
||||||
badgeId, _ := c.ParamsInt("badgeId", 0)
|
|
||||||
|
|
||||||
var badge models.Badge
|
|
||||||
if err := database.C.Where("id = ? AND account_id = ?", badgeId, user.ID).First(&badge).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := services.ActiveBadge(badge); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return c.SendStatus(fiber.StatusOK)
|
|
||||||
}
|
|
@ -37,12 +37,6 @@ func MapControllers(app *fiber.App, baseURL string) {
|
|||||||
preferences.Put("/notifications", updateNotificationPreference)
|
preferences.Put("/notifications", updateNotificationPreference)
|
||||||
}
|
}
|
||||||
|
|
||||||
badges := api.Group("/badges").Name("Badges")
|
|
||||||
{
|
|
||||||
badges.Get("/me", listUserBadge)
|
|
||||||
badges.Post("/:badgeId/active", activeUserBadge)
|
|
||||||
}
|
|
||||||
|
|
||||||
reports := api.Group("/reports").Name("Reports API")
|
reports := api.Group("/reports").Name("Reports API")
|
||||||
{
|
{
|
||||||
abuse := reports.Group("/abuse").Name("Abuse Reports")
|
abuse := reports.Group("/abuse").Name("Abuse Reports")
|
||||||
@ -80,9 +74,6 @@ func MapControllers(app *fiber.App, baseURL string) {
|
|||||||
me.Put("/status", editStatus)
|
me.Put("/status", editStatus)
|
||||||
me.Delete("/status", clearStatus)
|
me.Delete("/status", clearStatus)
|
||||||
|
|
||||||
me.Get("/pages", getOwnAccountPage)
|
|
||||||
me.Put("/pages", updateAccountPage)
|
|
||||||
|
|
||||||
contacts := me.Group("/contacts").Name("Contacts")
|
contacts := me.Group("/contacts").Name("Contacts")
|
||||||
{
|
{
|
||||||
contacts.Get("/", listContact)
|
contacts.Get("/", listContact)
|
||||||
@ -126,7 +117,6 @@ func MapControllers(app *fiber.App, baseURL string) {
|
|||||||
{
|
{
|
||||||
directory.Get("/", getOtherUserinfo)
|
directory.Get("/", getOtherUserinfo)
|
||||||
directory.Get("/status", getStatus)
|
directory.Get("/status", getStatus)
|
||||||
directory.Get("/pages", getAccountPage)
|
|
||||||
|
|
||||||
directory.Get("/check-in", listOtherUserCheckInRecord)
|
directory.Get("/check-in", listOtherUserCheckInRecord)
|
||||||
}
|
}
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
|
||||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
|
||||||
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
|
|
||||||
"git.solsynth.dev/hypernet/passport/pkg/internal/web/exts"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getAccountPage(c *fiber.Ctx) error {
|
|
||||||
alias := c.Params("alias")
|
|
||||||
|
|
||||||
tx := database.C.Where("name = ?", alias)
|
|
||||||
|
|
||||||
numericId, err := strconv.Atoi(alias)
|
|
||||||
if err == nil {
|
|
||||||
tx = tx.Or("id = ?", numericId)
|
|
||||||
}
|
|
||||||
|
|
||||||
var account models.Account
|
|
||||||
if err := tx.First(&account).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
var page models.AccountPage
|
|
||||||
if err := database.C.Where("account_id = ?", account.ID).First(&page).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(page)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getOwnAccountPage(c *fiber.Ctx) error {
|
|
||||||
if err := sec.EnsureAuthenticated(c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
user := c.Locals("user").(models.Account)
|
|
||||||
|
|
||||||
var page models.AccountPage
|
|
||||||
if err := database.C.Where("account_id = ?", user.ID).First(&page).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(page)
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateAccountPage(c *fiber.Ctx) error {
|
|
||||||
if err := sec.EnsureAuthenticated(c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
user := c.Locals("user").(models.Account)
|
|
||||||
|
|
||||||
var data struct {
|
|
||||||
Content string `json:"content" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
var page models.AccountPage
|
|
||||||
if err := database.C.Where("account_id = ?", user.ID).First(&page).Error; err != nil {
|
|
||||||
page = models.AccountPage{
|
|
||||||
AccountID: user.ID,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
page.Content = data.Content
|
|
||||||
|
|
||||||
if err := database.C.Save(&page).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(page)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user