Compare commits
28 Commits
33ea56fb0c
...
v0.0.5
| Author | SHA1 | Date | |
|---|---|---|---|
| 37c6978d1b | |||
| 9389df28e4 | |||
| b94bc612c3 | |||
| 25e61c553f | |||
| a31d21456c | |||
| a1f58e817e | |||
| 387bd2d0ae | |||
| 0ab1e95690 | |||
| d7727e9b0d | |||
| 72dfaf5da1 | |||
| 5e0771d482 | |||
| b9ed00c127 | |||
| 8b74cab34e | |||
| dbb91fac62 | |||
| 8cb1fff36b | |||
| d0524f901c | |||
| 384ef90ea8 | |||
| a315161ed3 | |||
| e2531e3021 | |||
| a2602f74f0 | |||
| 1c1ba99080 | |||
| ad21d50ce5 | |||
| 3a3fab08f6 | |||
| bb649aef48 | |||
| f204069392 | |||
| ac663f21e1 | |||
| d1992ec466 | |||
| 46db63e62a |
25
README.md
25
README.md
@@ -6,20 +6,20 @@ A simple, lightweight web application for managing user profile photos in a Free
|
|||||||
* **LDAP Authentication**: Secure login with existing FreeIPA credentials.
|
* **LDAP Authentication**: Secure login with existing FreeIPA credentials.
|
||||||
* **Profile Management**: View user details (Display Name, Email).
|
* **Profile Management**: View user details (Display Name, Email).
|
||||||
* **Photo Upload**: Users can upload and update their profile picture (`jpegPhoto` attribute).
|
* **Photo Upload**: Users can upload and update their profile picture (`jpegPhoto` attribute).
|
||||||
|
* **Change Password**: Users can change there password once logged in
|
||||||
* **Session Management**: Secure, cookie-based sessions with CSRF protection.
|
* **Session Management**: Secure, cookie-based sessions with CSRF protection.
|
||||||
* **Customizable**: Configurable styling (logo, favicon) and LDAP settings.
|
* **Customizable**: Configurable styling (logo, favicon) and LDAP settings.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
* **Go 1.26+** installed on your machine.
|
||||||
* **Go 1.20+** installed on your machine.
|
* Access to a **FreeIPA Server**.
|
||||||
* Access to an **FreeIPA Server**.
|
* A Service Account with permission to search and modify the `jpegPhoto` attribute.
|
||||||
* A Service Account (Bind DN) with permission to search users and modify the `jpegPhoto` attribute.
|
|
||||||
|
|
||||||
## Setup & Installation
|
## Setup & Installation
|
||||||
|
|
||||||
1. **Clone the Repository**
|
1. **Clone the Repository**
|
||||||
```bash
|
```bash
|
||||||
git clone https://git.astraltech.xyz/gawells/Self-Service-Dashboard
|
git clone https://git.astraltech.xyz/gawells/Self-Service-Dashboard.git
|
||||||
cd Self-Service-Dashboard
|
cd Self-Service-Dashboard
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -30,7 +30,10 @@ A simple, lightweight web application for managing user profile photos in a Free
|
|||||||
```
|
```
|
||||||
|
|
||||||
5. **Edit config**
|
5. **Edit config**
|
||||||
put in your config values for ldap, and whatevery styling guidelines you would want to use
|
Edit the config file
|
||||||
|
```bash
|
||||||
|
nvim data/config.json
|
||||||
|
```
|
||||||
|
|
||||||
4. **Install Dependencies**
|
4. **Install Dependencies**
|
||||||
```bash
|
```bash
|
||||||
@@ -41,15 +44,7 @@ A simple, lightweight web application for managing user profile photos in a Free
|
|||||||
```bash
|
```bash
|
||||||
go run ./src/main/
|
go run ./src/main/
|
||||||
```
|
```
|
||||||
The application will be available at `http://<host>:<port>`.
|
The application will be available at `http://localhost:<port>`.
|
||||||
|
|
||||||
## Directory Structure
|
|
||||||
|
|
||||||
* `src/`: Go source code (`main.go`, `ldap.go`, `session.go`, etc.).
|
|
||||||
* `src/pages/`: HTML templates for login and profile pages.
|
|
||||||
* `static/`: CSS files, images, and other static assets.
|
|
||||||
* `data/`: Configuration files and local assets (logos).
|
|
||||||
* `avatars/`: Stores cached user profile photos.
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
165
src/components/profile_photo.go
Normal file
165
src/components/profile_photo.go
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
package components
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"astraltech.xyz/accountmanager/src/helpers"
|
||||||
|
"astraltech.xyz/accountmanager/src/ldap"
|
||||||
|
"astraltech.xyz/accountmanager/src/logging"
|
||||||
|
"astraltech.xyz/accountmanager/src/session"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
photoCreatedTimestamp = make(map[string]time.Time)
|
||||||
|
photoCreatedMutex sync.Mutex
|
||||||
|
blankPhotoData []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
sessionManager = session.GetSessionManager()
|
||||||
|
LDAPServer *ldap.LDAPServer
|
||||||
|
|
||||||
|
BaseDN string
|
||||||
|
|
||||||
|
ServiceUserBindDN string
|
||||||
|
ServiceUserPassword string
|
||||||
|
)
|
||||||
|
|
||||||
|
func ReadBlankPhoto() {
|
||||||
|
blank, err := helpers.ReadFile("static/images/blank_profile.jpg")
|
||||||
|
if err != nil {
|
||||||
|
logging.Fatal("Could not load blank profile image")
|
||||||
|
}
|
||||||
|
blankPhotoData = blank
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateUserPhoto(username string, photoData []byte) error {
|
||||||
|
helpers.Mkdir("./avatars", os.ModePerm)
|
||||||
|
|
||||||
|
path := fmt.Sprintf("./avatars/%s.jpeg", username)
|
||||||
|
cleaned := filepath.Clean(path)
|
||||||
|
dst, err := helpers.CreateFile(cleaned)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Could not save file")
|
||||||
|
}
|
||||||
|
photoCreatedMutex.Lock()
|
||||||
|
photoCreatedTimestamp[username] = time.Now()
|
||||||
|
photoCreatedMutex.Unlock()
|
||||||
|
defer dst.Close()
|
||||||
|
logging.Info("Writing to avarar file")
|
||||||
|
_, err = dst.Write(photoData)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func UploadPhotoHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
sessionData, err := sessionManager.GetSession(r)
|
||||||
|
if err != nil {
|
||||||
|
logging.Error(err.Error())
|
||||||
|
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.UserID, BaseDN)
|
||||||
|
err = LDAPServer.ModifyAttribute(ServiceUserBindDN, ServiceUserPassword, userDN, "jpegphoto", []string{string(data)})
|
||||||
|
if err != nil {
|
||||||
|
logging.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
CreateUserPhoto(sessionData.UserID, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AvatarHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "image/jpeg")
|
||||||
|
username := r.URL.Query().Get("user")
|
||||||
|
if strings.Contains(username, "/") {
|
||||||
|
w.Write(blankPhotoData)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
filePath := fmt.Sprintf("./avatars/%s.jpeg", username)
|
||||||
|
cleaned := filepath.Clean(filePath)
|
||||||
|
fileExist, err := helpers.DoesFileExist(cleaned)
|
||||||
|
if err != nil {
|
||||||
|
w.Write(blankPhotoData)
|
||||||
|
logging.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
w.Write(val)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
photoCreatedMutex.Unlock()
|
||||||
|
|
||||||
|
userSearch, err := LDAPServer.SerchServer(
|
||||||
|
ServiceUserBindDN, ServiceUserPassword,
|
||||||
|
BaseDN,
|
||||||
|
fmt.Sprintf("(&(objectClass=inetOrgPerson)(uid=%s))", ldap.LDAPEscapeFilter(username)),
|
||||||
|
[]string{"jpegphoto"},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
logging.Error(err.Error())
|
||||||
|
w.Write(blankPhotoData)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if userSearch.EntryCount() == 0 {
|
||||||
|
w.Write(blankPhotoData)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
entry := userSearch.GetEntry(0)
|
||||||
|
bytes := entry.GetRawAttributeValue("jpegphoto")
|
||||||
|
if len(bytes) == 0 {
|
||||||
|
w.Write(blankPhotoData)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
w.Write(bytes)
|
||||||
|
CreateUserPhoto(username, bytes)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package email
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package helpers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -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)
|
||||||
7
src/ldap/ldap_helpers.go
Normal file
7
src/ldap/ldap_helpers.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package ldap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-ldap/ldap/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
func LDAPEscapeFilter(input string) string { return ldap.EscapeFilter(input) }
|
||||||
29
src/ldap/ldap_search.go
Normal file
29
src/ldap/ldap_search.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package ldap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-ldap/ldap/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LDAPSearch struct {
|
||||||
|
search *ldap.SearchResult
|
||||||
|
}
|
||||||
|
|
||||||
|
type LDAPEntry struct {
|
||||||
|
entry *ldap.Entry
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LDAPSearch) EntryCount() int {
|
||||||
|
return len(s.search.Entries)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LDAPSearch) GetEntry(number int) *LDAPEntry {
|
||||||
|
return &LDAPEntry{s.search.Entries[number]}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *LDAPEntry) GetRawAttributeValue(name string) []byte {
|
||||||
|
return e.entry.GetRawAttributeValue(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *LDAPEntry) GetAttributeValue(name string) string {
|
||||||
|
return e.entry.GetAttributeValue(name)
|
||||||
|
}
|
||||||
130
src/ldap/ldap_server.go
Normal file
130
src/ldap/ldap_server.go
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
package ldap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"astraltech.xyz/accountmanager/src/logging"
|
||||||
|
"github.com/go-ldap/ldap/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LDAPServer struct {
|
||||||
|
URL string
|
||||||
|
StartTLS bool
|
||||||
|
IgnoreInsecureCert bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LDAPServer) TestConnection() (bool, error) {
|
||||||
|
l, err := ldap.DialURL(s.URL)
|
||||||
|
l.Close()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// internal connect, should not be used regularly
|
||||||
|
func (s *LDAPServer) connect() (*ldap.Conn, error) {
|
||||||
|
l, err := ldap.DialURL(s.URL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.StartTLS {
|
||||||
|
err = l.StartTLS(&tls.Config{
|
||||||
|
InsecureSkipVerify: s.IgnoreInsecureCert,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
l.Close()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return l, nil
|
||||||
|
}
|
||||||
|
func (s *LDAPServer) connectAsUser(userDN, password string) (*ldap.Conn, error) {
|
||||||
|
conn, err := s.connect()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = conn.Bind(userDN, password)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return conn, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LDAPServer) AuthenticateUser(userDN, password string) (bool, error) {
|
||||||
|
conn, err := s.connectAsUser(userDN, password)
|
||||||
|
if err != nil || conn == nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
conn.Close()
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LDAPServer) SerchServer(
|
||||||
|
userDN string, password string,
|
||||||
|
baseDN string,
|
||||||
|
searchFilter string, attributes []string,
|
||||||
|
) (*LDAPSearch, error) {
|
||||||
|
logging.Debugf("Searching %s LDAP server\n\tBase DN: %s\n\tSearch Filter %s\n\tAttributes: %s", s.URL, baseDN, searchFilter, strings.Join(attributes, ","))
|
||||||
|
conn, err := s.connectAsUser(userDN, password)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
searchRequest := ldap.NewSearchRequest(
|
||||||
|
baseDN,
|
||||||
|
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
|
||||||
|
searchFilter, attributes,
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
sr, err := conn.Search(searchRequest)
|
||||||
|
if err != nil {
|
||||||
|
logging.Errorf("Failed to search LDAP server %s\n", err.Error())
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &LDAPSearch{sr}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LDAPServer) ChangePassword(userDN string, oldPassword string, newPassword string) error {
|
||||||
|
conn, err := s.connectAsUser(userDN, oldPassword)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
// Perform password modify extended operation
|
||||||
|
_, err = conn.PasswordModify(&ldap.PasswordModifyRequest{
|
||||||
|
UserIdentity: userDN,
|
||||||
|
OldPassword: oldPassword,
|
||||||
|
NewPassword: newPassword,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logging.Errorf("Password modify failed: %s", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logging.Infof("Password successfully changed for %s", userDN)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LDAPServer) ModifyAttribute(bindUserDN string, password string, userDN string, attribute string, data []string) error {
|
||||||
|
logging.Infof("Modifing LDAP attribute %s", attribute)
|
||||||
|
|
||||||
|
conn, err := s.connectAsUser(bindUserDN, password)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
modify := ldap.NewModifyRequest(userDN, nil)
|
||||||
|
modify.Replace(attribute, data)
|
||||||
|
err = conn.Modify(modify)
|
||||||
|
if err != nil {
|
||||||
|
logging.Errorf("Failed to modify %s", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
181
src/main/ldap.go
181
src/main/ldap.go
@@ -1,181 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"astraltech.xyz/accountmanager/src/logging"
|
|
||||||
"github.com/go-ldap/ldap/v3"
|
|
||||||
)
|
|
||||||
|
|
||||||
type LDAPServer struct {
|
|
||||||
URL string
|
|
||||||
StartTLS bool
|
|
||||||
IgnoreInsecureCert bool
|
|
||||||
Connection *ldap.Conn
|
|
||||||
}
|
|
||||||
|
|
||||||
type LDAPSearch struct {
|
|
||||||
Succeeded bool
|
|
||||||
LDAPSearch *ldap.SearchResult
|
|
||||||
}
|
|
||||||
|
|
||||||
func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) *LDAPServer {
|
|
||||||
logging.Debugf("Connecting to LDAP server %s", URL)
|
|
||||||
l, err := ldap.DialURL(URL)
|
|
||||||
if err != nil {
|
|
||||||
logging.Fatal("Failed to connect to LDAP server")
|
|
||||||
logging.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
logging.Infof("Connected to LDAP server")
|
|
||||||
|
|
||||||
if starttls {
|
|
||||||
logging.Debugf("Enabling StartTLS")
|
|
||||||
if err := l.StartTLS(&tls.Config{InsecureSkipVerify: ignore_cert}); err != nil {
|
|
||||||
logging.Errorf("StartTLS failed %s", err.Error())
|
|
||||||
}
|
|
||||||
logging.Infof("StartTLS enabled")
|
|
||||||
}
|
|
||||||
|
|
||||||
return &LDAPServer{
|
|
||||||
Connection: l,
|
|
||||||
URL: URL,
|
|
||||||
StartTLS: starttls,
|
|
||||||
IgnoreInsecureCert: ignore_cert,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func reconnectToLDAPServer(server *LDAPServer) error {
|
|
||||||
logging.Debugf("Reconnecting to %s LDAP server", server.URL)
|
|
||||||
if server == nil {
|
|
||||||
logging.Errorf("Cannot reconnect: server is nil")
|
|
||||||
return fmt.Errorf("Server is nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
l, err := ldap.DialURL(server.URL)
|
|
||||||
if err != nil {
|
|
||||||
logging.Errorf("Failed to connect to LDAP server (has server gone down)")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if server.StartTLS {
|
|
||||||
logging.Debugf("StartTLS enabling")
|
|
||||||
if err := l.StartTLS(&tls.Config{InsecureSkipVerify: server.IgnoreInsecureCert}); err != nil {
|
|
||||||
logging.Error("StartTLS failed")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
logging.Debugf("Successfully Started TLS")
|
|
||||||
}
|
|
||||||
|
|
||||||
server.Connection = l
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func connectAsLDAPUser(server *LDAPServer, bindDN, password string) error {
|
|
||||||
logging.Debugf("Connecting to %s LDAP server with %s BindDN", server.URL, bindDN)
|
|
||||||
if server == nil {
|
|
||||||
logging.Errorf("Failed to connect as user, LDAP server is NULL")
|
|
||||||
return fmt.Errorf("LDAP server is null")
|
|
||||||
}
|
|
||||||
|
|
||||||
if server.Connection == nil || server.Connection.IsClosing() {
|
|
||||||
err := reconnectToLDAPServer(server)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err := server.Connection.Bind(bindDN, password)
|
|
||||||
if err != nil {
|
|
||||||
logging.Errorf("Failed to bind to LDAP as user %s", err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func searchLDAPServer(server *LDAPServer, baseDN string, searchFilter string, attributes []string) LDAPSearch {
|
|
||||||
logging.Debugf("Searching %s LDAP server\n\tBase DN: %s\n\tSearch Filter %s\n\tAttributes: %s", server.URL, baseDN, searchFilter, strings.Join(attributes, ","))
|
|
||||||
if server == nil {
|
|
||||||
logging.Errorf("Server is nil, failed to search LDAP server")
|
|
||||||
return LDAPSearch{false, nil}
|
|
||||||
}
|
|
||||||
|
|
||||||
if server.Connection == nil {
|
|
||||||
reconnectToLDAPServer(server)
|
|
||||||
if server.Connection == nil {
|
|
||||||
return LDAPSearch{false, nil}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
searchRequest := ldap.NewSearchRequest(
|
|
||||||
baseDN,
|
|
||||||
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
|
|
||||||
searchFilter, attributes,
|
|
||||||
nil,
|
|
||||||
)
|
|
||||||
|
|
||||||
sr, err := server.Connection.Search(searchRequest)
|
|
||||||
if err != nil {
|
|
||||||
logging.Errorf("Failed to search LDAP server %s\n", err.Error())
|
|
||||||
return LDAPSearch{false, nil}
|
|
||||||
}
|
|
||||||
|
|
||||||
return LDAPSearch{true, sr}
|
|
||||||
}
|
|
||||||
|
|
||||||
func modifyLDAPAttribute(server *LDAPServer, userDN string, attribute string, data []string) error {
|
|
||||||
logging.Infof("Modifing LDAP attribute %s", attribute)
|
|
||||||
modify := ldap.NewModifyRequest(userDN, nil)
|
|
||||||
modify.Replace(attribute, data)
|
|
||||||
err := server.Connection.Modify(modify)
|
|
||||||
if err != nil {
|
|
||||||
logging.Errorf("Failed to modify %s", err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func changeLDAPPassword(server *LDAPServer, userDN, oldPassword, newPassword string) error {
|
|
||||||
logging.Infof("Changing LDAP password for %s", userDN)
|
|
||||||
|
|
||||||
if server == nil || server.Connection == nil {
|
|
||||||
return fmt.Errorf("LDAP connection not initialized")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure connection is alive
|
|
||||||
if server.Connection.IsClosing() {
|
|
||||||
if err := reconnectToLDAPServer(server); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bind as the user (required for FreeIPA self-password change)
|
|
||||||
err := server.Connection.Bind(userDN, oldPassword)
|
|
||||||
if err != nil {
|
|
||||||
logging.Errorf("Failed to bind as user: %s", err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform password modify extended operation
|
|
||||||
_, err = server.Connection.PasswordModify(&ldap.PasswordModifyRequest{
|
|
||||||
UserIdentity: userDN,
|
|
||||||
OldPassword: oldPassword,
|
|
||||||
NewPassword: newPassword,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logging.Errorf("Password modify failed: %s", err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
logging.Infof("Password successfully changed for %s", userDN)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func closeLDAPServer(server *LDAPServer) {
|
|
||||||
if server != nil && server.Connection != nil {
|
|
||||||
logging.Debug("Closing connection to LDAP server")
|
|
||||||
err := server.Connection.Close()
|
|
||||||
if err != nil {
|
|
||||||
logging.Errorf("Failed to close LDAP server %s", err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ldapEscapeFilter(input string) string { return ldap.EscapeFilter(input) }
|
|
||||||
228
src/main/main.go
228
src/main/main.go
@@ -3,24 +3,22 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
|
"astraltech.xyz/accountmanager/src/components"
|
||||||
|
"astraltech.xyz/accountmanager/src/helpers"
|
||||||
|
"astraltech.xyz/accountmanager/src/ldap"
|
||||||
"astraltech.xyz/accountmanager/src/logging"
|
"astraltech.xyz/accountmanager/src/logging"
|
||||||
"astraltech.xyz/accountmanager/src/session"
|
"astraltech.xyz/accountmanager/src/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ldapServer *LDAPServer
|
ldapServer ldap.LDAPServer
|
||||||
ldapServerMutex sync.Mutex
|
serverConfig *ServerConfig
|
||||||
serverConfig *ServerConfig
|
sessionManager *session.SessionManager
|
||||||
sessionManager *session.SessionManager
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserData struct {
|
type UserData struct {
|
||||||
@@ -30,62 +28,35 @@ type UserData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
userData = make(map[string]UserData)
|
userData = make(map[string]*UserData)
|
||||||
userDataMutex sync.RWMutex
|
userDataMutex sync.RWMutex
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
func authenticateUser(username, password string) (*UserData, error) {
|
||||||
photoCreatedTimestamp = make(map[string]time.Time)
|
|
||||||
photoCreatedMutex sync.Mutex
|
|
||||||
blankPhotoData []byte
|
|
||||||
)
|
|
||||||
|
|
||||||
func createUserPhoto(username string, photoData []byte) error {
|
|
||||||
Mkdir("./avatars", os.ModePerm)
|
|
||||||
|
|
||||||
path := fmt.Sprintf("./avatars/%s.jpeg", username)
|
|
||||||
cleaned := filepath.Clean(path)
|
|
||||||
dst, err := CreateFile(cleaned)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Could not save file")
|
|
||||||
}
|
|
||||||
photoCreatedMutex.Lock()
|
|
||||||
photoCreatedTimestamp[username] = time.Now()
|
|
||||||
photoCreatedMutex.Unlock()
|
|
||||||
defer dst.Close()
|
|
||||||
logging.Info("Writing to avarar file")
|
|
||||||
_, err = dst.Write(photoData)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func authenticateUser(username, password string) (UserData, error) {
|
|
||||||
logging.Event(logging.AuthenticateUser, username)
|
logging.Event(logging.AuthenticateUser, username)
|
||||||
ldapServerMutex.Lock()
|
|
||||||
defer ldapServerMutex.Unlock()
|
|
||||||
if ldapServer.Connection == nil {
|
|
||||||
return UserData{isAuth: false}, fmt.Errorf("LDAP server not connected")
|
|
||||||
}
|
|
||||||
userDN := fmt.Sprintf("uid=%s,cn=users,cn=accounts,%s", username, serverConfig.LDAPConfig.BaseDN)
|
userDN := fmt.Sprintf("uid=%s,cn=users,cn=accounts,%s", username, serverConfig.LDAPConfig.BaseDN)
|
||||||
connected := connectAsLDAPUser(ldapServer, userDN, password)
|
|
||||||
if connected != nil {
|
|
||||||
return UserData{isAuth: false}, connected
|
|
||||||
}
|
|
||||||
|
|
||||||
userSearch := searchLDAPServer(
|
connected, err := ldapServer.AuthenticateUser(userDN, password)
|
||||||
ldapServer,
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if connected == false {
|
||||||
|
logging.Debug("Failed to authenticate user")
|
||||||
|
return nil, fmt.Errorf("Failed to authenticate user %s", username)
|
||||||
|
}
|
||||||
|
logging.Info("User authenticated successfully")
|
||||||
|
|
||||||
|
userSearch, err := ldapServer.SerchServer(
|
||||||
|
userDN, password,
|
||||||
serverConfig.LDAPConfig.BaseDN,
|
serverConfig.LDAPConfig.BaseDN,
|
||||||
fmt.Sprintf("(&(objectClass=inetOrgPerson)(uid=%s))", ldapEscapeFilter(username)),
|
fmt.Sprintf("(&(objectClass=inetOrgPerson)(uid=%s))", ldap.LDAPEscapeFilter(username)),
|
||||||
[]string{"displayName", "mail", "jpegphoto"},
|
[]string{"displayName", "mail", "jpegphoto"},
|
||||||
)
|
)
|
||||||
if !userSearch.Succeeded {
|
if err != nil {
|
||||||
return UserData{isAuth: false}, fmt.Errorf("user metadata not found")
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
entry := userSearch.LDAPSearch.Entries[0]
|
entry := userSearch.GetEntry(0)
|
||||||
user := UserData{
|
user := UserData{
|
||||||
isAuth: true,
|
isAuth: true,
|
||||||
DisplayName: entry.GetAttributeValue("displayName"),
|
DisplayName: entry.GetAttributeValue("displayName"),
|
||||||
@@ -94,9 +65,9 @@ func authenticateUser(username, password string) (UserData, error) {
|
|||||||
|
|
||||||
photoData := entry.GetRawAttributeValue("jpegphoto")
|
photoData := entry.GetRawAttributeValue("jpegphoto")
|
||||||
if len(photoData) > 0 {
|
if len(photoData) > 0 {
|
||||||
createUserPhoto(username, photoData)
|
components.CreateUserPhoto(username, photoData)
|
||||||
}
|
}
|
||||||
return user, nil
|
return &user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginPageData struct {
|
type LoginPageData struct {
|
||||||
@@ -128,7 +99,7 @@ func loginHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
userData[username] = newUserData
|
userData[username] = newUserData
|
||||||
userDataMutex.Unlock()
|
userDataMutex.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
logging.Error(err.Error())
|
||||||
tmpl.Execute(w, LoginPageData{IsHiddenClassList: ""})
|
tmpl.Execute(w, LoginPageData{IsHiddenClassList: ""})
|
||||||
} else {
|
} else {
|
||||||
if newUserData.isAuth == true {
|
if newUserData.isAuth == true {
|
||||||
@@ -177,57 +148,6 @@ func profileHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func avatarHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "image/jpeg")
|
|
||||||
username := r.URL.Query().Get("user")
|
|
||||||
if strings.Contains(username, "/") {
|
|
||||||
w.Write(blankPhotoData)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
filePath := fmt.Sprintf("./avatars/%s.jpeg", username)
|
|
||||||
cleaned := filepath.Clean(filePath)
|
|
||||||
value, err := ReadFile(cleaned)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
photoCreatedMutex.Lock()
|
|
||||||
if time.Since(photoCreatedTimestamp[username]) <= 5*time.Minute {
|
|
||||||
photoCreatedMutex.Unlock()
|
|
||||||
w.Write(value)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
photoCreatedMutex.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
ldapServerMutex.Lock()
|
|
||||||
defer ldapServerMutex.Unlock()
|
|
||||||
connected := connectAsLDAPUser(ldapServer, serverConfig.LDAPConfig.BindDN, serverConfig.LDAPConfig.BindPassword)
|
|
||||||
if connected != nil {
|
|
||||||
w.Write(blankPhotoData)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
userSearch := searchLDAPServer(
|
|
||||||
ldapServer,
|
|
||||||
serverConfig.LDAPConfig.BaseDN,
|
|
||||||
fmt.Sprintf("(&(objectClass=inetOrgPerson)(uid=%s))", ldapEscapeFilter(username)),
|
|
||||||
[]string{"jpegphoto"},
|
|
||||||
)
|
|
||||||
if !userSearch.Succeeded || len(userSearch.LDAPSearch.Entries) == 0 {
|
|
||||||
w.Write(blankPhotoData)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
entry := userSearch.LDAPSearch.Entries[0]
|
|
||||||
bytes := entry.GetRawAttributeValue("jpegphoto")
|
|
||||||
if len(bytes) == 0 {
|
|
||||||
w.Write(blankPhotoData)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
w.Write(bytes)
|
|
||||||
createUserPhoto(username, bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func logoutHandler(w http.ResponseWriter, r *http.Request) {
|
func logoutHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
cookie, err := r.Cookie("session_token")
|
cookie, err := r.Cookie("session_token")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -251,48 +171,6 @@ func logoutHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadPhotoHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
sessionData, err := sessionManager.GetSession(r)
|
|
||||||
if err != nil {
|
|
||||||
logging.Error(err.Error())
|
|
||||||
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.UserID, serverConfig.LDAPConfig.BaseDN)
|
|
||||||
ldapServerMutex.Lock()
|
|
||||||
defer ldapServerMutex.Unlock()
|
|
||||||
modifyLDAPAttribute(ldapServer, userDN, "jpegphoto", []string{string(data)})
|
|
||||||
createUserPhoto(sessionData.UserID, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func faviconHandler(w http.ResponseWriter, r *http.Request) {
|
func faviconHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
logging.Info("Requesting Favicon")
|
logging.Info("Requesting Favicon")
|
||||||
http.ServeFile(w, r, serverConfig.StyleConfig.FaviconPath)
|
http.ServeFile(w, r, serverConfig.StyleConfig.FaviconPath)
|
||||||
@@ -343,7 +221,7 @@ func changePasswordHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
serverConfig.LDAPConfig.BaseDN,
|
serverConfig.LDAPConfig.BaseDN,
|
||||||
)
|
)
|
||||||
|
|
||||||
err = changeLDAPPassword(ldapServer, userDN, oldPassword, newPassword)
|
err = ldapServer.ChangePassword(userDN, oldPassword, newPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
|
||||||
@@ -363,37 +241,47 @@ func changePasswordHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logging.Info("Starting the server")
|
logging.Info("Starting the server")
|
||||||
sessionManager = session.CreateSessionManager(session.InMemory)
|
sessionManager = session.GetSessionManager()
|
||||||
|
sessionManager.SetStoreType(session.InMemory)
|
||||||
|
|
||||||
var err error = nil
|
var err error
|
||||||
blankPhotoData, err = ReadFile("static/blank_profile.jpg")
|
|
||||||
if err != nil {
|
|
||||||
logging.Fatal("Could not load blank profile image")
|
|
||||||
}
|
|
||||||
serverConfig, err = loadServerConfig("./data/config.json")
|
serverConfig, err = loadServerConfig("./data/config.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Could not load server config")
|
log.Fatal("Could not load server config")
|
||||||
}
|
}
|
||||||
|
|
||||||
ldapServerMutex.Lock()
|
ldapServer = ldap.LDAPServer{
|
||||||
server := connectToLDAPServer(serverConfig.LDAPConfig.LDAPURL, serverConfig.LDAPConfig.Security == "tls", serverConfig.LDAPConfig.IgnoreInvalidCert)
|
URL: serverConfig.LDAPConfig.LDAPURL,
|
||||||
ldapServer = server
|
StartTLS: serverConfig.LDAPConfig.Security == "tls",
|
||||||
ldapServerMutex.Unlock()
|
IgnoreInsecureCert: serverConfig.LDAPConfig.IgnoreInvalidCert,
|
||||||
defer closeLDAPServer(ldapServer)
|
}
|
||||||
|
|
||||||
HandleFunc("/favicon.ico", faviconHandler)
|
components.LDAPServer = &ldapServer
|
||||||
HandleFunc("/logo", logoHandler)
|
components.BaseDN = serverConfig.LDAPConfig.BaseDN
|
||||||
|
components.ServiceUserBindDN = serverConfig.LDAPConfig.BindDN
|
||||||
|
components.ServiceUserPassword = serverConfig.LDAPConfig.BindPassword
|
||||||
|
|
||||||
|
connected, err := ldapServer.TestConnection()
|
||||||
|
if connected != true || err != nil {
|
||||||
|
if err != nil {
|
||||||
|
logging.Error(err.Error())
|
||||||
|
}
|
||||||
|
logging.Fatal("Failed to connect to LDAP server")
|
||||||
|
}
|
||||||
|
|
||||||
|
helpers.HandleFunc("/favicon.ico", faviconHandler)
|
||||||
|
helpers.HandleFunc("/logo", logoHandler)
|
||||||
|
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||||
HandleFunc("/login", loginHandler)
|
helpers.HandleFunc("/login", loginHandler)
|
||||||
HandleFunc("/profile", profileHandler)
|
helpers.HandleFunc("/profile", profileHandler)
|
||||||
HandleFunc("/logout", logoutHandler)
|
helpers.HandleFunc("/logout", logoutHandler)
|
||||||
|
|
||||||
HandleFunc("/avatar", avatarHandler)
|
helpers.HandleFunc("/avatar", components.AvatarHandler)
|
||||||
HandleFunc("/change-photo", uploadPhotoHandler)
|
helpers.HandleFunc("/change-photo", components.UploadPhotoHandler)
|
||||||
HandleFunc("/change-password", changePasswordHandler)
|
helpers.HandleFunc("/change-password", changePasswordHandler)
|
||||||
|
|
||||||
HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
helpers.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/profile", http.StatusFound) // 302 redirect
|
http.Redirect(w, r, "/profile", http.StatusFound) // 302 redirect
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,16 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="input_label">Password</label><br />
|
<label class="input_label">Password</label><br />
|
||||||
<input type="password" name="password" placeholder="" required />
|
<div class="password_box">
|
||||||
|
<input type="password" name="password" placeholder="" required />
|
||||||
|
<button type="button" class="show_password_toggle closed"></button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit">Login</button>
|
<button type="submit">Login</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script src="/static/error/error.js" type="text/javascript"></script>
|
<script src="/static/error/error.js" type="text/javascript"></script>
|
||||||
|
<script
|
||||||
|
src="/static/javascript/show_password.js"
|
||||||
|
type="text/javascript"
|
||||||
|
></script>
|
||||||
|
|||||||
@@ -9,14 +9,24 @@
|
|||||||
<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 hidden"></div>
|
||||||
|
|
||||||
<div id="change_password_dialogue" class="hidden card static_center">
|
<div id="change_password_dialogue" class="card static_center hidden">
|
||||||
Change Password
|
<div class="dialouge_title">Change Password</div>
|
||||||
|
|
||||||
<button id="close_password_dialogue">X</button>
|
<button id="close_password_dialogue">X</button>
|
||||||
|
|
||||||
|
<hr
|
||||||
|
style="
|
||||||
|
border: 0;
|
||||||
|
border-top: 1px solid var(--border-subtle);
|
||||||
|
margin: 20px 0;
|
||||||
|
margin-bottom: 0px;
|
||||||
|
margin-top: 0px;
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
|
||||||
<div id="password_error" class="error hidden">
|
<div id="password_error" class="error hidden">
|
||||||
<div id="password_text"></div>
|
<div id="password_text"></div>
|
||||||
<button id="password_error_close_button" class="close_error_button">
|
<button id="password_error_close_button" class="close_error_button">
|
||||||
@@ -26,37 +36,68 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="input_label">Current password</label><br />
|
<label class="input_label">Current password</label><br />
|
||||||
<input
|
<div class="password_box">
|
||||||
type="password"
|
<input
|
||||||
id="current_password"
|
type="password"
|
||||||
name="current_password"
|
id="current_password"
|
||||||
placeholder=""
|
name="current_password"
|
||||||
required
|
placeholder=""
|
||||||
/>
|
required
|
||||||
|
/>
|
||||||
|
<button type="button" class="show_password_toggle closed"></button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="input_label">New password</label><br />
|
<label class="input_label">New password</label><br />
|
||||||
<input
|
<div class="password_box">
|
||||||
type="password"
|
<input
|
||||||
id="new_password"
|
type="password"
|
||||||
name="new_password"
|
id="new_password"
|
||||||
placeholder=""
|
name="new_password"
|
||||||
required
|
placeholder=""
|
||||||
/>
|
required
|
||||||
|
/>
|
||||||
|
<button type="button" class="show_password_toggle closed"></button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="input_label">New password (repeat)</label><br />
|
<label class="input_label">New password (repeat)</label><br />
|
||||||
<input
|
<div class="password_box">
|
||||||
type="password"
|
<input
|
||||||
id="new_password_repeat"
|
type="password"
|
||||||
name="new_password_repeat"
|
id="new_password_repeat"
|
||||||
placeholder=""
|
name="new_password_repeat"
|
||||||
required
|
placeholder=""
|
||||||
/>
|
required
|
||||||
|
/>
|
||||||
|
<button type="button" class="show_password_toggle closed"></button>
|
||||||
|
</div>
|
||||||
</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>
|
||||||
|
|
||||||
|
<!--<div id="password_errors">
|
||||||
|
<div class="password_error">Error 1</div>
|
||||||
|
<div class="password_error">Error 2</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="password_warnings">
|
||||||
|
<div class="password_error">Error 1</div>
|
||||||
|
<div class="password_error">Error 2</div>
|
||||||
|
</div>-->
|
||||||
|
|
||||||
<button id="final_change_password_button">Change Password</button>
|
<button id="final_change_password_button">Change Password</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -80,7 +121,7 @@
|
|||||||
|
|
||||||
<button id="edit_picture_button">
|
<button id="edit_picture_button">
|
||||||
<img
|
<img
|
||||||
src="/static/crayon_icon.png"
|
src="/static/images/crayon_icon.png"
|
||||||
id="edit_picture_image"
|
id="edit_picture_image"
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
@@ -136,96 +177,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 +216,17 @@
|
|||||||
});
|
});
|
||||||
</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>
|
||||||
|
|
||||||
|
<script
|
||||||
|
src="/static/javascript/show_password.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
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package session
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"astraltech.xyz/accountmanager/src/logging"
|
"astraltech.xyz/accountmanager/src/logging"
|
||||||
@@ -13,22 +14,31 @@ type SessionManager struct {
|
|||||||
store SessionStore
|
store SessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var instance *SessionManager
|
||||||
|
var once sync.Once
|
||||||
|
|
||||||
type StoreType int
|
type StoreType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
InMemory StoreType = iota
|
InMemory StoreType = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateSessionManager(storeType StoreType) *SessionManager {
|
func GetSessionManager() *SessionManager {
|
||||||
sessionManager := SessionManager{}
|
once.Do(func() {
|
||||||
|
instance = &SessionManager{}
|
||||||
|
})
|
||||||
|
return instance
|
||||||
|
}
|
||||||
|
|
||||||
|
func (manager *SessionManager) SetStoreType(storeType StoreType) {
|
||||||
|
logging.Infof("Changing session manager store type")
|
||||||
switch storeType {
|
switch storeType {
|
||||||
case InMemory:
|
case InMemory:
|
||||||
{
|
{
|
||||||
sessionManager.store = NewMemoryStore()
|
manager.store = NewMemoryStore()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &sessionManager
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManager) CreateSession(userID string) (cookie *http.Cookie, err error) {
|
func (manager *SessionManager) CreateSession(userID string) (cookie *http.Cookie, err error) {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
BIN
static/images/closed_eye.png
Normal file
BIN
static/images/closed_eye.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
BIN
static/images/filled_eye.png
Normal file
BIN
static/images/filled_eye.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
106
static/javascript/handle_password_change.js
Normal file
106
static/javascript/handle_password_change.js
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
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");
|
||||||
|
|
||||||
|
const currentPasswordButton = document.getElementById("current_password"),
|
||||||
|
newPasswordButton = document.getElementById("new_password"),
|
||||||
|
newPasswordRepeatButton = document.getElementById("new_password_repeat");
|
||||||
|
|
||||||
|
const strengh_label = document.getElementById("strengh-label");
|
||||||
|
const password_progress = document.getElementById("password-progress");
|
||||||
|
|
||||||
|
popup_botton.addEventListener("click", () => {
|
||||||
|
document.getElementById("popup_background").classList.remove("hidden");
|
||||||
|
document
|
||||||
|
.getElementById("change_password_dialogue")
|
||||||
|
.classList.remove("hidden");
|
||||||
|
|
||||||
|
currentPasswordButton.value = "";
|
||||||
|
newPasswordButton.value = "";
|
||||||
|
newPasswordRepeatButton.value = "";
|
||||||
|
strengh_label.innerText = "Strength: Weak";
|
||||||
|
password_progress.style.width = "0%";
|
||||||
|
});
|
||||||
|
|
||||||
|
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 (currentPasswordButton.value === "") {
|
||||||
|
displayError("Please enter current password");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPasswordButton.value === "") {
|
||||||
|
displayError("No value for new password");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPasswordRepeatButton.value === "") {
|
||||||
|
displayError("Please repeat new password");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPasswordButton.value !== newPasswordRepeatButton.value) {
|
||||||
|
displayError("New passwords do not match");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append(
|
||||||
|
"csrf_token",
|
||||||
|
document.getElementById("csrf_token_storage").value,
|
||||||
|
);
|
||||||
|
formData.append("old_password", currentPasswordButton.value);
|
||||||
|
formData.append("new_password", newPasswordButton.value);
|
||||||
|
formData.append("new_password_repeat", newPasswordRepeatButton.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;
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
22
static/javascript/show_password.js
Normal file
22
static/javascript/show_password.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
const showPasswordButtons = document.getElementsByClassName(
|
||||||
|
"show_password_toggle",
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const button of showPasswordButtons) {
|
||||||
|
button.addEventListener("click", function () {
|
||||||
|
const input = this.parentElement.querySelector(
|
||||||
|
"input[type='password'], input[type='text']",
|
||||||
|
);
|
||||||
|
if (!input) return;
|
||||||
|
const isHidden = input.type === "password";
|
||||||
|
input.type = isHidden ? "text" : "password";
|
||||||
|
|
||||||
|
if (isHidden) {
|
||||||
|
this.classList.add("open");
|
||||||
|
this.classList.remove("closed");
|
||||||
|
} else {
|
||||||
|
this.classList.remove("open");
|
||||||
|
this.classList.add("closed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -128,7 +128,31 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#close_password_dialogue {
|
#close_password_dialogue {
|
||||||
width: fit-content;
|
display: inline-block;
|
||||||
|
aspect-ratio: 1 / 1;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 2.5rem;
|
right: 2.5rem;
|
||||||
|
padding: 0px;
|
||||||
|
margin: 0px;
|
||||||
|
width: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#password_errors {
|
||||||
|
background-color: var(--error-red);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 20px;
|
||||||
|
border-color: var(--error-border-red);
|
||||||
|
border-width: 2px;
|
||||||
|
border-style: solid;
|
||||||
|
color: var(--text-main);
|
||||||
|
}
|
||||||
|
|
||||||
|
#password_warnings {
|
||||||
|
background-color: var(--warning-yellow);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 20px;
|
||||||
|
border-color: var(--warning-border-yellow);
|
||||||
|
border-width: 2px;
|
||||||
|
border-style: solid;
|
||||||
|
color: var(--text-main);
|
||||||
}
|
}
|
||||||
|
|||||||
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,13 @@
|
|||||||
--error-red: #ef4444; /* Professional Red */
|
--error-red: #ef4444; /* Professional Red */
|
||||||
--error-border-red: #e22d2d;
|
--error-border-red: #e22d2d;
|
||||||
|
|
||||||
|
--warning-yellow: #fef08a;
|
||||||
|
--warning-border-yellow: #fde047;
|
||||||
|
|
||||||
|
--password-strength-weak: var(--error-red);
|
||||||
|
--password-strength-medium: var(--warning-border-yellow);
|
||||||
|
--password-strength-strong: #43ef6b;
|
||||||
|
|
||||||
font-family: "Inter", sans-serif;
|
font-family: "Inter", sans-serif;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
}
|
}
|
||||||
@@ -39,6 +46,10 @@ button:hover {
|
|||||||
background-color: var(--primary-hover);
|
background-color: var(--primary-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button:focus {
|
||||||
|
outline: 2px solid var(--primary-accent);
|
||||||
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
background-color: var(--bg-input);
|
background-color: var(--bg-input);
|
||||||
@@ -47,6 +58,10 @@ input {
|
|||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input:focus {
|
||||||
|
outline: 2px solid var(--primary-accent);
|
||||||
|
}
|
||||||
|
|
||||||
input::placeholder {
|
input::placeholder {
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
}
|
}
|
||||||
@@ -70,6 +85,47 @@ input::placeholder {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
z-index: 9999; /* higher = on top */
|
z-index: 9999; /* higher = on top */
|
||||||
|
|
||||||
background-color: black;
|
backdrop-filter: blur(4px);
|
||||||
opacity: 10%;
|
background-color: rgba(0, 0, 0, 0.3);
|
||||||
|
pointer-events: all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialouge_title {
|
||||||
|
font-size: 20px;
|
||||||
|
margin-bottom: 0px;
|
||||||
|
color: var(--text-main) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.password_box {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.show_password_toggle {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
position: absolute;
|
||||||
|
right: 5px;
|
||||||
|
bottom: 50%;
|
||||||
|
transform: translateY(50%);
|
||||||
|
background-size: contain;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
background-color: rgba(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.show_password_toggle.closed {
|
||||||
|
background-image: url("/static/images/closed_eye.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
.show_password_toggle.open {
|
||||||
|
background-image: url("/static/images/filled_eye.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
.show_password_toggle:hover {
|
||||||
|
background-color: rgba(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.show_password_toggle:focus {
|
||||||
|
outline: none !important;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user