mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-06-06 15:47:19 +02:00
Fixed #129
- Removed requirements for Domain (now domain field can be empty and no error will be shown)
This commit is contained in:
parent
de658a3c6c
commit
e0f5431215
@ -27,8 +27,8 @@ func HandleSMTPSet(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
domain, err := utils.PostPara(r, "domain")
|
domain, err := utils.PostPara(r, "domain")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendErrorResponse(w, "domain cannot be empty")
|
//Assume domain is empty, raised by issue #129
|
||||||
return
|
domain = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
portString, err := utils.PostPara(r, "port")
|
portString, err := utils.PostPara(r, "port")
|
||||||
@ -206,7 +206,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func HandleAdminAccountResetEmail(w http.ResponseWriter, r *http.Request) {
|
func HandleAdminAccountResetEmail(w http.ResponseWriter, r *http.Request) {
|
||||||
if EmailSender.Username == "" || EmailSender.Domain == "" {
|
if EmailSender.Username == "" {
|
||||||
//Reset account not setup
|
//Reset account not setup
|
||||||
utils.SendErrorResponse(w, "Reset account not setup.")
|
utils.SendErrorResponse(w, "Reset account not setup.")
|
||||||
return
|
return
|
||||||
|
@ -20,7 +20,7 @@ type Sender struct {
|
|||||||
SenderAddr string //e.g. admin@arozos.com
|
SenderAddr string //e.g. admin@arozos.com
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create a new email sender object
|
// Create a new email sender object
|
||||||
func NewEmailSender(hostname string, domain string, port int, username string, password string, senderAddr string) *Sender {
|
func NewEmailSender(hostname string, domain string, port int, username string, password string, senderAddr string) *Sender {
|
||||||
return &Sender{
|
return &Sender{
|
||||||
Hostname: hostname,
|
Hostname: hostname,
|
||||||
@ -33,13 +33,15 @@ func NewEmailSender(hostname string, domain string, port int, username string, p
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Send a email to a reciving addr
|
Send a email to a reciving addr
|
||||||
Example Usage:
|
Example Usage:
|
||||||
SendEmail(
|
SendEmail(
|
||||||
test@example.com,
|
|
||||||
"Free donuts",
|
test@example.com,
|
||||||
"Come get your free donuts on this Sunday!"
|
"Free donuts",
|
||||||
)
|
"Come get your free donuts on this Sunday!"
|
||||||
|
|
||||||
|
)
|
||||||
*/
|
*/
|
||||||
func (s *Sender) SendEmail(to string, subject string, content string) error {
|
func (s *Sender) SendEmail(to string, subject string, content string) error {
|
||||||
//Parse the email content
|
//Parse the email content
|
||||||
@ -50,7 +52,13 @@ func (s *Sender) SendEmail(to string, subject string, content string) error {
|
|||||||
content + "\n\n")
|
content + "\n\n")
|
||||||
|
|
||||||
//Login to the SMTP server
|
//Login to the SMTP server
|
||||||
auth := smtp.PlainAuth("", s.Username+"@"+s.Domain, s.Password, s.Hostname)
|
var auth smtp.Auth
|
||||||
|
if s.Domain == "" {
|
||||||
|
auth = smtp.PlainAuth("", s.Username, s.Password, s.Hostname)
|
||||||
|
} else {
|
||||||
|
auth = smtp.PlainAuth("", s.Username+"@"+s.Domain, s.Password, s.Hostname)
|
||||||
|
}
|
||||||
|
|
||||||
err := smtp.SendMail(s.Hostname+":"+strconv.Itoa(s.Port), auth, s.SenderAddr, []string{to}, msg)
|
err := smtp.SendMail(s.Hostname+":"+strconv.Itoa(s.Port), auth, s.SenderAddr, []string{to}, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -345,7 +345,8 @@
|
|||||||
form.find('input[name="hostname"]').parent().removeClass('error');
|
form.find('input[name="hostname"]').parent().removeClass('error');
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate domain
|
// validate domain, now allow empty string (for smtp that dont use domain as input)
|
||||||
|
/*
|
||||||
const domain = form.find('input[name="domain"]').val().trim();
|
const domain = form.find('input[name="domain"]').val().trim();
|
||||||
if (!domainRegex.test(domain)) {
|
if (!domainRegex.test(domain)) {
|
||||||
form.find('input[name="domain"]').parent().addClass('error');
|
form.find('input[name="domain"]').parent().addClass('error');
|
||||||
@ -353,6 +354,7 @@
|
|||||||
} else {
|
} else {
|
||||||
form.find('input[name="domain"]').parent().removeClass('error');
|
form.find('input[name="domain"]').parent().removeClass('error');
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// validate username
|
// validate username
|
||||||
const username = form.find('input[name="username"]').val().trim();
|
const username = form.find('input[name="username"]').val().trim();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user