diff --git a/handler/download/file/file.go b/handler/file/download/download.go similarity index 99% rename from handler/download/file/file.go rename to handler/file/download/download.go index 5e48442..22176cc 100644 --- a/handler/download/file/file.go +++ b/handler/file/download/download.go @@ -1,4 +1,4 @@ -package downloadFileHandler +package downloadHandler import ( "fmt" diff --git a/handler/download/download.go b/handler/file/file.go similarity index 72% rename from handler/download/download.go rename to handler/file/file.go index 277bf1e..a39abf3 100644 --- a/handler/download/download.go +++ b/handler/file/file.go @@ -1,37 +1,38 @@ -package downloadHandler +package fileHandler import ( + "fmt" "github.com/fossyy/filekeeper/app" - "github.com/fossyy/filekeeper/view/client/download" - "net/http" - "github.com/fossyy/filekeeper/types" "github.com/fossyy/filekeeper/utils" + fileView "github.com/fossyy/filekeeper/view/client/file" + "net/http" + "strconv" ) func GET(w http.ResponseWriter, r *http.Request) { userSession := r.Context().Value("user").(types.User) files, err := app.Server.Database.GetFiles(userSession.UserID.String()) if err != nil { + fmt.Println(err.Error()) w.WriteHeader(http.StatusInternalServerError) return } - var filesData []types.FileData for i := 0; i < len(files); i++ { filesData = append(filesData, types.FileData{ ID: files[i].ID.String(), Name: files[i].Name, Size: utils.ConvertFileSize(files[i].Size), - Downloaded: files[i].Downloaded, + Downloaded: strconv.FormatUint(files[i].Downloaded, 10), }) } - component := downloadView.Main("Filekeeper - Download Page", filesData) + component := fileView.Main("File Dashboard", filesData, userSession) err = component.Render(r.Context(), w) if err != nil { + fmt.Println(err.Error()) w.WriteHeader(http.StatusInternalServerError) - app.Server.Logger.Error(err.Error()) return } } diff --git a/handler/upload/upload.go b/handler/file/upload/upload.go similarity index 89% rename from handler/upload/upload.go rename to handler/file/upload/upload.go index 97b5ade..fc0d876 100644 --- a/handler/upload/upload.go +++ b/handler/file/upload/upload.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/fossyy/filekeeper/app" "github.com/fossyy/filekeeper/types" - filesView "github.com/fossyy/filekeeper/view/client/upload" "io" "net/http" "os" @@ -13,14 +12,6 @@ import ( "strings" ) -func GET(w http.ResponseWriter, r *http.Request) { - component := filesView.Main("Filekeeper - Upload") - if err := component.Render(r.Context(), w); err != nil { - w.WriteHeader(http.StatusInternalServerError) - return - } -} - func POST(w http.ResponseWriter, r *http.Request) { fileID := r.PathValue("id") if err := r.ParseMultipartForm(32 << 20); err != nil { diff --git a/handler/user/totp/setup.go b/handler/user/totp/setup.go index 89b2817..f622fc0 100644 --- a/handler/user/totp/setup.go +++ b/handler/user/totp/setup.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/base64" "fmt" + "github.com/a-h/templ" "github.com/fossyy/filekeeper/app" "github.com/fossyy/filekeeper/view/client/user/totp" "image/png" @@ -41,10 +42,18 @@ func GET(w http.ResponseWriter, r *http.Request) { return } - component := userTotpSetupView.Main("Filekeeper - 2FA Setup Page", base64Str, secret, userSession, types.Message{ - Code: 3, - Message: "", - }) + var component templ.Component + if r.Header.Get("hx-request") == "true" { + component = userTotpSetupView.MainContent(base64Str, secret, userSession, types.Message{ + Code: 3, + Message: "", + }) + } else { + component = userTotpSetupView.Main("Filekeeper - 2FA Setup Page", base64Str, secret, userSession, types.Message{ + Code: 3, + Message: "", + }) + } if err := component.Render(r.Context(), w); err != nil { w.WriteHeader(http.StatusInternalServerError) return @@ -69,26 +78,42 @@ func POST(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) return } + var component templ.Component if totp.Verify(code, time.Now().Unix()) { if err := app.Server.Database.InitializeTotp(userSession.Email, secret); err != nil { w.WriteHeader(http.StatusInternalServerError) return } app.Server.Service.DeleteUser(userSession.Email) - component := userTotpSetupView.Main("Filekeeper - 2FA Setup Page", base64Str, secret, userSession, types.Message{ - Code: 1, - Message: "Your TOTP setup is complete! Your account is now more secure.", - }) + if r.Header.Get("hx-request") == "true" { + component = userTotpSetupView.MainContent(base64Str, secret, userSession, types.Message{ + Code: 1, + Message: "Your TOTP setup is complete! Your account is now more secure.", + }) + } else { + component = userTotpSetupView.Main("Filekeeper - 2FA Setup Page", base64Str, secret, userSession, types.Message{ + Code: 1, + Message: "Your TOTP setup is complete! Your account is now more secure.", + }) + } + if err := component.Render(r.Context(), w); err != nil { w.WriteHeader(http.StatusInternalServerError) return } return } else { - component := userTotpSetupView.Main("Filekeeper - 2FA Setup Page", base64Str, secret, userSession, types.Message{ - Code: 0, - Message: "The code you entered is incorrect. Please double-check the code and try again.", - }) + if r.Header.Get("hx-request") == "true" { + component = userTotpSetupView.MainContent(base64Str, secret, userSession, types.Message{ + Code: 0, + Message: "The code you entered is incorrect. Please double-check the code and try again.", + }) + } else { + component = userTotpSetupView.Main("Filekeeper - 2FA Setup Page", base64Str, secret, userSession, types.Message{ + Code: 0, + Message: "The code you entered is incorrect. Please double-check the code and try again.", + }) + } if err := component.Render(r.Context(), w); err != nil { w.WriteHeader(http.StatusInternalServerError) return diff --git a/handler/user/user.go b/handler/user/user.go index fd3a9ce..510de35 100644 --- a/handler/user/user.go +++ b/handler/user/user.go @@ -61,7 +61,6 @@ func GET(w http.ResponseWriter, r *http.Request) { handlerWS(upgrade, userSession) } - var component templ.Component sessions, err := session.GetSessions(userSession.Email) if err != nil { w.WriteHeader(http.StatusInternalServerError) @@ -86,21 +85,35 @@ func GET(w http.ResponseWriter, r *http.Request) { AllowanceUsedPercent: fmt.Sprintf("%.2f", float64(usage)/float64(allowance.AllowanceByte)*100), } + var component templ.Component if err := r.URL.Query().Get("error"); err != "" { message, ok := errorMessages[err] if !ok { message = "Unknown error occurred. Please contact support at bagas@fossy.my.id for assistance." } - - component = userView.Main("Filekeeper - User Page", userSession, allowanceStats, sessions, types.Message{ - Code: 0, - Message: message, - }) + if r.Header.Get("hx-request") == "true" { + component = userView.MainContent(userSession, allowanceStats, sessions, types.Message{ + Code: 0, + Message: message, + }) + } else { + component = userView.Main("Filekeeper - User Page", userSession, allowanceStats, sessions, types.Message{ + Code: 0, + Message: message, + }) + } } else { - component = userView.Main("Filekeeper - User Page", userSession, allowanceStats, sessions, types.Message{ - Code: 1, - Message: "", - }) + if r.Header.Get("hx-request") == "true" { + component = userView.MainContent(userSession, allowanceStats, sessions, types.Message{ + Code: 1, + Message: "", + }) + } else { + component = userView.Main("Filekeeper - User Page", userSession, allowanceStats, sessions, types.Message{ + Code: 1, + Message: "", + }) + } } err = component.Render(r.Context(), w) if err != nil { diff --git a/public/main.js b/public/main.js index d6dcced..65b09be 100644 --- a/public/main.js +++ b/public/main.js @@ -78,55 +78,32 @@ async function handleFile(file){ function addNewUploadElement(file){ const newDiv = document.createElement('div'); newDiv.innerHTML = ` -
-
-
- - - - -
-

${ file.name }

-

${ convertFileSize(file.size) }

-
-
- -
-
-
- -
-
- -
- Starting... -
-
Uploading 0%
-
+
+
+
+
+ + + + +
+ 0% +
+
+
+ ${ file.name } +
+ +
+
Starting...
+
+
+ +
+
`; - document.getElementById('container').appendChild(newDiv); + document.getElementById('FileUploadBoxItem').appendChild(newDiv); + document.getElementById('uploadBox').classList.remove('hidden'); } function convertFileSize(sizeInBytes) { @@ -150,7 +127,6 @@ async function splitFile(file, chunkSize) { const start = i * chunkSize; const end = Math.min(fileSize, start + chunkSize); const chunk = file.slice(start, end); - chunk.hash = "test" fileChunks.push(chunk); } @@ -171,7 +147,6 @@ async function uploadChunks(name, size, chunks, chunkArray, FileID) { let progress1 = document.getElementById(`progress-${name}-1`); let progress2 = document.getElementById(`progress-${name}-2`); let progress3 = document.getElementById(`progress-${name}-3`); - let progress4 = document.getElementById(`progress-${name}-4`); let isFailed = false for (let index = 0; index < chunks.length; index++) { const percentComplete = Math.round((index + 1) / chunks.length * 100); @@ -183,12 +158,12 @@ async function uploadChunks(name, size, chunks, chunkArray, FileID) { formData.append('index', index); formData.append('done', false); - progress1.setAttribute("aria-valuenow", percentComplete); - progress2.style.width = `${percentComplete}%`; + progress1.style.strokeDashoffset = 100 - percentComplete; + progress2.innerText = `${percentComplete}%`; const startTime = performance.now(); try { - await fetch(`/upload/${FileID}`, { + await fetch(`/file/${FileID}`, { method: 'POST', body: formData }); @@ -203,22 +178,18 @@ async function uploadChunks(name, size, chunks, chunkArray, FileID) { const totalTime = (endTime - startTime) / 1000; const uploadSpeed = chunk.size / totalTime / 1024 / 1024; byteUploaded += chunk.size - progress3.innerText = `${uploadSpeed.toFixed(2)} MB/s`; - progress4.innerText = `Uploading ${percentComplete}% - ${convertFileSize(byteUploaded)} of ${ convertFileSize(size)}`; + progress3.innerText = `Uploading... ${uploadSpeed.toFixed(2)} MB/s`; } else { - progress1.setAttribute("aria-valuenow", percentComplete); - progress2.style.width = `${percentComplete}%`; + progress1.style.strokeDashoffset = 100 - percentComplete; + progress2.innerText = `${percentComplete}%`; progress3.innerText = `Fixing Missing Byte`; - progress4.innerText = `Uploading Missing Byte ${percentComplete}% - ${convertFileSize(byteUploaded)} of ${ convertFileSize(size)}`; byteUploaded += chunk.size } } if (isFailed) { progress3.innerText = `Upload Failed`; - progress4.innerText = `There was an issue uploading the file. Please try again.`; } else { progress3.innerText = `Done`; - progress4.innerText = `File Uploaded 100% - ${convertFileSize(byteUploaded)} of ${ convertFileSize(size)}`; } } diff --git a/routes/client/routes.go b/routes/client/routes.go index 3930f00..72b92f7 100644 --- a/routes/client/routes.go +++ b/routes/client/routes.go @@ -5,8 +5,9 @@ import ( googleOauthCallbackHandler "github.com/fossyy/filekeeper/handler/auth/google/callback" googleOauthSetupHandler "github.com/fossyy/filekeeper/handler/auth/google/setup" totpHandler "github.com/fossyy/filekeeper/handler/auth/totp" - downloadHandler "github.com/fossyy/filekeeper/handler/download" - downloadFileHandler "github.com/fossyy/filekeeper/handler/download/file" + fileHandler "github.com/fossyy/filekeeper/handler/file" + downloadHandler "github.com/fossyy/filekeeper/handler/file/download" + uploadHandler "github.com/fossyy/filekeeper/handler/file/upload" forgotPasswordHandler "github.com/fossyy/filekeeper/handler/forgotPassword" forgotPasswordVerifyHandler "github.com/fossyy/filekeeper/handler/forgotPassword/verify" indexHandler "github.com/fossyy/filekeeper/handler/index" @@ -14,7 +15,6 @@ import ( signinHandler "github.com/fossyy/filekeeper/handler/signin" signupHandler "github.com/fossyy/filekeeper/handler/signup" signupVerifyHandler "github.com/fossyy/filekeeper/handler/signup/verify" - uploadHandler "github.com/fossyy/filekeeper/handler/upload" userHandler "github.com/fossyy/filekeeper/handler/user" userHandlerResetPassword "github.com/fossyy/filekeeper/handler/user/ResetPassword" userSessionTerminateHandler "github.com/fossyy/filekeeper/handler/user/session/terminate" @@ -109,20 +109,16 @@ func SetupRoutes() *http.ServeMux { middleware.Auth(userHandlerTotpSetup.POST, w, r) }) - handler.HandleFunc("GET /upload", func(w http.ResponseWriter, r *http.Request) { - middleware.Auth(uploadHandler.GET, w, r) + handler.HandleFunc("GET /file", func(w http.ResponseWriter, r *http.Request) { + middleware.Auth(fileHandler.GET, w, r) }) - handler.HandleFunc("POST /upload/{id}", func(w http.ResponseWriter, r *http.Request) { + handler.HandleFunc("POST /file/{id}", func(w http.ResponseWriter, r *http.Request) { middleware.Auth(uploadHandler.POST, w, r) }) - handler.HandleFunc("GET /download", func(w http.ResponseWriter, r *http.Request) { - middleware.Auth(downloadHandler.GET, w, r) - }) - - handler.HandleFunc("GET /download/{id}", func(w http.ResponseWriter, r *http.Request) { - downloadFileHandler.GET(w, r) + handler.HandleFunc("GET /file/{id}", func(w http.ResponseWriter, r *http.Request) { + downloadHandler.GET(w, r) }) handler.HandleFunc("GET /logout", func(w http.ResponseWriter, r *http.Request) { diff --git a/types/types.go b/types/types.go index 506d1be..2a15117 100644 --- a/types/types.go +++ b/types/types.go @@ -30,7 +30,7 @@ type FileData struct { ID string Name string Size string - Downloaded uint64 + Downloaded string } type FileWithDetail struct { diff --git a/view/client/download/download.templ b/view/client/download/download.templ deleted file mode 100644 index feac8bd..0000000 --- a/view/client/download/download.templ +++ /dev/null @@ -1,76 +0,0 @@ -package downloadView - -import ( - "github.com/fossyy/filekeeper/view/client/layout" - "github.com/fossyy/filekeeper/types" -) - -templ component(title string, files []types.FileData){ - @layout.BaseAuth(title){ -
-
-
-
-

Download Files

-
-
-
- for _, file := range files { -
-
-
-

{ file.Name }

-

{ file.Size }

-
-
- - - - - - - - -
-
-
- } - -
-
-
- } -} - -templ Main(title string, files []types.FileData){ - @component(title, files) -} \ No newline at end of file diff --git a/view/client/download/download_templ.go b/view/client/download/download_templ.go deleted file mode 100644 index 61e21ab..0000000 --- a/view/client/download/download_templ.go +++ /dev/null @@ -1,124 +0,0 @@ -// Code generated by templ - DO NOT EDIT. - -// templ: version: v0.2.663 -package downloadView - -//lint:file-ignore SA4006 This context is only used if a nested component is present. - -import "github.com/a-h/templ" -import "context" -import "io" -import "bytes" - -import ( - "github.com/fossyy/filekeeper/types" - "github.com/fossyy/filekeeper/view/client/layout" -) - -func component(title string, files []types.FileData) templ.Component { - return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) - if !templ_7745c5c3_IsBuffer { - templ_7745c5c3_Buffer = templ.GetBuffer() - defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var1 := templ.GetChildren(ctx) - if templ_7745c5c3_Var1 == nil { - templ_7745c5c3_Var1 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var2 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) - if !templ_7745c5c3_IsBuffer { - templ_7745c5c3_Buffer = templ.GetBuffer() - defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Download Files

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - for _, file := range files { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var3 string - templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(file.Name) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\download\download.templ`, Line: 22, Col: 86} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var4 string - templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(file.Size) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\download\download.templ`, Line: 23, Col: 75} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - if !templ_7745c5c3_IsBuffer { - _, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer) - } - return templ_7745c5c3_Err - }) - templ_7745c5c3_Err = layout.BaseAuth(title).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - if !templ_7745c5c3_IsBuffer { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) - } - return templ_7745c5c3_Err - }) -} - -func Main(title string, files []types.FileData) templ.Component { - return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) - if !templ_7745c5c3_IsBuffer { - templ_7745c5c3_Buffer = templ.GetBuffer() - defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var6 := templ.GetChildren(ctx) - if templ_7745c5c3_Var6 == nil { - templ_7745c5c3_Var6 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = component(title, files).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - if !templ_7745c5c3_IsBuffer { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) - } - return templ_7745c5c3_Err - }) -} diff --git a/view/client/file/file.templ b/view/client/file/file.templ new file mode 100644 index 0000000..05e9bcb --- /dev/null +++ b/view/client/file/file.templ @@ -0,0 +1,137 @@ +package fileView + +import ( + "github.com/fossyy/filekeeper/view/client/layout" + "github.com/fossyy/filekeeper/types" +) + +templ component(title string, files []types.FileData, user types.User) { + @layout.BaseAuth(title) { + @layout.Navbar(user) +
+
+ + + + + + Back + +
+
+ + +
+
+ + + + + + + + + + + for _, file := range files { + + + + + + + } + +
File NameFile SizeDownloadsAction
+ + + + + + {file.Name} + {file.Size} +
+ + + + + + {file.Downloaded} +
+
+ + Download + +
+
+
+
+
+
+ +
+ + } +} + +templ Main(title string, files []types.FileData, user types.User) { + @component(title, files, user) +} diff --git a/view/client/file/file_templ.go b/view/client/file/file_templ.go new file mode 100644 index 0000000..01bcfa6 --- /dev/null +++ b/view/client/file/file_templ.go @@ -0,0 +1,141 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package fileView + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import ( + "github.com/fossyy/filekeeper/types" + "github.com/fossyy/filekeeper/view/client/layout" +) + +func component(title string, files []types.FileData, user types.User) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var2 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + templ_7745c5c3_Err = layout.Navbar(user).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Back
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, file := range files { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
File NameFile SizeDownloadsAction
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var3 string + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(file.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\file\file.templ`, Line: 70, Col: 48} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var4 string + templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(file.Size) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\file\file.templ`, Line: 72, Col: 69} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var5 string + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(file.Downloaded) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\file\file.templ`, Line: 80, Col: 64} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Download\r
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer) + } + return templ_7745c5c3_Err + }) + templ_7745c5c3_Err = layout.BaseAuth(title).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func Main(title string, files []types.FileData, user types.User) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var7 := templ.GetChildren(ctx) + if templ_7745c5c3_Var7 == nil { + templ_7745c5c3_Var7 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = component(title, files, user).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} diff --git a/view/client/index/index.templ b/view/client/index/index.templ index 76dc8e9..f10c7ea 100644 --- a/view/client/index/index.templ +++ b/view/client/index/index.templ @@ -20,12 +20,12 @@ templ content(title string, user types.User) {
if user.Authenticated { + href="/user" hx-get="/user" hx-swap="innerHTML" hx-push-url="true" hx-target="#content"> Open Dashboard } else { + href="/signup" hx-get="/signup" hx-swap="innerHTML" hx-push-url="true" hx-target="#content"> Get started } diff --git a/view/client/index/index_templ.go b/view/client/index/index_templ.go index f969cfb..198b6e8 100644 --- a/view/client/index/index_templ.go +++ b/view/client/index/index_templ.go @@ -47,12 +47,12 @@ func content(title string, user types.User) templ.Component { return templ_7745c5c3_Err } if user.Authenticated { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Open Dashboard") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Open Dashboard") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Get started") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Get started") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/view/client/layout/base.templ b/view/client/layout/base.templ index db9e140..b8cab83 100644 --- a/view/client/layout/base.templ +++ b/view/client/layout/base.templ @@ -48,19 +48,32 @@ templ BaseAuth(title string){ { children... }
- + + @MainScript() @modalScript() + } @@ -80,6 +93,21 @@ templ modal() { } +templ MainScript() { + +} + templ modalScript(){ ") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Mengupload 1 item
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = MainScript().Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -123,7 +127,7 @@ func BaseAuth(title string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -158,7 +162,7 @@ func modal() templ.Component { }) } -func modalScript() templ.Component { +func MainScript() templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -171,6 +175,30 @@ func modalScript() templ.Component { templ_7745c5c3_Var6 = templ.NopComponent } ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func modalScript() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var7 := templ.GetChildren(ctx) + if templ_7745c5c3_Var7 == nil { + templ_7745c5c3_Var7 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -190,9 +218,9 @@ func Navbar(user types.User) templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var7 := templ.GetChildren(ctx) - if templ_7745c5c3_Var7 == nil { - templ_7745c5c3_Var7 = templ.NopComponent + templ_7745c5c3_Var8 := templ.GetChildren(ctx) + if templ_7745c5c3_Var8 == nil { + templ_7745c5c3_Var8 = templ.NopComponent } ctx = templ.ClearChildren(ctx) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
\"Filekeeper Filekeeper
") @@ -204,12 +232,12 @@ func Navbar(user types.User) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var8 string - templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(user.Username) + var templ_7745c5c3_Var9 string + templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(user.Username) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\layout\base.templ`, Line: 149, Col: 40} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\layout\base.templ`, Line: 177, Col: 40} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -217,12 +245,12 @@ func Navbar(user types.User) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var9 string - templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(user.Email) + var templ_7745c5c3_Var10 string + templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(user.Email) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\layout\base.templ`, Line: 150, Col: 67} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\layout\base.templ`, Line: 178, Col: 67} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -255,9 +283,9 @@ func Footer() templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var10 := templ.GetChildren(ctx) - if templ_7745c5c3_Var10 == nil { - templ_7745c5c3_Var10 = templ.NopComponent + templ_7745c5c3_Var11 := templ.GetChildren(ctx) + if templ_7745c5c3_Var11 == nil { + templ_7745c5c3_Var11 = templ.NopComponent } ctx = templ.ClearChildren(ctx) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") diff --git a/view/client/upload/upload.templ b/view/client/upload/upload.templ deleted file mode 100644 index 4492773..0000000 --- a/view/client/upload/upload.templ +++ /dev/null @@ -1,68 +0,0 @@ -package uploadView - -import "github.com/fossyy/filekeeper/view/client/layout" - -templ content(title string) { - @layout.BaseAuth(title){ -
-
-
-
-
- -
-
- -
-
-
-
-
-
- - } -} - -templ Main(title string) { - @content(title) -} \ No newline at end of file diff --git a/view/client/upload/upload_templ.go b/view/client/upload/upload_templ.go deleted file mode 100644 index c880629..0000000 --- a/view/client/upload/upload_templ.go +++ /dev/null @@ -1,76 +0,0 @@ -// Code generated by templ - DO NOT EDIT. - -// templ: version: v0.2.663 -package uploadView - -//lint:file-ignore SA4006 This context is only used if a nested component is present. - -import "github.com/a-h/templ" -import "context" -import "io" -import "bytes" - -import "github.com/fossyy/filekeeper/view/client/layout" - -func content(title string) templ.Component { - return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) - if !templ_7745c5c3_IsBuffer { - templ_7745c5c3_Buffer = templ.GetBuffer() - defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var1 := templ.GetChildren(ctx) - if templ_7745c5c3_Var1 == nil { - templ_7745c5c3_Var1 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var2 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) - if !templ_7745c5c3_IsBuffer { - templ_7745c5c3_Buffer = templ.GetBuffer() - defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - if !templ_7745c5c3_IsBuffer { - _, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer) - } - return templ_7745c5c3_Err - }) - templ_7745c5c3_Err = layout.BaseAuth(title).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - if !templ_7745c5c3_IsBuffer { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) - } - return templ_7745c5c3_Err - }) -} - -func Main(title string) templ.Component { - return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) - if !templ_7745c5c3_IsBuffer { - templ_7745c5c3_Buffer = templ.GetBuffer() - defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var3 := templ.GetChildren(ctx) - if templ_7745c5c3_Var3 == nil { - templ_7745c5c3_Var3 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = content(title).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - if !templ_7745c5c3_IsBuffer { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) - } - return templ_7745c5c3_Err - }) -} diff --git a/view/client/user/totp/setup.templ b/view/client/user/totp/setup.templ index 544c33d..67e2ebe 100644 --- a/view/client/user/totp/setup.templ +++ b/view/client/user/totp/setup.templ @@ -7,115 +7,120 @@ import ( templ content(title string, qrcode string, code string, user types.User, msg types.Message) { @layout.BaseAuth(title){ - @layout.Navbar(user) -
- - - - - - Back - -
-
-
-

Set up Two-Factor Authentication

-
-

Secure your account with time-based one-time passwords (TOTP).

-
-

Here's how to set up the Google Authenticator app:

-
    -
  1. Download the Google Authenticator app on your mobile device.
  2. -
  3. Open the app and tap "Begin Setup".
  4. -
  5. Select "Scan a barcode" and point your camera at the QR code below.
  6. -
  7. The app will automatically add your account and display a 6-digit code.
  8. -
  9. Enter this code on the website to complete the setup.
  10. -
-
-
-
-
- switch msg.Code { - case 0: - - case 1: - - } -
- QR Code -
-
-

Backup Code:

-
----|----
-

TOTP Secret:

-
- {code} -
-
-
-
- - - -
- -
-
-
-
-
-
-
- @layout.Footer() + @MainContent(qrcode, code, user, msg) } } +templ MainContent(qrcode string, code string, user types.User, msg types.Message) { + @layout.Navbar(user) +
+ + + + + + Back + +
+
+
+

Set up Two-Factor Authentication

+
+

Secure your account with time-based one-time passwords (TOTP).

+
+

Here's how to set up the Google Authenticator app:

+
    +
  1. Download the Google Authenticator app on your mobile device.
  2. +
  3. Open the app and tap "Begin Setup".
  4. +
  5. Select "Scan a barcode" and point your camera at the QR code below.
  6. +
  7. The app will automatically add your account and display a 6-digit code.
  8. +
  9. Enter this code on the website to complete the setup.
  10. +
+
+
+
+
+ switch msg.Code { + case 0: + + case 1: + + } +
+ QR Code +
+
+

Backup Code:

+
----|----
+

TOTP Secret:

+
+ {code} +
+
+
+
+ + + +
+ +
+
+
+
+
+
+
+ @layout.Footer() + @layout.MainScript() +} + templ Main(title string, qrcode string, code string, user types.User, msg types.Message) { @content(title, qrcode, code, user, msg) } \ No newline at end of file diff --git a/view/client/user/totp/setup_templ.go b/view/client/user/totp/setup_templ.go index 03cd22d..8a9a4ca 100644 --- a/view/client/user/totp/setup_templ.go +++ b/view/client/user/totp/setup_templ.go @@ -34,96 +34,7 @@ func content(title string, qrcode string, code string, user types.User, msg type templ_7745c5c3_Buffer = templ.GetBuffer() defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } - templ_7745c5c3_Err = layout.Navbar(user).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Back

Set up Two-Factor Authentication

Secure your account with time-based one-time passwords (TOTP).

Here's how to set up the Google Authenticator app:

  1. Download the Google Authenticator app on your mobile device.
  2. Open the app and tap \"Begin Setup\".
  3. Select \"Scan a barcode\" and point your camera at the QR code below.
  4. The app will automatically add your account and display a 6-digit code.
  5. Enter this code on the website to complete the setup.
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - switch msg.Code { - case 0: - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Info
Error! ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var3 string - templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(msg.Message) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\totp\setup.templ`, Line: 61, Col: 80} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - case 1: - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Info
Success! ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var4 string - templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(msg.Message) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\totp\setup.templ`, Line: 71, Col: 82} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
\"QR

Backup Code:

----|----

TOTP Secret:

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var6 string - templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(code) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\totp\setup.templ`, Line: 90, Col: 27} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = layout.Footer().Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = MainContent(qrcode, code, user, msg).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -143,6 +54,123 @@ func content(title string, qrcode string, code string, user types.User, msg type }) } +func MainContent(qrcode string, code string, user types.User, msg types.Message) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var3 := templ.GetChildren(ctx) + if templ_7745c5c3_Var3 == nil { + templ_7745c5c3_Var3 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = layout.Navbar(user).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Back

Set up Two-Factor Authentication

Secure your account with time-based one-time passwords (TOTP).

Here's how to set up the Google Authenticator app:

  1. Download the Google Authenticator app on your mobile device.
  2. Open the app and tap \"Begin Setup\".
  3. Select \"Scan a barcode\" and point your camera at the QR code below.
  4. The app will automatically add your account and display a 6-digit code.
  5. Enter this code on the website to complete the setup.
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + switch msg.Code { + case 0: + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Info
Error! ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var4 string + templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(msg.Message) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\totp\setup.templ`, Line: 66, Col: 76} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + case 1: + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Info
Success! ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var5 string + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(msg.Message) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\totp\setup.templ`, Line: 76, Col: 78} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
\"QR

Backup Code:

----|----

TOTP Secret:

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var7 string + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(code) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\totp\setup.templ`, Line: 95, Col: 23} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = layout.Footer().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = layout.MainScript().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + func Main(title string, qrcode string, code string, user types.User, msg types.Message) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) @@ -151,9 +179,9 @@ func Main(title string, qrcode string, code string, user types.User, msg types.M defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var8 := templ.GetChildren(ctx) - if templ_7745c5c3_Var8 == nil { - templ_7745c5c3_Var8 = templ.NopComponent + templ_7745c5c3_Var9 := templ.GetChildren(ctx) + if templ_7745c5c3_Var9 == nil { + templ_7745c5c3_Var9 = templ.NopComponent } ctx = templ.ClearChildren(ctx) templ_7745c5c3_Err = content(title, qrcode, code, user, msg).Render(ctx, templ_7745c5c3_Buffer) diff --git a/view/client/user/user.templ b/view/client/user/user.templ index a5af25d..7d038f8 100644 --- a/view/client/user/user.templ +++ b/view/client/user/user.templ @@ -8,302 +8,302 @@ import ( templ content(message types.Message, title string, user types.User, allowance *types.Allowance, ListSession []*session.SessionInfo) { @layout.BaseAuth(title){ - @layout.Navbar(user) -
-
-
-
-

Profile

+ @MainContent(user, allowance, ListSession, message) + } +} + +templ MainContent(user types.User, allowance *types.Allowance, ListSession []*session.SessionInfo, message types.Message) { + @layout.Navbar(user) +
+
+
+
+

Profile

+
+
+ + +
+
+ + +
+
+ +
+
+ JL +
+ +
+
+
+
+
+

Session Management

+
+
+
+ + +
+
+
+
+
+ + + + + + + + + + + for _, ses := range ListSession { + + + + + + + } + +
+ IP Address + + Browser + + Device + + Actions +
{ses.IP} + {ses.Browser + ses.Version} + {ses.OS + ses.OSVersion} + + +
+
+
+
+
+
+
+

Reset Password

+ switch message.Code { + case 0: + + } +
+ type="password" id="currentPassword" name="currentPassword" placeholder="Current password" />
+ type="password" id="password" name="password" placeholder="New password" />
-
-
- JL -
- -
+
+ +
-
-
-

Session Management

-
-
-
- - -
-
-
-
-
- - - - - - - - - - - for _, ses := range ListSession { - - - - - - - } - -
- IP Address - - Browser - - Device - - Actions -
{ses.IP} - {ses.Browser + ses.Version} - {ses.OS + ses.OSVersion} - - -
-
-
-
+ +
+
+ +

+ Click to log out or terminate the current session. +

+
+
+ +
+
+
+

Storage Usage

+ + + + + + +
+
+
{allowance.AllowanceUsedByte} / {allowance.AllowanceByte}
+
+
-
-
-

Reset Password

- switch message.Code { - case 0: - - } -
-
-
- - -
-
- - -
-
- - -
- - -
-
-
-
- -

- Click to log out or terminate the current session. -

+ + Manage +
- -
-
-
-

Storage Usage

- - - - - - -
-
-
{allowance.AllowanceUsedByte} / {allowance.AllowanceByte}
-
-
-
- - Upload - - - Download - -
+
+
+

Upgrade Storage +

-
-
-

Upgrade Storage -

+
+
+

Pro Plan

+

50GB of storage for $9.99/month

+ + Upgrade +
-
-
-

Pro Plan

-

50GB of storage for $9.99/month

- - Upgrade - -
-
-

Enterprise Plan

-

1TB of storage for $49.99/month

- - Upgrade - -
+
+

Enterprise Plan

+

1TB of storage for $49.99/month

+ + Upgrade +
-
- @templ.JSONScript("AllowanceUsedPercent", allowance.AllowanceUsedPercent) - - + @layout.MainScript() + ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = layout.Footer().Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = MainContent(user, allowance, ListSession, message).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -209,6 +55,192 @@ func content(message types.Message, title string, user types.User, allowance *ty }) } +func MainContent(user types.User, allowance *types.Allowance, ListSession []*session.SessionInfo, message types.Message) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var3 := templ.GetChildren(ctx) + if templ_7745c5c3_Var3 == nil { + templ_7745c5c3_Var3 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = layout.Navbar(user).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Profile

JL

Session Management

Setup\r
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, ses := range ListSession { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
IP Address\rBrowser\rDevice\rActions\r
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var6 string + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(ses.IP) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\user.templ`, Line: 117, Col: 118} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var7 string + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(ses.Browser + ses.Version) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\user.templ`, Line: 119, Col: 137} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var8 string + templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(ses.OS + ses.OSVersion) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\user.templ`, Line: 121, Col: 134} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Reset Password

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + switch message.Code { + case 0: + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var10 string + templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(message.Message) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\user.templ`, Line: 146, Col: 48} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
  • New Passwords do not match
  • New Password must contain at least one uppercase letter
  • New Password length must be at least 8 characters

Click to log out or terminate the current session.\r

Storage Usage

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var11 string + templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(allowance.AllowanceUsedByte) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\user.templ`, Line: 249, Col: 84} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" / ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var12 string + templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(allowance.AllowanceByte) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\user.templ`, Line: 249, Col: 112} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Manage\r

Upgrade Storage\r

Pro Plan

50GB of storage for $9.99/month

Upgrade\r

Enterprise Plan

1TB of storage for $49.99/month

Upgrade\r
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = layout.Footer().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.JSONScript("AllowanceUsedPercent", allowance.AllowanceUsedPercent).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = layout.MainScript().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + func SessionTable(ListSession []*session.SessionInfo) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) @@ -217,9 +249,9 @@ func SessionTable(ListSession []*session.SessionInfo) templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var12 := templ.GetChildren(ctx) - if templ_7745c5c3_Var12 == nil { - templ_7745c5c3_Var12 = templ.NopComponent + templ_7745c5c3_Var13 := templ.GetChildren(ctx) + if templ_7745c5c3_Var13 == nil { + templ_7745c5c3_Var13 = templ.NopComponent } ctx = templ.ClearChildren(ctx) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") @@ -231,24 +263,11 @@ func SessionTable(ListSession []*session.SessionInfo) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var13 string - templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(ses.IP) + var templ_7745c5c3_Var14 string + templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(ses.IP) if templ_7745c5c3_Err != nil { return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\user.templ`, Line: 314, Col: 82} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var14 string - templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(ses.Browser + ses.Version) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\user.templ`, Line: 316, Col: 101} - } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -258,11 +277,24 @@ func SessionTable(ListSession []*session.SessionInfo) templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var15 string - templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(ses.OS + ses.OSVersion) + templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(ses.Browser + ses.Version) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\user.templ`, Line: 316, Col: 101} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var16 string + templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(ses.OS + ses.OSVersion) if templ_7745c5c3_Err != nil { return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\user.templ`, Line: 318, Col: 98} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -270,16 +302,16 @@ func SessionTable(ListSession []*session.SessionInfo) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var16 string - templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs("/user/session/terminate/" + ses.SessionID) + var templ_7745c5c3_Var17 string + templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs("/user/session/terminate/" + ses.SessionID) if templ_7745c5c3_Err != nil { return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\client\user\user.templ`, Line: 325, Col: 71} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-target=\"#session-tables\" hx-swap=\"outerHTML\">Terminate\r") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-target=\"#session-tables\" hx-swap=\"innerHTML\">Terminate\r") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -303,9 +335,9 @@ func Main(title string, user types.User, allowance *types.Allowance, ListSession defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var17 := templ.GetChildren(ctx) - if templ_7745c5c3_Var17 == nil { - templ_7745c5c3_Var17 = templ.NopComponent + templ_7745c5c3_Var18 := templ.GetChildren(ctx) + if templ_7745c5c3_Var18 == nil { + templ_7745c5c3_Var18 = templ.NopComponent } ctx = templ.ClearChildren(ctx) templ_7745c5c3_Err = content(message, title, user, allowance, ListSession).Render(ctx, templ_7745c5c3_Buffer)