2 Commits

Author SHA1 Message Date
4e412e9c18 extract out error login 2026-03-31 20:42:14 -04:00
6220021953 show error when new passwords do not match 2026-03-31 20:33:38 -04:00
6 changed files with 132 additions and 46 deletions

View File

@@ -309,6 +309,47 @@ func cleanupSessions() {
} }
} }
// func changePasswordHandler(w http.ResponseWriter, r *http.Request) {
// exist, sessionData := validateSession(r)
// if !exist {
// http.Redirect(w, r, "/login", http.StatusSeeOther)
// return
// }
// err := r.ParseMultipartForm(10 << 20) // 10MB limit
// if err != nil {
// http.Error(w, "Bad request", http.StatusBadRequest)
// return
// }
// if r.FormValue("csrf_token") != sessionData.CSRFToken {
// http.Error(w, "CSRF Forbidden", http.StatusForbidden)
// return
// }
// file, header, err := r.FormFile("photo")
// if err != nil {
// http.Error(w, "File not found", http.StatusBadRequest)
// return
// }
// defer file.Close()
// if header.Size > (10 * 1024 * 1024) {
// http.Error(w, "File is to large (limit is 10 MB)", http.StatusBadRequest)
// return
// }
// // 3. Read file into memory
// data, err := io.ReadAll(file)
// if err != nil {
// http.Error(w, "Failed to read file", http.StatusInternalServerError)
// return
// }
// userDN := fmt.Sprintf("uid=%s,cn=users,cn=accounts,%s", sessionData.data.Username, serverConfig.LDAPConfig.BaseDN)
// ldapServerMutex.Lock()
// defer ldapServerMutex.Unlock()
// modifyLDAPAttribute(ldapServer, userDN, "jpegphoto", []string{string(data)})
// createUserPhoto(sessionData.data.Username, data)
// }
func main() { func main() {
logging.Info("Starting the server") logging.Info("Starting the server")

View File

@@ -6,6 +6,7 @@
rel="stylesheet" rel="stylesheet"
/> />
<link rel="stylesheet" href="static/style.css" /> <link rel="stylesheet" href="static/style.css" />
<link rel="stylesheet" href="static/error.css" />
<link rel="stylesheet" href="static/card.css" /> <link rel="stylesheet" href="static/card.css" />
<link rel="stylesheet" href="static/login_page.css" /> <link rel="stylesheet" href="static/login_page.css" />
@@ -15,9 +16,9 @@
Welcome to Astral Tech, Please Sign in to your account below Welcome to Astral Tech, Please Sign in to your account below
</div> </div>
<div id="incorrect_password_text" class="{{.IsHiddenClassList}}"> <div class="error {{.IsHiddenClassList}}">
⚠️ Invalid username or password. ⚠️ Invalid username or password.
<button id="incorrect_password_close_button">X</button> <button class="close_error_button">X</button>
</div> </div>
<div> <div>
@@ -32,12 +33,4 @@
<button type="submit">Login</button> <button type="submit">Login</button>
</form> </form>
<script> <script src="/static/error.js" type="text/javascript"></script>
document
.getElementById("incorrect_password_close_button")
.addEventListener("click", function () {
document
.getElementById("incorrect_password_text")
.classList.add("hidden");
});
</script>

View File

@@ -7,15 +7,31 @@
/> />
<link rel="stylesheet" href="static/style.css" /> <link rel="stylesheet" href="static/style.css" />
<link rel="stylesheet" href="static/card.css" /> <link rel="stylesheet" href="static/card.css" />
<link rel="stylesheet" href="static/error.css" />
<link rel="stylesheet" href="static/profile_page.css" /> <link rel="stylesheet" href="static/profile_page.css" />
<div id="popup_background" class="blocked hidden"></div> <div id="popup_background" class="blocked hidden"></div>
<div id="change_password_dialouge" class="hidden card"> <div id="change_password_dialouge" class="hidden card">
<input type="password" placeholder="Current Password" /> <div id="new_password_error" class="error hidden">
<input type="password" placeholder="New Password" /> ⚠️ New password and new Password repeat do not match.
<input type="password" placeholder="New Password(repeat)" /> <button id="new_password_error_close_button" class="close_error_button">
<button>Change Password</button> X
</button>
</div>
<input
type="password"
id="current_password"
placeholder="Current Password"
/>
<input type="password" id="new_password" placeholder="New Password" />
<input
type="password"
id="new_password_repeat"
placeholder="New Password(repeat)"
/>
<button id="final_change_password_button">Change Password</button>
</div> </div>
<img id="logo_image" alt="logo" src="/logo" /> <img id="logo_image" alt="logo" src="/logo" />
@@ -102,9 +118,36 @@
document document
.getElementById("change_password_dialouge") .getElementById("change_password_dialouge")
.classList.remove("hidden"); .classList.remove("hidden");
});
</script>
// document.getElementById("change_password_dialouge").classList.add("hidden"); <script type="text/javascript">
// document.getElementById("popup_background").classList.add("hidden"); const changePasswordButton = document.getElementById(
"final_change_password_button",
);
changePasswordButton.addEventListener("click", () => {
if (
document.getElementById("new_password").value !=
document.getElementById("new_password_repeat").value
) {
document
.getElementById("new_password_error")
.classList.remove("hidden");
return;
}
const formData = new FormData();
formData.append(
"csrf_token",
document.getElementById("csrf_token_storage").value,
);
formData.append("old", file);
document
.getElementById("change_password_dialouge")
.classList.add("hidden");
document.getElementById("popup_background").classList.add("hidden");
}); });
</script> </script>
@@ -146,3 +189,5 @@
currentPreviewURL = img.src; currentPreviewURL = img.src;
}); });
</script> </script>
<script src="/static/error.js" type="text/javascript"></script>

29
static/error.css Normal file
View File

@@ -0,0 +1,29 @@
.error {
background-color: var(--error-red) !important;
border-radius: 10px;
padding: 20px;
border-style: solid;
border-color: var(--error-border-red);
border-width: 1px;
box-sizing: border-box;
font-size: 12px;
position: relative;
color: white;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}
.close_error_button {
position: absolute !important;
background-color: rgba(0, 0, 0, 0) !important;
padding: 0px !important;
top: 20px;
right: 20px;
color: black !important;
font-weight: normal !important;
border: none;
}
.close_error_button:hover {
cursor: default;
font-weight: bold !important;
}

7
static/error.js Normal file
View File

@@ -0,0 +1,7 @@
var error_close_buttons = document.getElementsByClassName("close_error_button");
for (const close_button of error_close_buttons) {
close_button.addEventListener("click", function () {
this.parentElement.classList.add("hidden");
});
}

View File

@@ -75,32 +75,3 @@
font-size: 1.25rem; font-size: 1.25rem;
margin-bottom: 8px; margin-bottom: 8px;
} }
#incorrect_password_text {
background-color: var(--error-red) !important;
border-radius: 10px;
padding: 20px;
border-style: solid;
border-color: var(--error-border-red);
border-width: 1px;
box-sizing: border-box;
font-size: 12px;
position: relative;
color: white;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}
#incorrect_password_close_button {
position: absolute !important;
background-color: rgba(0, 0, 0, 0) !important;
padding: 0px !important;
top: 20px;
right: 20px;
color: black !important;
font-weight: normal !important;
}
#incorrect_password_close_button:hover {
cursor: default;
font-weight: bold !important;
}