commit c59aa2c154e7a575331dadff6e0c11b725786b61
parent af6c67365eb79aecde74a1b81e39833b8fb8cb1c
Author: Peter Kosyh <p.kosyh@gmail.com>
Date: Wed, 2 Sep 2020 00:04:50 +0300
email staff draft
Diffstat:
3 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/ii-tool/main.go b/ii-tool/main.go
@@ -67,6 +67,7 @@ func main() {
args := flag.Args()
if len(args) < 1 {
+ fmt.Printf("%s\n", err)
fmt.Printf(`Help: %s [options] command [arguments]
Commands:
send <server> <pauth> <msg|-> - send message
diff --git a/ii/db.go b/ii/db.go
@@ -9,6 +9,7 @@ import (
"io"
"os"
"path/filepath"
+ "regexp"
"sort"
"strings"
"sync"
@@ -536,6 +537,8 @@ func (db *UDB) Id(Secret string) int32 {
return -1
}
+var emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
+
func (db *UDB) Add(Name string, Mail string, Passwd string) error {
db.Sync.Lock()
defer db.Sync.Unlock()
@@ -546,6 +549,9 @@ func (db *UDB) Add(Name string, Mail string, Passwd string) error {
if !IsUsername(Name) {
return errors.New("Wrong username")
}
+ if ! emailRegex.MatchString(Mail) {
+ return errors.New("Wrong email")
+ }
var id int32 = 0
for _, v := range db.Names {
if v.Id > id {
diff --git a/ii/net.go b/ii/net.go
@@ -8,6 +8,7 @@ import (
"io"
"io/ioutil"
"net/http"
+ // "net/smtp"
"net/url"
"strings"
"sync"
@@ -252,3 +253,21 @@ func Connect(addr string) (*Node, error) {
}
return &n, nil
}
+/*
+func SendMail(email string, login string, passwd string, server string) error {
+ aserv := strings.Split(server, ":")[0]
+ auth := smtp.PlainAuth("", login, passwd, aserv)
+ msg := "Hello!"
+ msg = "From: noreply@ii-go\n" +
+ "To: " + email + "\n" +
+ "Subject: Hello there\n\n" +
+ msg
+ err := smtp.SendMail(server, auth, "noreply@ii-go",[]string{email}, []byte(msg))
+ if err != nil {
+ Error.Printf("Can't send message to: %s", email)
+ return err
+ }
+ Info.Printf("Sent message to: %s", email)
+ return nil
+}
+*/