fixed invite bug
Some checks failed
Build and Push Docker Image / Build image (push) Has been cancelled
Some checks failed
Build and Push Docker Image / Build image (push) Has been cancelled
This commit is contained in:
parent
8ac960102a
commit
b8e028b80d
@ -19,8 +19,6 @@ authentication:
|
|||||||
user_pass:
|
user_pass:
|
||||||
type: "mongo"
|
type: "mongo"
|
||||||
initial_user:
|
initial_user:
|
||||||
username: ""
|
|
||||||
password: ""
|
|
||||||
email: ""
|
email: ""
|
||||||
mongo:
|
mongo:
|
||||||
url: "mongodb://mongo:27107"
|
url: "mongodb://mongo:27107"
|
||||||
|
@ -27,7 +27,6 @@ type UserPassAuthenticationDbHandler struct {
|
|||||||
|
|
||||||
func (self *UserPassAuthenticationDbHandler) ListUsers(ctx context.Context) ([]models.User, error) {
|
func (self *UserPassAuthenticationDbHandler) ListUsers(ctx context.Context) ([]models.User, error) {
|
||||||
cursor, err := self.collection.Find(ctx, bson.M{})
|
cursor, err := self.collection.Find(ctx, bson.M{})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -53,13 +52,11 @@ func (self *UserPassAuthenticationDbHandler) ListUsers(ctx context.Context) ([]m
|
|||||||
func (self *UserPassAuthenticationDbHandler) AuthenticateUser(ctx context.Context, username string, password string) (*models.User, error) {
|
func (self *UserPassAuthenticationDbHandler) AuthenticateUser(ctx context.Context, username string, password string) (*models.User, error) {
|
||||||
var user AuthUser
|
var user AuthUser
|
||||||
err := self.collection.FindOne(ctx, bson.M{"username": username}).Decode(&user)
|
err := self.collection.FindOne(ctx, bson.M{"username": username}).Decode(&user)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bcrypt.CompareHashAndPassword([]byte(user.HashedPassword), []byte(password))
|
err = bcrypt.CompareHashAndPassword([]byte(user.HashedPassword), []byte(password))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -82,7 +79,6 @@ func (self *UserPassAuthenticationDbHandler) CreateUser(
|
|||||||
maxOwnedServers uint,
|
maxOwnedServers uint,
|
||||||
) error {
|
) error {
|
||||||
hashedPassword, err := dbhandler.HashPassword(password)
|
hashedPassword, err := dbhandler.HashPassword(password)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -149,9 +145,9 @@ func NewUserPassAuthHandler(config models.MongoDBConfig) (*UserPassAuthenticatio
|
|||||||
}
|
}
|
||||||
|
|
||||||
type InviteToken struct {
|
type InviteToken struct {
|
||||||
Email string `json:"email"`
|
Email string `bson:"email"`
|
||||||
Token string `json:"token"`
|
Token string `bson:"token"`
|
||||||
Permissions models.Permission `json:"permissions"`
|
Permissions models.Permission `bson:"permissions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InviteTokenDbHandler struct {
|
type InviteTokenDbHandler struct {
|
||||||
@ -167,7 +163,6 @@ func (self *ServersDbHandler) SaveInviteToken(ctx context.Context, email string,
|
|||||||
Email: email,
|
Email: email,
|
||||||
Token: token,
|
Token: token,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
12
mail/mail.go
12
mail/mail.go
@ -22,12 +22,12 @@ func NewMailClient(config models.EmailConfig) *MailClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *MailClient) SendMail(
|
func (mc *MailClient) SendMail(
|
||||||
recipient string,
|
recipient string,
|
||||||
subject string,
|
subject string,
|
||||||
content string,
|
content string,
|
||||||
) error {
|
) error {
|
||||||
from := mail.Address{Name: "", Address: self.mailConfig.FromEmail}
|
from := mail.Address{Name: "", Address: mc.mailConfig.FromEmail}
|
||||||
to := mail.Address{Name: "", Address: recipient}
|
to := mail.Address{Name: "", Address: recipient}
|
||||||
|
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
@ -41,21 +41,21 @@ func (self *MailClient) SendMail(
|
|||||||
}
|
}
|
||||||
message += "\r\n" + content
|
message += "\r\n" + content
|
||||||
|
|
||||||
conn, err := tls.Dial("tcp", self.mailConfig.Server+":465", &tls.Config{ServerName: self.mailConfig.Server})
|
conn, err := tls.Dial("tcp", mc.mailConfig.Server+":465", &tls.Config{ServerName: mc.mailConfig.Server})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := smtp.NewClient(conn, self.mailConfig.Server)
|
client, err := smtp.NewClient(conn, mc.mailConfig.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = client.Auth(*self.auth); err != nil {
|
if err = client.Auth(*mc.auth); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = client.Mail(self.mailConfig.FromEmail); err != nil {
|
if err = client.Mail(mc.mailConfig.FromEmail); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user