Compare commits
6 Commits
v0.0.4
...
b9ed00c127
| Author | SHA1 | Date | |
|---|---|---|---|
| b9ed00c127 | |||
| 8b74cab34e | |||
| dbb91fac62 | |||
| 8cb1fff36b | |||
| d0524f901c | |||
| 384ef90ea8 |
@@ -98,7 +98,11 @@ func UploadPhotoHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
userDN := fmt.Sprintf("uid=%s,cn=users,cn=accounts,%s", sessionData.UserID, BaseDN)
|
userDN := fmt.Sprintf("uid=%s,cn=users,cn=accounts,%s", sessionData.UserID, BaseDN)
|
||||||
LDAPServer.ModifyAttribute(ServiceUserBindDN, ServiceUserPassword, userDN, "jpegphoto", []string{string(data)})
|
err = LDAPServer.ModifyAttribute(ServiceUserBindDN, ServiceUserPassword, userDN, "jpegphoto", []string{string(data)})
|
||||||
|
if err != nil {
|
||||||
|
logging.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
CreateUserPhoto(sessionData.UserID, data)
|
CreateUserPhoto(sessionData.UserID, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,17 +116,25 @@ func AvatarHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
filePath := fmt.Sprintf("./avatars/%s.jpeg", username)
|
filePath := fmt.Sprintf("./avatars/%s.jpeg", username)
|
||||||
cleaned := filepath.Clean(filePath)
|
cleaned := filepath.Clean(filePath)
|
||||||
value, err := helpers.ReadFile(cleaned)
|
fileExist, err := helpers.DoesFileExist(cleaned)
|
||||||
|
if err != nil {
|
||||||
if err == nil {
|
w.Write(blankPhotoData)
|
||||||
photoCreatedMutex.Lock()
|
logging.Error(err.Error())
|
||||||
if time.Since(photoCreatedTimestamp[username]) <= 5*time.Minute {
|
return
|
||||||
photoCreatedMutex.Unlock()
|
}
|
||||||
w.Write(value)
|
photoCreatedMutex.Lock()
|
||||||
|
if fileExist && time.Since(photoCreatedTimestamp[username]) <= 5*time.Minute {
|
||||||
|
photoCreatedMutex.Unlock()
|
||||||
|
val, err := helpers.ReadFile(cleaned)
|
||||||
|
if err != nil {
|
||||||
|
logging.Error(err.Error())
|
||||||
|
w.Write(blankPhotoData)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
photoCreatedMutex.Unlock()
|
w.Write(val)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
photoCreatedMutex.Unlock()
|
||||||
|
|
||||||
userSearch, err := LDAPServer.SerchServer(
|
userSearch, err := LDAPServer.SerchServer(
|
||||||
ServiceUserBindDN, ServiceUserPassword,
|
ServiceUserBindDN, ServiceUserPassword,
|
||||||
@@ -130,10 +142,16 @@ func AvatarHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Sprintf("(&(objectClass=inetOrgPerson)(uid=%s))", ldap.LDAPEscapeFilter(username)),
|
fmt.Sprintf("(&(objectClass=inetOrgPerson)(uid=%s))", ldap.LDAPEscapeFilter(username)),
|
||||||
[]string{"jpegphoto"},
|
[]string{"jpegphoto"},
|
||||||
)
|
)
|
||||||
if err == nil || userSearch.EntryCount() == 0 {
|
if err != nil {
|
||||||
|
logging.Error(err.Error())
|
||||||
w.Write(blankPhotoData)
|
w.Write(blankPhotoData)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if userSearch.EntryCount() == 0 {
|
||||||
|
w.Write(blankPhotoData)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
entry := userSearch.GetEntry(0)
|
entry := userSearch.GetEntry(0)
|
||||||
bytes := entry.GetRawAttributeValue("jpegphoto")
|
bytes := entry.GetRawAttributeValue("jpegphoto")
|
||||||
if len(bytes) == 0 {
|
if len(bytes) == 0 {
|
||||||
@@ -142,5 +160,6 @@ func AvatarHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
} else {
|
} else {
|
||||||
w.Write(bytes)
|
w.Write(bytes)
|
||||||
CreateUserPhoto(username, bytes)
|
CreateUserPhoto(username, bytes)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,17 @@ func CreateFile(path string) (*os.File, error) {
|
|||||||
return file, nil
|
return file, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DoesFileExist(path string) (bool, error) {
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
if err == nil {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
func HandleFunc(path string, handler func(http.ResponseWriter, *http.Request)) {
|
func HandleFunc(path string, handler func(http.ResponseWriter, *http.Request)) {
|
||||||
logging.Infof("Handling %s", path)
|
logging.Infof("Handling %s", path)
|
||||||
http.HandleFunc(path, handler)
|
http.HandleFunc(path, handler)
|
||||||
|
|||||||
@@ -9,10 +9,11 @@
|
|||||||
<link rel="stylesheet" href="static/card.css" />
|
<link rel="stylesheet" href="static/card.css" />
|
||||||
<link rel="stylesheet" href="static/error/error.css" />
|
<link rel="stylesheet" href="static/error/error.css" />
|
||||||
<link rel="stylesheet" href="static/profile_page.css" />
|
<link rel="stylesheet" href="static/profile_page.css" />
|
||||||
|
<link rel="stylesheet" href="static/progress_bar.css" />
|
||||||
|
|
||||||
<div id="popup_background" class="blocked hidden"></div>
|
<div id="popup_background" class="blocked"></div>
|
||||||
|
|
||||||
<div id="change_password_dialogue" class="hidden card static_center">
|
<div id="change_password_dialogue" class="card static_center">
|
||||||
Change Password
|
Change Password
|
||||||
|
|
||||||
<button id="close_password_dialogue">X</button>
|
<button id="close_password_dialogue">X</button>
|
||||||
@@ -57,6 +58,18 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label class="input_label" id="strengh-label">Strength: Weak</label
|
||||||
|
><br />
|
||||||
|
<div class="progress-bar">
|
||||||
|
<div
|
||||||
|
class="progress-bar-progress"
|
||||||
|
id="password-progress"
|
||||||
|
style="width: 0%"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button id="final_change_password_button">Change Password</button>
|
<button id="final_change_password_button">Change Password</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -136,96 +149,6 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
const popup_botton = document.getElementById("change_password_button");
|
|
||||||
|
|
||||||
popup_botton.addEventListener("click", () => {
|
|
||||||
document.getElementById("popup_background").classList.remove("hidden");
|
|
||||||
document
|
|
||||||
.getElementById("change_password_dialogue")
|
|
||||||
.classList.remove("hidden");
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
const changePasswordButton = document.getElementById(
|
|
||||||
"final_change_password_button",
|
|
||||||
);
|
|
||||||
|
|
||||||
function displayError(errorText) {
|
|
||||||
document.getElementById("password_error").classList.remove("hidden");
|
|
||||||
document.getElementById("password_text").innerText =
|
|
||||||
"⚠️ " + errorText + ".";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
changePasswordButton.addEventListener("click", () => {
|
|
||||||
if (document.getElementById("current_password").value === "") {
|
|
||||||
displayError("Please enter current password");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.getElementById("new_password").value === "") {
|
|
||||||
displayError("No value for new password");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.getElementById("new_password_repeat").value === "") {
|
|
||||||
displayError("Please repeat new password");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
document.getElementById("new_password").value !==
|
|
||||||
document.getElementById("new_password_repeat").value
|
|
||||||
) {
|
|
||||||
displayError("New password and new password repeat do not match");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append(
|
|
||||||
"csrf_token",
|
|
||||||
document.getElementById("csrf_token_storage").value,
|
|
||||||
);
|
|
||||||
formData.append(
|
|
||||||
"old_password",
|
|
||||||
document.getElementById("current_password").value,
|
|
||||||
);
|
|
||||||
formData.append(
|
|
||||||
"new_password",
|
|
||||||
document.getElementById("new_password").value,
|
|
||||||
);
|
|
||||||
formData.append(
|
|
||||||
"new_password_repeat",
|
|
||||||
document.getElementById("new_password_repeat").value,
|
|
||||||
);
|
|
||||||
|
|
||||||
fetch("/change-password", {
|
|
||||||
method: "POST",
|
|
||||||
body: formData,
|
|
||||||
})
|
|
||||||
.then(async (res) => {
|
|
||||||
const data = await res.json();
|
|
||||||
if (!res.ok) {
|
|
||||||
throw new Error(data.error || "Request failed");
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
})
|
|
||||||
.then((data) => {
|
|
||||||
document
|
|
||||||
.getElementById("change_password_dialogue")
|
|
||||||
.classList.add("hidden");
|
|
||||||
document
|
|
||||||
.getElementById("popup_background")
|
|
||||||
.classList.add("hidden");
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
displayError(err.message);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var currentPreviewURL = null;
|
var currentPreviewURL = null;
|
||||||
|
|
||||||
@@ -265,15 +188,12 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
document
|
|
||||||
.getElementById("close_password_dialogue")
|
|
||||||
.addEventListener("click", () => {
|
|
||||||
document
|
|
||||||
.getElementById("change_password_dialogue")
|
|
||||||
.classList.add("hidden");
|
|
||||||
document.getElementById("popup_background").classList.add("hidden");
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script src="/static/error/error.js" type="text/javascript"></script>
|
<script src="/static/error/error.js" type="text/javascript"></script>
|
||||||
|
<script
|
||||||
|
src="/static/javascript/password_strength.js"
|
||||||
|
type="text/javascript"
|
||||||
|
></script>
|
||||||
|
<script
|
||||||
|
src="/static/javascript/handle_password_change.js"
|
||||||
|
type="text/javascript"
|
||||||
|
></script>
|
||||||
|
|||||||
7
src/session/session_errors.go
Normal file
7
src/session/session_errors.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package session
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var ErrSessionNotFound = errors.New("session not found")
|
||||||
|
var ErrSessionAlreadyExists = errors.New("session already exists")
|
||||||
|
var ErrSessionExpired = errors.New("session expired")
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package session
|
package session
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -9,10 +8,6 @@ import (
|
|||||||
"astraltech.xyz/accountmanager/src/worker"
|
"astraltech.xyz/accountmanager/src/worker"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrSessionNotFound = errors.New("session not found")
|
|
||||||
var ErrSessionAlreadyExists = errors.New("session already exists")
|
|
||||||
var ErrSessionExpired = errors.New("session expired")
|
|
||||||
|
|
||||||
type MemoryStore struct {
|
type MemoryStore struct {
|
||||||
sessions map[string]*SessionData
|
sessions map[string]*SessionData
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
|
|||||||
108
static/javascript/handle_password_change.js
Normal file
108
static/javascript/handle_password_change.js
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
document
|
||||||
|
.getElementById("close_password_dialogue")
|
||||||
|
.addEventListener("click", () => {
|
||||||
|
document.getElementById("change_password_dialogue").classList.add("hidden");
|
||||||
|
document.getElementById("popup_background").classList.add("hidden");
|
||||||
|
});
|
||||||
|
|
||||||
|
const popup_botton = document.getElementById("change_password_button");
|
||||||
|
|
||||||
|
popup_botton.addEventListener("click", () => {
|
||||||
|
document.getElementById("popup_background").classList.remove("hidden");
|
||||||
|
document
|
||||||
|
.getElementById("change_password_dialogue")
|
||||||
|
.classList.remove("hidden");
|
||||||
|
});
|
||||||
|
|
||||||
|
const changePasswordButton = document.getElementById(
|
||||||
|
"final_change_password_button",
|
||||||
|
);
|
||||||
|
|
||||||
|
function displayError(errorText) {
|
||||||
|
document.getElementById("password_error").classList.remove("hidden");
|
||||||
|
document.getElementById("password_text").innerText = "⚠️ " + errorText + ".";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
changePasswordButton.addEventListener("click", () => {
|
||||||
|
if (document.getElementById("current_password").value === "") {
|
||||||
|
displayError("Please enter current password");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.getElementById("new_password").value === "") {
|
||||||
|
displayError("No value for new password");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.getElementById("new_password_repeat").value === "") {
|
||||||
|
displayError("Please repeat new password");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
document.getElementById("new_password").value !==
|
||||||
|
document.getElementById("new_password_repeat").value
|
||||||
|
) {
|
||||||
|
displayError("New password and new password repeat do not match");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append(
|
||||||
|
"csrf_token",
|
||||||
|
document.getElementById("csrf_token_storage").value,
|
||||||
|
);
|
||||||
|
formData.append(
|
||||||
|
"old_password",
|
||||||
|
document.getElementById("current_password").value,
|
||||||
|
);
|
||||||
|
formData.append(
|
||||||
|
"new_password",
|
||||||
|
document.getElementById("new_password").value,
|
||||||
|
);
|
||||||
|
formData.append(
|
||||||
|
"new_password_repeat",
|
||||||
|
document.getElementById("new_password_repeat").value,
|
||||||
|
);
|
||||||
|
|
||||||
|
fetch("/change-password", {
|
||||||
|
method: "POST",
|
||||||
|
body: formData,
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
const data = await res.json();
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(data.error || "Request failed");
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
document
|
||||||
|
.getElementById("change_password_dialogue")
|
||||||
|
.classList.add("hidden");
|
||||||
|
document.getElementById("popup_background").classList.add("hidden");
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
displayError(err.message);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("new_password").addEventListener("input", () => {
|
||||||
|
score = EvaluatePassword(document.getElementById("new_password").value).score;
|
||||||
|
strengh_label = document.getElementById("strengh-label");
|
||||||
|
password_progress = document.getElementById("password-progress");
|
||||||
|
|
||||||
|
password_progress.style.width = score + "%";
|
||||||
|
|
||||||
|
if (score <= 40) {
|
||||||
|
strengh_label.innerText = "Strength: Weak";
|
||||||
|
password_progress.style.backgroundColor = "var(--password-strength-weak)";
|
||||||
|
} else if (score > 40 && score <= 70) {
|
||||||
|
strengh_label.innerText = "Strength: Medium";
|
||||||
|
password_progress.style.backgroundColor = "var(--password-strength-medium)";
|
||||||
|
} else if (score > 40 && score >= 70) {
|
||||||
|
strengh_label.innerText = "Strength: Strong";
|
||||||
|
password_progress.style.backgroundColor = "var(--password-strength-strong)";
|
||||||
|
}
|
||||||
|
});
|
||||||
51
static/javascript/password_strength.js
Normal file
51
static/javascript/password_strength.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
// build in evaluate password function
|
||||||
|
// Errors: reasons why the FreeIPA server would reject the password
|
||||||
|
// Suggestions: reasons the password should be made stronger
|
||||||
|
// You can change this code to change how complexity is rated
|
||||||
|
// Return values
|
||||||
|
// Score: 0-100
|
||||||
|
// Errors: A list of errors that would cause the server to reject the password
|
||||||
|
// Suggestions: A list of suggestions to make the password stronger
|
||||||
|
function EvaluatePassword(password) {
|
||||||
|
let score = 0;
|
||||||
|
let errors = [];
|
||||||
|
let suggestions = [];
|
||||||
|
|
||||||
|
const hasUpper = /[A-Z]/.test(password);
|
||||||
|
const hasLower = /[a-z]/.test(password);
|
||||||
|
const hasNumber = /[0-9]/.test(password);
|
||||||
|
const hasSpecial = /[^A-Za-z0-9]/.test(password);
|
||||||
|
const isLongEnough = password.length >= 8;
|
||||||
|
|
||||||
|
if (!isLongEnough) {
|
||||||
|
errors.push("Password must be at least 8 characters long.");
|
||||||
|
}
|
||||||
|
score += Math.min(password.length * 3, 60);
|
||||||
|
if (hasUpper) score += 10;
|
||||||
|
if (hasLower) score += 10;
|
||||||
|
if (hasNumber) score += 10;
|
||||||
|
if (hasSpecial) score += 10;
|
||||||
|
if (score < 100) {
|
||||||
|
if (password.length < 20) {
|
||||||
|
suggestions.push(
|
||||||
|
`Add ${20 - password.length} more characters to reach maximum length points.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!hasUpper) suggestions.push("Add an uppercase letter.");
|
||||||
|
if (!hasLower) suggestions.push("Add a lowercase letter.");
|
||||||
|
if (!hasNumber) suggestions.push("Add a number.");
|
||||||
|
if (!hasSpecial)
|
||||||
|
suggestions.push("Add a special character (e.g., !, @, #).");
|
||||||
|
if (score > 70 && score < 100) {
|
||||||
|
suggestions.push(
|
||||||
|
"Pro-tip: Use a full sentence (passphrase) to make it easier to remember and harder to crack.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
score: Math.min(score, 100),
|
||||||
|
errors: errors,
|
||||||
|
suggestions: suggestions,
|
||||||
|
};
|
||||||
|
}
|
||||||
16
static/progress_bar.css
Normal file
16
static/progress_bar.css
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
:root {
|
||||||
|
--progress-top: #becbd8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-bar {
|
||||||
|
width: 100%;
|
||||||
|
background-color: var(--bg-input);
|
||||||
|
height: 20px;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-bar-progress {
|
||||||
|
background-color: var(--progress-top);
|
||||||
|
height: 20px;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
@@ -16,6 +16,10 @@
|
|||||||
--error-red: #ef4444; /* Professional Red */
|
--error-red: #ef4444; /* Professional Red */
|
||||||
--error-border-red: #e22d2d;
|
--error-border-red: #e22d2d;
|
||||||
|
|
||||||
|
--password-strength-weak: var(--error-red);
|
||||||
|
--password-strength-medium: #efe943;
|
||||||
|
--password-strength-strong: #43ef6b;
|
||||||
|
|
||||||
font-family: "Inter", sans-serif;
|
font-family: "Inter", sans-serif;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user