From af08d9befc5379d1fb44b696158c2d91b2450ed7 Mon Sep 17 00:00:00 2001 From: kenneth <1185230223@qq.com> Date: Wed, 11 Dec 2024 17:37:58 +0800 Subject: [PATCH] update assets use --- assets/css/home.css | 17 +++++++ assets/js/home.js | 22 ++++++++ go.mod | 2 +- internal/handler/account.go | 16 +++--- internal/templ/auth/login.templ | 10 ++-- internal/templ/auth/login_templ.go | 10 ++-- internal/templ/auth/register.templ | 10 ++-- internal/templ/auth/register_templ.go | 10 ++-- internal/templ/base/base.templ | 22 ++++---- internal/templ/base/base_templ.go | 56 ++++++++++++++------- internal/templ/css/home.templ | 23 --------- internal/templ/css/home_templ.go | 40 --------------- internal/templ/err/404.templ | 2 +- internal/templ/err/404_templ.go | 2 +- internal/templ/home/home.templ | 8 +-- internal/templ/home/home_templ.go | 8 +-- internal/templ/js/home.templ | 28 ----------- internal/templ/js/home_templ.go | 40 --------------- internal/templ/{model => models}/auth.go | 2 +- internal/templ/templ.go | 18 ++++--- internal/templ/url/url.templ | 8 +-- internal/templ/url/url_templ.go | 8 +-- internal/templ/{funcs => util}/authorize.go | 2 +- internal/templ/{funcs => util}/csrf.go | 2 +- internal/templ/util/file.go | 29 +++++++++++ 25 files changed, 177 insertions(+), 218 deletions(-) create mode 100644 assets/css/home.css create mode 100644 assets/js/home.js delete mode 100644 internal/templ/css/home.templ delete mode 100644 internal/templ/css/home_templ.go delete mode 100644 internal/templ/js/home.templ delete mode 100644 internal/templ/js/home_templ.go rename internal/templ/{model => models}/auth.go (95%) rename internal/templ/{funcs => util}/authorize.go (92%) rename internal/templ/{funcs => util}/csrf.go (91%) create mode 100644 internal/templ/util/file.go diff --git a/assets/css/home.css b/assets/css/home.css new file mode 100644 index 0000000..dd0a918 --- /dev/null +++ b/assets/css/home.css @@ -0,0 +1,17 @@ +.my_table { + display: block; + max-width: 1280px; +} + +.my_table tr { + display: inline-block; + width: 100%; + border: 1px solid #eee; + border-collapse: collapse; +} + +.my_table tr td { + display: inline-block; + word-wrap: break-word; + padding: 2px 5px; +} \ No newline at end of file diff --git a/assets/js/home.js b/assets/js/home.js new file mode 100644 index 0000000..f11c0cc --- /dev/null +++ b/assets/js/home.js @@ -0,0 +1,22 @@ +$('.deleteShortUrl').click(function () { + let csrfToken = $('input[name="csrf_token"]').val() + let u = $(this).attr('data-short-url') + $.ajax({ + url: '/delete-short-url/' + u, + type: 'POST', + cache: false, + processData: false, + contentType: false, + headers: { + "X-CSRF-Token": csrfToken + }, + success: function (res) { + if (res.success) { + alert('删除成功'); + window.location.reload(); + } else { + alert('删除失败'); + } + } + }) +}); \ No newline at end of file diff --git a/go.mod b/go.mod index cff3f6e..6fcef4e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/zhang2092/go-url-shortener -go 1.23.3 +go 1.23.4 require ( github.com/a-h/templ v0.2.793 diff --git a/internal/handler/account.go b/internal/handler/account.go index 1198cd4..15c028e 100644 --- a/internal/handler/account.go +++ b/internal/handler/account.go @@ -11,11 +11,11 @@ import ( "github.com/zhang2092/go-url-shortener/internal/pkg/cookie" pwd "github.com/zhang2092/go-url-shortener/internal/pkg/password" "github.com/zhang2092/go-url-shortener/internal/templ" - "github.com/zhang2092/go-url-shortener/internal/templ/model" + "github.com/zhang2092/go-url-shortener/internal/templ/models" ) func RegisterView(w http.ResponseWriter, r *http.Request) { - templ.Register(w, r, &model.RegisterPageData{}) + templ.Register(w, r, &models.RegisterPageData{}) } func Register(store db.Store) http.HandlerFunc { @@ -67,7 +67,7 @@ func Register(store db.Store) http.HandlerFunc { } func LoginView(w http.ResponseWriter, r *http.Request) { - templ.Login(w, r, &model.LoginPageData{}) + templ.Login(w, r, &models.LoginPageData{}) } func Login(store db.Store) http.HandlerFunc { @@ -75,7 +75,7 @@ func Login(store db.Store) http.HandlerFunc { defer r.Body.Close() if err := r.ParseForm(); err != nil { - templ.Login(w, r, &model.LoginPageData{Summary: "请求网络错误,请刷新重试"}) + templ.Login(w, r, &models.LoginPageData{Summary: "请求网络错误,请刷新重试"}) return } @@ -128,9 +128,9 @@ func Logout() http.HandlerFunc { } } -func viladatorRegister(email, username, password string) (*model.RegisterPageData, bool) { +func viladatorRegister(email, username, password string) (*models.RegisterPageData, bool) { ok := true - resp := &model.RegisterPageData{ + resp := &models.RegisterPageData{ Email: email, Username: username, Password: password, @@ -152,9 +152,9 @@ func viladatorRegister(email, username, password string) (*model.RegisterPageDat return resp, ok } -func viladatorLogin(email, password string) (*model.LoginPageData, bool) { +func viladatorLogin(email, password string) (*models.LoginPageData, bool) { ok := true - errs := &model.LoginPageData{ + errs := &models.LoginPageData{ Email: email, Password: password, } diff --git a/internal/templ/auth/login.templ b/internal/templ/auth/login.templ index b8c0bcc..65af545 100644 --- a/internal/templ/auth/login.templ +++ b/internal/templ/auth/login.templ @@ -2,19 +2,19 @@ package auth import ( "github.com/zhang2092/go-url-shortener/internal/templ/base" - "github.com/zhang2092/go-url-shortener/internal/templ/funcs" - "github.com/zhang2092/go-url-shortener/internal/templ/model" + "github.com/zhang2092/go-url-shortener/internal/templ/models" + "github.com/zhang2092/go-url-shortener/internal/templ/util" "net/http" ) -templ Login(r *http.Request, page string, form *model.LoginPageData) { - @base.Base(page) { +templ Login(r *http.Request, form *models.LoginPageData) { + @base.Base() {