Rewrote account switching, fix some minor bugs here and there

This commit is contained in:
Mukhtar Akere
2025-09-16 21:15:24 +01:00
parent 76f5b85313
commit 30b2db06e7
34 changed files with 945 additions and 866 deletions
+5 -4
View File
@@ -3,9 +3,10 @@ package web
import (
"encoding/json"
"fmt"
"github.com/sirrobot01/decypharr/internal/config"
"net/http"
"strings"
"github.com/sirrobot01/decypharr/internal/config"
)
func (wb *Web) setupMiddleware(next http.Handler) http.Handler {
@@ -79,7 +80,7 @@ func (wb *Web) sendJSONError(w http.ResponseWriter, message string, statusCode i
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(statusCode)
json.NewEncoder(w).Encode(map[string]interface{}{
"error": message,
"status": statusCode,
"error": message,
"status": statusCode,
})
}
}
+4
View File
@@ -371,6 +371,9 @@
const statusBadge = account.disabled ?
'<span class="badge badge-error badge-sm">Disabled</span>' :
'<span class="badge badge-success badge-sm">Active</span>';
const inUseBadge = account.in_use ?
'<span class="badge badge-info badge-sm">In Use</span>' :
'';
html += `
<div class="card bg-base-100 compact">
@@ -380,6 +383,7 @@
<div class="flex items-center gap-2">
<h5 class="font-medium text-sm">Account #${account.order + 1}</h5>
${statusBadge}
${inUseBadge}
</div>
<p class="text-xs text-base-content/70 mt-1">${account.username || 'No username'}</p>
</div>
+2 -1
View File
@@ -2,9 +2,10 @@ package web
import (
"encoding/json"
"net/http"
"github.com/sirrobot01/decypharr/internal/config"
"golang.org/x/crypto/bcrypt"
"net/http"
)
func (wb *Web) LoginHandler(w http.ResponseWriter, r *http.Request) {
+5 -5
View File
@@ -1,14 +1,14 @@
package web
import (
"cmp"
"embed"
"html/template"
"github.com/gorilla/sessions"
"github.com/rs/zerolog"
"github.com/sirrobot01/decypharr/internal/config"
"github.com/sirrobot01/decypharr/internal/logger"
"github.com/sirrobot01/decypharr/pkg/wire"
"html/template"
"os"
)
var restartFunc func()
@@ -64,6 +64,7 @@ type Web struct {
}
func New() *Web {
cfg := config.Get()
templates := template.Must(template.ParseFS(
content,
"templates/layout.html",
@@ -75,8 +76,7 @@ func New() *Web {
"templates/login.html",
"templates/register.html",
))
secretKey := cmp.Or(os.Getenv("DECYPHARR_SECRET_KEY"), "\"wqj(v%lj*!-+kf@4&i95rhh_!5_px5qnuwqbr%cjrvrozz_r*(\"")
cookieStore := sessions.NewCookieStore([]byte(secretKey))
cookieStore := sessions.NewCookieStore([]byte(cfg.SecretKey()))
cookieStore.Options = &sessions.Options{
Path: "/",
MaxAge: 86400 * 7,