bot: Add linking command

This commit is contained in:
Kevin Kandlbinder 2022-03-24 16:45:27 +01:00
parent 4f587820d1
commit 01fc6a3a1f
2 changed files with 53 additions and 0 deletions

View file

@ -2,8 +2,10 @@ package model
import (
"encoding/base64"
"errors"
"go.mongodb.org/mongo-driver/bson/primitive"
"golang.org/x/crypto/bcrypt"
"strings"
)
type DBUser struct {
@ -20,6 +22,20 @@ type DBUser struct {
Password *string `bson:"-" json:"-"` // Password may never be sent out!
}
func (usr *DBUser) ValidateMXID(mxid string) error {
for i, pendingMxid := range usr.PendingMatrixLinks {
if strings.EqualFold(*pendingMxid, mxid) {
usr.PendingMatrixLinks = append(usr.PendingMatrixLinks[:i], usr.PendingMatrixLinks[i+1:]...)
usr.MatrixLinks = append(usr.MatrixLinks, &mxid)
return nil
}
}
return errors.New("not pending")
}
func (usr *DBUser) HashPassword() error {
if usr.Password == nil {
return nil