getemail - use username if its an email addres
This commit is contained in:
@@ -161,7 +161,7 @@ func SendAlert(u int64, subject, body string) error {
|
||||
if !ok {
|
||||
return fmt.Errorf("scsusers.SendAlert: User %d not found", u)
|
||||
}
|
||||
email, ok := user.Get("email")
|
||||
email, ok := user.GetEmail()
|
||||
if !ok {
|
||||
return fmt.Errorf("scsusers.SendAlert: User %d has no email", u)
|
||||
}
|
||||
|
19
meta.go
19
meta.go
@@ -4,6 +4,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/mail"
|
||||
)
|
||||
|
||||
type Metadata struct {
|
||||
@@ -11,6 +12,24 @@ type Metadata struct {
|
||||
MetaValue string `db:"meta_value"`
|
||||
}
|
||||
|
||||
func (u *UserData) GetEmail() (string, bool) {
|
||||
_, err := mail.ParseAddress(u.Username)
|
||||
|
||||
if err == nil {
|
||||
return u.Username, true
|
||||
}
|
||||
|
||||
e, ok := u.Get("email")
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
_, err = mail.ParseAddress(e)
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
return e, true
|
||||
}
|
||||
|
||||
func (u *UserData) LoadMeta() bool {
|
||||
q := fmt.Sprintf("select meta_key, meta_value, id from %s_meta where user=?", c.TablePrefix)
|
||||
rows, err := c.db.Query(q, u.UserID)
|
||||
|
Reference in New Issue
Block a user