瀏覽代碼

Added enable overview in non cloud mode

Toby Chui 3 年之前
父節點
當前提交
34e63c33cf
共有 5 個文件被更改,包括 74 次插入19 次删除
  1. 39 0
      mod/auth/register/register.go
  2. 19 3
      notification.go
  3. 9 9
      system.info.go
  4. 5 5
      system/www/smtpn.html
  5. 2 2
      web/SystemAO/info/overview.html

+ 39 - 0
mod/auth/register/register.go

@@ -15,6 +15,7 @@ import (
 	"io/ioutil"
 	"log"
 	"net/http"
+	"net/mail"
 	"os"
 	"strings"
 
@@ -174,6 +175,7 @@ func (h *RegisterHandler) CleanRegisters() {
 	}
 }
 
+//List all User Emails, return [username(string), email(string), stillResitered(bool)]
 func (h *RegisterHandler) ListAllUserEmails() [][]interface{} {
 	results := [][]interface{}{}
 	entries, _ := h.database.ListTable("register")
@@ -208,6 +210,12 @@ func (h *RegisterHandler) HandleRegisterRequest(w http.ResponseWriter, r *http.R
 		return
 	}
 
+	//Validate the email is a email
+	if !isValidEmail(email) {
+		sendErrorResponse(w, "Invalid or malformed email")
+		return
+	}
+
 	username, err := mv(r, "username", true)
 	if username == "" || strings.TrimSpace(username) == "" || err != nil {
 		sendErrorResponse(w, "Invalid Username")
@@ -261,3 +269,34 @@ func (h *RegisterHandler) HandleRegisterRequest(w http.ResponseWriter, r *http.R
 	log.Println("New User Registered: ", email, username, strings.Repeat("*", len(password)))
 
 }
+
+//Change Email for the registered user
+func (h *RegisterHandler) HandleEmailChange(w http.ResponseWriter, r *http.Request) {
+	//Get input paramter
+	email, err := mv(r, "email", true)
+	if err != nil {
+		sendErrorResponse(w, "Invalid Email")
+		return
+	}
+
+	//Validate the email is a email
+	if !isValidEmail(email) {
+		sendErrorResponse(w, "Invalid or malformed email")
+		return
+	}
+
+	//Get username from request
+	username, err := h.authAgent.GetUserName(w, r)
+	if err != nil {
+		sendErrorResponse(w, "Unable to get username from request")
+		return
+	}
+
+	//Write email to database as well
+	h.database.Write("register", "user/email/"+username, email)
+}
+
+func isValidEmail(email string) bool {
+	_, err := mail.ParseAddress(email)
+	return err == nil
+}

+ 19 - 3
notification.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"log"
 	"strconv"
 	"time"
 
@@ -17,24 +18,39 @@ func notificationInit() {
 	//Register the notification agents
 
 	//SMTP Mail Sender
+	//Load configuration from database
+
+	//Load username and their email from authAgent
+	userEmailmap := map[string]string{}
+	allRecords := registerHandler.ListAllUserEmails()
+	for _, userRercord := range allRecords {
+		if userRercord[2].(bool) {
+			userEmailmap[userRercord[0].(string)] = userRercord[1].(string)
+		}
+	}
+
+	log.Println(userEmailmap)
+
 	smtpAgent := smtpn.Agent{
 		Hostname:           *host_name,
 		SMTPSender:         "[email protected]",
-		SMTPPassword:       "",
+		SMTPPassword:       "noreplypassword",
 		SMTPDomain:         "mail.gandi.net",
 		SMTPPort:           587,
-		UsernameToEmailMap: map[string]string{},
+		UsernameToEmailMap: userEmailmap,
 	}
 
 	notificationQueue.RegisterNotificationAgent(smtpAgent)
 
+	//Create and register other notification agents
+
 	go func() {
 		time.Sleep(10 * time.Second)
 		notificationQueue.BroadcastNotification(&notification.NotificationPayload{
 			ID:            strconv.Itoa(int(time.Now().Unix())),
 			Title:         "Disk SMART Error",
 			Message:       "This is a testing notification for showcasing a sample email when DISK SMART error was scanned and discovered.<br> Please visit <a href='https://blog.teacat.io'>here</a> for more information.",
-			Receiver:      []string{"TC", "jk", "ay"},
+			Receiver:      []string{"TC"},
 			Sender:        "SMART Nightly Scanner",
 			ReciverAgents: []string{"smtpn"},
 		})

+ 9 - 9
system.info.go

@@ -41,6 +41,15 @@ func SystemInfoInit() {
 	//Create Info Server Object
 	var infoServer *info.Server = nil
 
+	//Overview of account and system information
+	registerSetting(settingModule{
+		Name:     "Overview",
+		Desc:     "Overview for user information",
+		IconPath: "SystemAO/info/img/small_icon.png",
+		Group:    "Info",
+		StartDir: "SystemAO/info/overview.html",
+	})
+
 	if *allow_hardware_management {
 		infoServer = info.NewInfoServer(info.ArOZInfo{
 			BuildVersion: build_version + "." + internal_version,
@@ -84,15 +93,6 @@ func SystemInfoInit() {
 		router.HandleFunc("/system/info/getUsageInfo", InfoHandleTaskInfo)
 
 	} else {
-		//Make a simpler page for the information of system for hardware management disabled nodes
-		registerSetting(settingModule{
-			Name:     "Overview",
-			Desc:     "Overview for user information",
-			IconPath: "SystemAO/info/img/small_icon.png",
-			Group:    "Info",
-			StartDir: "SystemAO/info/overview.html",
-		})
-
 		//Remve hardware information from the infoServer
 		infoServer = info.NewInfoServer(info.ArOZInfo{
 			BuildVersion: build_version + "." + internal_version,

+ 5 - 5
system/www/smtpn.html

@@ -22,11 +22,11 @@
 		}
     </style>
 </head>
-<body style="margin:0;padding:0;">
-    <table role="presentation" style="width:100%;border-collapse:collapse;border:0;border-spacing:0;background:#ffffff;">
+<body style="margin:0; padding:0;">
+    <table role="presentation" style="width:100%;border-collapse:collapse;border:0;border-spacing:0;background-color: #fcfcfc;">
         <tr>
             <td class="theme" style="padding: 1em; color: #595959; color: white;">
-				System Notification from {{hostname}}
+				<b>System Notification from {{hostname}}</b>
             </td>
         </tr>
 		<tr>
@@ -37,8 +37,8 @@
             </td>
         </tr>
 		<tr style="border-top: 1px solid #d4d4d4 !important;">
-            <td style="padding:0.4em; font-size: 0.8em;">
-				This message was sent automatically from {{hostname}} on {{timestamp}}.
+            <td style="padding:0.8em; padding-left: 1.2em; font-size: 0.8em;">
+				This message was automatically sent by {{hostname}} on {{timestamp}}.
             </td>
         </tr>
     </table>

+ 2 - 2
web/SystemAO/info/overview.html

@@ -38,13 +38,13 @@
                     <div class="ui divider"></div>
                     <div class="ui grid">
                         <div class="six wide column">
-                            Used Storage:
+                            Used Space
                         </div>
                         <div class="ten wide column" id="usedStorage">
                             Loading...
                         </div>
                         <div class="six wide column">
-                            Total Storage:
+                            Total Space
                         </div>
                         <div class="ten wide column" id="totalStorage">
                             Loading...