mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
changing contact token format
This commit is contained in:
parent
bbdc4ed722
commit
4082476d73
@ -115,15 +115,27 @@ func BearerAppToken(r *http.Request, detail bool) (*store.Account, int, error) {
|
||||
return &app.Account, http.StatusOK, nil
|
||||
}
|
||||
|
||||
func ParseToken(token string) (string, string, error) {
|
||||
split := strings.Split(token, ":")
|
||||
if len(split) != 2 {
|
||||
return "", "", errors.New("invalid token format")
|
||||
}
|
||||
return split[0], split[1], nil
|
||||
}
|
||||
|
||||
func BearerContactToken(r *http.Request) (*store.Card, int, error) {
|
||||
|
||||
// parse bearer authentication
|
||||
auth := r.Header.Get("Authorization")
|
||||
token := strings.TrimSpace(strings.TrimPrefix(auth, "Bearer"))
|
||||
target, access, err := ParseToken(token)
|
||||
if err != nil {
|
||||
return nil, http.StatusBadRequest, err
|
||||
}
|
||||
|
||||
// find token record
|
||||
var card store.Card
|
||||
if err := store.DB.Preload("Account").Where("InToken = ?", token).First(&card).Error; err != nil {
|
||||
if err := store.DB.Preload("Account").Where("account_id = ? AND InToken = ?", target, access).First(&card).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, http.StatusNotFound, err
|
||||
} else {
|
||||
|
@ -70,7 +70,7 @@ func SendLocalNotification(notification *store.Notification) {
|
||||
}
|
||||
|
||||
func SendRemoteNotification(notification *store.Notification) {
|
||||
PrintMsg(notification)
|
||||
// TODO send remote notification
|
||||
}
|
||||
|
||||
// notify all cards of profile change
|
||||
|
@ -87,12 +87,12 @@ type AccountDetail struct {
|
||||
|
||||
type App struct {
|
||||
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
||||
AccountID string `gorm:"index"`
|
||||
AccountID string `gorm:"not null;index:appguid,unique"`
|
||||
Name string
|
||||
Description string
|
||||
Image string
|
||||
Url string
|
||||
Token string `gorm:"not null;index"`
|
||||
Token string `gorm:"not null;index:appguid,unique"`
|
||||
Created int64 `gorm:"autoCreateTime"`
|
||||
Account Account `gorm:"references:Guid"`
|
||||
}
|
||||
@ -124,8 +124,8 @@ type Label struct {
|
||||
type Card struct {
|
||||
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
||||
CardId string `gorm:"not null;index:card,unique"`
|
||||
AccountID string `gorm:"not null;index:card,unique;index:guid,unqiue"`
|
||||
Guid string `gorm:"not null;index:guid,unique"`
|
||||
AccountID string `gorm:"not null;index:card,unique"`
|
||||
Guid string `gorm:"not null;index:cardguid,unique"`
|
||||
Username string
|
||||
Name string
|
||||
Description string
|
||||
@ -135,7 +135,7 @@ type Card struct {
|
||||
Node string `gorm:"not null"`
|
||||
ProfileRevision int64 `gorm:"not null"`
|
||||
Status string `gorm:"not null"`
|
||||
InToken string
|
||||
InToken string `gorm:"not null;index:cardguid,unique"`
|
||||
OutToken string
|
||||
Notes string
|
||||
DataRevision int64 `gorm:"not null"`
|
||||
@ -144,8 +144,8 @@ type Card struct {
|
||||
ViewRevision int64 `gorm:"not null"`
|
||||
RemoteProfile int64
|
||||
RemoteContent int64
|
||||
Account Account `gorm:"references:Guid"`
|
||||
Groups []Group `gorm:"many2many:card_groups;"`
|
||||
Account Account `gorm:"references:Guid"`
|
||||
}
|
||||
|
||||
type CardGroup struct {
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
|
||||
func TestAddAccount(t *testing.T) {
|
||||
|
||||
PrintMsg("ADD")
|
||||
|
||||
// acquire new token for creating accounts
|
||||
r, w, _ := NewRequest("POST", "/admin/accounts", nil)
|
||||
SetBasicAuth(r, "admin:pass");
|
||||
|
Loading…
Reference in New Issue
Block a user