Browse Source

feat: require setting username and password (#9)

jeessy2 3 years ago
parent
commit
72207fa2ce
2 changed files with 14 additions and 7 deletions
  1. 5 0
      web/save.go
  2. 9 7
      web/writing.html

+ 5 - 0
web/save.go

@@ -16,6 +16,11 @@ func Save(writer http.ResponseWriter, request *http.Request) {
 	conf.Username = strings.TrimSpace(request.FormValue("Username"))
 	conf.Password = request.FormValue("Password")
 
+	if conf.Username == "" || conf.Password == "" {
+		writer.Write([]byte("请输入登录用户名/密码"))
+		return
+	}
+
 	forms := request.PostForm
 	for index, projectName := range forms["ProjectName"] {
 		saveDays, _ := strconv.Atoi(forms["SaveDays"][index])

+ 9 - 7
web/writing.html

@@ -32,8 +32,8 @@
           <button class="btn btn-primary submit_btn" style="margin-bottom: 15px;">Save</button>
           <button class="btn btn-warning submit_btn_backupNow" style="margin-bottom: 15px;margin-left: 15px;">Save & Backup Now</button>
 
-          <div class="alert alert-success" style="display: none;">
-            <strong id="resultMsg">保存成功</strong>
+          <div class="alert" style="display: none;">
+            <strong id="resultMsg"></strong>
           </div>
 
           <div class="portlet">
@@ -135,16 +135,16 @@
               <div class="form-group row">
                 <label for="Username" class="col-sm-2 col-form-label">登录用户名</label>
                 <div class="col-sm-10">
-                  <input class="form-control" name="Username" id="Username" value="{{.Username}}" aria-describedby="Username_help">
-                  <small id="Username_help" class="form-text text-muted">强烈建议输入</small>
+                  <input class="form-control" name="Username" id="Username" value="{{.Username}}" aria-describedby="Username_help" required>
+                  <small id="Username_help" class="form-text text-muted">必须输入</small>
                 </div>
               </div>
 
               <div class="form-group row">
                 <label for="Password" class="col-sm-2 col-form-label">登录密码</label>
                 <div class="col-sm-10">
-                  <input class="form-control" type="password" name="Password" id="Password" value="{{.Password}}" aria-describedby="password_help">
-                  <small id="password_help" class="form-text text-muted">强烈建议输入</small>
+                  <input class="form-control" type="password" name="Password" id="Password" value="{{.Password}}" aria-describedby="password_help" required>
+                  <small id="password_help" class="form-text text-muted">必须输入</small>
                 </div>
               </div>
 
@@ -249,10 +249,12 @@
           success: function (result) {
             $('.alert').css("display", "block");
             if (result !== "ok") {
-              $('.alert').addClass("alert-danger")
+              $('.alert').addClass("alert-danger").removeClass("alert-success")
               $('#resultMsg').html(result)
             } else {
               // ok
+              $('.alert').addClass("alert-success").removeClass("alert-danger")
+              $('#resultMsg').html("保存成功")
               setTimeout(function(){
                 $('.alert').css("display", "none");
               }, 3000)