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