From e79441dbc517c6985fd65b59c2c9ac0c267ed981 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 20 Apr 2024 22:50:09 +0800 Subject: [PATCH] :sparkles: Sign up & Sign in --- .idea/Passport.iml | 1 + .idea/dataSources.local.xml | 7 +- .../74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml | 675 +++++++----------- .../schema/public.abK9xQ.meta | 2 +- .idea/jsLibraryMappings.xml | 6 + .idea/workspace.xml | 30 +- go.mod | 5 +- go.sum | 18 + pkg/i18n/locale.en.json | 7 +- pkg/i18n/locale.zh.json | 7 +- pkg/server/accounts_api.go | 7 +- pkg/server/auth_api.go | 7 +- pkg/server/friendships_api.go | 3 +- pkg/server/notifications_api.go | 3 +- pkg/server/notify_api.go | 3 +- pkg/server/page_api.go | 3 +- pkg/server/ui/auth.go | 26 - pkg/server/ui/index.go | 5 + pkg/server/ui/signin.go | 77 ++ pkg/server/ui/signup.go | 86 +++ pkg/services/ticket.go | 19 +- pkg/{server/utils.go => utils/request.go} | 2 +- pkg/views/layouts/auth.gohtml | 46 +- pkg/views/partials/header.gohtml | 46 +- pkg/views/signin.gohtml | 3 +- pkg/views/signup.gohtml | 75 ++ 26 files changed, 706 insertions(+), 463 deletions(-) create mode 100644 .idea/jsLibraryMappings.xml delete mode 100644 pkg/server/ui/auth.go create mode 100644 pkg/server/ui/signin.go create mode 100644 pkg/server/ui/signup.go rename pkg/{server/utils.go => utils/request.go} (96%) create mode 100644 pkg/views/signup.gohtml diff --git a/.idea/Passport.iml b/.idea/Passport.iml index 5e764c4..0da4db5 100644 --- a/.idea/Passport.iml +++ b/.idea/Passport.iml @@ -5,5 +5,6 @@ + \ No newline at end of file diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml index 04919cb..36b95b8 100644 --- a/.idea/dataSources.local.xml +++ b/.idea/dataSources.local.xml @@ -10,8 +10,11 @@ postgres - - + + + + + diff --git a/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml b/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml index 1daf5ad..d818613 100644 --- a/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml +++ b/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml @@ -3,15 +3,7 @@ mdy - 1||-9223372036854775808|c|G -1||10|c|G -1||10|C|G -1||10|T|G -4||-9223372036854775808|c|G -4||10|c|G -4||10|C|G -4||10|T|G - 6258 + 6267 16.2 1713083875 true ACDT @@ -808,7 +800,7 @@ false Zulu 13474||10|C|G 13474||-9223372036854775808|U|G 13474||10|U|G - 6258 + 6267 37312 postgres @@ -4249,8 +4241,8 @@ false Zulu standard public schema 1 - 6258 - 2024-04-20.06:09:48 + 6267 + 2024-04-20.11:07:46 2200 523 pg_database_owner @@ -4303,15 +4295,7 @@ false Zulu 6247 littlesheep - - bigint|0s - 37439 - 1 - 1 - 6243 - littlesheep - - + bigint|0s 37324 1 @@ -4319,15 +4303,15 @@ false Zulu 6227 littlesheep - + bigint|0s - 37419 + 37526 1 1 - 6241 + 6259 littlesheep - + bigint|0s 37459 1 @@ -4335,7 +4319,7 @@ false Zulu 6245 littlesheep - + bigint|0s 37509 1 @@ -4343,7 +4327,7 @@ false Zulu 6251 littlesheep - + bigint|0s 37489 1 @@ -4351,7 +4335,7 @@ false Zulu 6249 littlesheep - + bigint|0s 37403 1 @@ -4359,85 +4343,79 @@ false Zulu 6238 littlesheep - +
3737062332littlesheep
- +
3738662362littlesheep
- +
3735562312littlesheep
- +
3734062292littlesheep
- +
3731462272littlesheep
- +
3747562472littlesheep
- - 37440 - 6243 - 2 - littlesheep -
- +
3732562272littlesheep
- - 37420 - 6241 +
+ 37527 + 62592littlesheep
- +
3746062452littlesheep
- +
3751062512littlesheep
- +
3749062492littlesheep
- +
3740462382littlesheep
- + bigint|0s nextval('passport_account_contacts_id_seq'::regclass) 1 @@ -4446,68 +4424,68 @@ false Zulu 37369 20 - + timestamp with time zone|0s 2 6233 1184 - + timestamp with time zone|0s 3 6233 1184 - + timestamp with time zone|0s 4 6233 1184 - + smallint|0s 5 6233 21 - + text|0s 6 6233 25 - + boolean|0s 7 6233 16 - + boolean|0s 8 6233 16 - + timestamp with time zone|0s 9 6233 1184 - + bigint|0s 10 6233 20 - + account_id 37378 6233 1 37314 - + id 1 37376 @@ -4516,7 +4494,7 @@ false Zulu 1 403 - + content 37383 6234 @@ -4526,20 +4504,20 @@ false Zulu 100 pg_catalog - + deleted_at 37384 6235 403 - + 1 37377 1 6233 37376 - + bigint|0s nextval('passport_account_friendships_id_seq'::regclass) 1 @@ -4548,63 +4526,63 @@ false Zulu 37385 20 - + timestamp with time zone|0s 2 6236 1184 - + timestamp with time zone|0s 3 6236 1184 - + timestamp with time zone|0s 4 6236 1184 - + bigint|0s 5 6236 20 - + bigint|0s 6 6236 20 - + bigint|0s 7 6236 20 - + smallint|0s 8 6236 21 - + account_id 37392 6236 1 37314 - + related_id 37397 6236 1 37314 - + id 1 37390 @@ -4613,20 +4591,20 @@ false Zulu 1 403 - + deleted_at 37402 6237 403 - + 1 37391 1 6236 37390 - + bigint|0s nextval('passport_account_pages_id_seq'::regclass) 1 @@ -4635,62 +4613,62 @@ false Zulu 37354 20 - + timestamp with time zone|0s 2 6231 1184 - + timestamp with time zone|0s 3 6231 1184 - + timestamp with time zone|0s 4 6231 1184 - + text|0s 5 6231 25 - + text|0s 6 6231 25 - + text|0s 7 6231 25 - + jsonb|0s 8 6231 3802 - + bigint|0s 9 6231 20 - + account_id 37363 6231 1 37314 - + id 1 37361 @@ -4699,20 +4677,20 @@ false Zulu 1 403 - + deleted_at 37368 6232 403 - + 1 37362 1 6231 37361 - + bigint|0s nextval('passport_account_profiles_id_seq'::regclass) 1 @@ -4721,62 +4699,62 @@ false Zulu 37339 20 - + timestamp with time zone|0s 2 6229 1184 - + timestamp with time zone|0s 3 6229 1184 - + timestamp with time zone|0s 4 6229 1184 - + text|0s 5 6229 25 - + text|0s 6 6229 25 - + bigint|0s 7 6229 20 - + timestamp with time zone|0s 8 6229 1184 - + bigint|0s 9 6229 20 - + account_id 37348 6229 1 37314 - + id 1 37346 @@ -4785,20 +4763,20 @@ false Zulu 1 403 - + deleted_at 37353 6230 403 - + 1 37347 1 6229 37346 - + bigint|0s nextval('passport_accounts_id_seq'::regclass) 1 @@ -4807,67 +4785,67 @@ false Zulu 37313 20 - + timestamp with time zone|0s 2 6224 1184 - + timestamp with time zone|0s 3 6224 1184 - + timestamp with time zone|0s 4 6224 1184 - + text|0s 5 6224 25 - + text|0s 6 6224 25 - + text|0s 7 6224 25 - + text|0s 8 6224 25 - + text|0s 9 6224 25 - + timestamp with time zone|0s 10 6224 1184 - + bigint|0s 11 6224 20 - + id 1 37320 @@ -4876,7 +4854,7 @@ false Zulu 1 403 - + name 37322 6225 @@ -4886,20 +4864,20 @@ false Zulu 100 pg_catalog - + deleted_at 37323 6226 403 - + 1 37321 1 6224 37320 - + bigint|0s nextval('passport_action_events_id_seq'::regclass) 1 @@ -4908,68 +4886,68 @@ false Zulu 37474 20 - + timestamp with time zone|0s 2 6247 1184 - + timestamp with time zone|0s 3 6247 1184 - + timestamp with time zone|0s 4 6247 1184 - + text|0s 5 6247 25 - + text|0s 6 6247 25 - + text|0s 7 6247 25 - + text|0s 8 6247 25 - + text|0s 9 6247 25 - + bigint|0s 10 6247 20 - + account_id 37483 6247 1 37314 - + id 1 37481 @@ -4978,149 +4956,20 @@ false Zulu 1 403 - + deleted_at 37488 6248 403 - + 1 37482 1 6247 37481 - - bigint|0s - nextval('passport_auth_challenges_id_seq'::regclass) - 1 - 1 - 6243 - 37439 - 20 - - - timestamp with time zone|0s - 2 - 6243 - 1184 - - - timestamp with time zone|0s - 3 - 6243 - 1184 - - - timestamp with time zone|0s - 4 - 6243 - 1184 - - - text|0s - 5 - 6243 - 25 - - - text|0s - 6 - 6243 - 25 - - - text|0s - 7 - 6243 - 25 - - - bigint|0s - 8 - 6243 - 20 - - - bigint|0s - 9 - 6243 - 20 - - - bigint|0s - 10 - 6243 - 20 - - - jsonb|0s - 11 - 6243 - 3802 - - - smallint|0s - 12 - 6243 - 21 - - - timestamp with time zone|0s - 13 - 6243 - 1184 - - - bigint|0s - 14 - 6243 - 20 - - - bigint|0s - 15 - 6243 - 20 - - - session_id - 37448 - 6243 - 1 - 37420 - - - account_id - 37453 - 6243 - 1 - 37314 - - - id - 1 - 37446 - 1 - 6243 - 1 - 403 - - - deleted_at - 37458 - 6244 - 403 - - - 1 - 37447 - 1 - 6243 - 37446 - - + bigint|0s nextval('passport_auth_factors_id_seq'::regclass) 1 @@ -5129,56 +4978,56 @@ false Zulu 37324 20 - + timestamp with time zone|0s 2 6227 1184 - + timestamp with time zone|0s 3 6227 1184 - + timestamp with time zone|0s 4 6227 1184 - + smallint|0s 5 6227 21 - + text|0s 6 6227 25 - + jsonb|0s 7 6227 3802 - + bigint|0s 8 6227 20 - + account_id 37333 6227 1 37314 - + id 1 37331 @@ -5187,143 +5036,173 @@ false Zulu 1 403 - + deleted_at 37338 6228 403 - + 1 37332 1 6227 37331 - + bigint|0s - nextval('passport_auth_sessions_id_seq'::regclass) + nextval('passport_auth_tickets_id_seq'::regclass) 1 1 - 6241 - 37419 + 6259 + 37526 20 - + timestamp with time zone|0s 2 - 6241 + 6259 1184 - + timestamp with time zone|0s 3 - 6241 + 6259 1184 - + timestamp with time zone|0s 4 - 6241 + 6259 1184 - - jsonb|0s + + text|0s 5 - 6241 - 3802 + 6259 + 25 - - jsonb|0s + + text|0s 6 - 6241 - 3802 + 6259 + 25 - + text|0s 7 - 6241 + 6259 25 - - text|0s + + boolean|0s 8 - 6241 - 25 + 6259 + 16 - - text|0s + + boolean|0s 9 - 6241 + 6259 + 16 + + + jsonb|0s + 10 + 6259 + 3802 + + + jsonb|0s + 11 + 6259 + 3802 + + + text|0s + 12 + 6259 25 - - timestamp with time zone|0s - 10 - 6241 - 1184 - - - timestamp with time zone|0s - 11 - 6241 - 1184 - - - timestamp with time zone|0s - 12 - 6241 - 1184 - - - bigint|0s + + text|0s 13 - 6241 - 20 + 6259 + 25 - - bigint|0s + + text|0s 14 - 6241 + 6259 + 25 + + + timestamp with time zone|0s + 15 + 6259 + 1184 + + + timestamp with time zone|0s + 16 + 6259 + 1184 + + + timestamp with time zone|0s + 17 + 6259 + 1184 + + + bigint|0s + 18 + 6259 20 - + + bigint|0s + 19 + 6259 + 20 + + client_id - 37428 - 6241 + 37540 + 6259 1 37404 - + account_id - 37433 - 6241 + 37535 + 6259 1 37314 - + id 1 - 37426 + 37533 1 - 6241 + 6259 1 403 - + deleted_at - 37438 - 6242 + 37545 + 6260 403 - + 1 - 37427 + 37534 1 - 6241 - 37426 + 6259 + 37533 - + bigint|0s nextval('passport_magic_tokens_id_seq'::regclass) 1 @@ -5332,56 +5211,56 @@ false Zulu 37459 20 - + timestamp with time zone|0s 2 6245 1184 - + timestamp with time zone|0s 3 6245 1184 - + timestamp with time zone|0s 4 6245 1184 - + text|0s 5 6245 25 - + smallint|0s 6 6245 21 - + bigint|0s 7 6245 20 - + timestamp with time zone|0s 8 6245 1184 - + assign_to 37468 6245 1 37314 - + id 1 37466 @@ -5390,20 +5269,20 @@ false Zulu 1 403 - + deleted_at 37473 6246 403 - + 1 37467 1 6245 37466 - + bigint|0s nextval('passport_notification_subscribers_id_seq'::regclass) 1 @@ -5412,56 +5291,56 @@ false Zulu 37509 20 - + timestamp with time zone|0s 2 6251 1184 - + timestamp with time zone|0s 3 6251 1184 - + timestamp with time zone|0s 4 6251 1184 - + text|0s 5 6251 25 - + text|0s 6 6251 25 - + text|0s 7 6251 25 - + bigint|0s 8 6251 20 - + account_id 37518 6251 1 37314 - + id 1 37516 @@ -5470,7 +5349,7 @@ false Zulu 1 403 - + device_id 37523 6252 @@ -5480,20 +5359,20 @@ false Zulu 100 pg_catalog - + deleted_at 37524 6253 403 - + 1 37517 1 6251 37516 - + bigint|0s nextval('passport_notifications_id_seq'::regclass) 1 @@ -5502,81 +5381,81 @@ false Zulu 37489 20 - + timestamp with time zone|0s 2 6249 1184 - + timestamp with time zone|0s 3 6249 1184 - + timestamp with time zone|0s 4 6249 1184 - + text|0s 5 6249 25 - + text|0s 6 6249 25 - + jsonb|0s 7 6249 3802 - + boolean|0s 8 6249 16 - + timestamp with time zone|0s 9 6249 1184 - + bigint|0s 10 6249 20 - + bigint|0s 11 6249 20 - + sender_id 37498 6249 1 37404 - + recipient_id 37503 6249 1 37314 - + id 1 37496 @@ -5585,20 +5464,20 @@ false Zulu 1 403 - + deleted_at 37508 6250 403 - + 1 37497 1 6249 37496 - + bigint|0s nextval('passport_third_clients_id_seq'::regclass) 1 @@ -5607,80 +5486,80 @@ false Zulu 37403 20 - + timestamp with time zone|0s 2 6238 1184 - + timestamp with time zone|0s 3 6238 1184 - + timestamp with time zone|0s 4 6238 1184 - + text|0s 5 6238 25 - + text|0s 6 6238 25 - + text|0s 7 6238 25 - + text|0s 8 6238 25 - + jsonb|0s 9 6238 3802 - + jsonb|0s 10 6238 3802 - + boolean|0s 11 6238 16 - + bigint|0s 12 6238 20 - + account_id 37412 6238 1 37314 - + id 1 37410 @@ -5689,7 +5568,7 @@ false Zulu 1 403 - + alias 37417 6239 @@ -5699,13 +5578,13 @@ false Zulu 100 pg_catalog - + deleted_at 37418 6240 403 - + 1 37411 1 diff --git a/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25/storage_v2/_src_/database/hy_passport.gNOKQQ/schema/public.abK9xQ.meta b/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25/storage_v2/_src_/database/hy_passport.gNOKQQ/schema/public.abK9xQ.meta index a9e0cff..4033bf5 100644 --- a/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25/storage_v2/_src_/database/hy_passport.gNOKQQ/schema/public.abK9xQ.meta +++ b/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25/storage_v2/_src_/database/hy_passport.gNOKQQ/schema/public.abK9xQ.meta @@ -1,2 +1,2 @@ #n:public -! [6258, 0, null, null, -2147483648, -2147483648] +! [6267, 0, null, null, -2147483648, -2147483648] diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..42f1d58 --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4695490..92b3f90 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,11 +5,31 @@ + + + + + + + - - - + + + + + + + + + + + + + + + + + + diff --git a/go.mod b/go.mod index f28bbb3..596a190 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,7 @@ require ( github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect - github.com/klauspost/compress v1.17.7 // indirect + github.com/klauspost/compress v1.17.8 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect @@ -76,6 +76,7 @@ require ( github.com/spf13/cast v1.6.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.6.0 // indirect + github.com/sujit-baniya/flash v0.1.8 // indirect github.com/tinylib/msgp v1.1.8 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.52.0 // indirect @@ -86,7 +87,7 @@ require ( golang.org/x/net v0.22.0 // indirect golang.org/x/oauth2 v0.15.0 // indirect golang.org/x/sync v0.5.0 // indirect - golang.org/x/sys v0.18.0 // indirect + golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect diff --git a/go.sum b/go.sum index c5a57a0..97a47d6 100644 --- a/go.sum +++ b/go.sum @@ -16,6 +16,7 @@ cloud.google.com/go/storage v1.35.1/go.mod h1:M6M/3V/D3KpzMTJyPOR/HU6n2Si5QdaXYE firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4= firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -52,6 +53,7 @@ github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9 github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofiber/contrib/websocket v1.3.0 h1:XADFAGorer1VJ1bqC4UkCjqS37kwRTV0415+050NrMk= github.com/gofiber/contrib/websocket v1.3.0/go.mod h1:xguaOzn2ZZ759LavtosEP+rcxIgBEE/rdumPINhR+Xo= +github.com/gofiber/fiber/v2 v2.36.0/go.mod h1:tgCr+lierLwLoVHHO/jn3Niannv34WRkQETU8wiL9fQ= github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM= github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= github.com/gofiber/template v1.8.3 h1:hzHdvMwMo/T2kouz2pPCA0zGiLCeMnoGsQZBTSYgZxc= @@ -123,8 +125,12 @@ github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= +github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -204,10 +210,13 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/sujit-baniya/flash v0.1.8 h1:BwcrybCatPU30VMA9IBA5q3ZE0VSr5c7qTqwZrSvyRI= +github.com/sujit-baniya/flash v0.1.8/go.mod h1:kmlAIkLDMlLshEeeE6fETEW8kSOopKN5WA3KXLmS/U0= github.com/tinylib/msgp v1.1.8 h1:FCXC1xanKO4I8plpHGH2P7koL/RzZs12l/+r7vakfm0= github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.38.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= github.com/valyala/fasthttp v1.52.0 h1:wqBQpxH71XW0e2g+Og4dzQM8pk34aFYlA1Ga8db7gU0= github.com/valyala/fasthttp v1.52.0/go.mod h1:hf5C4QnVMkNXMspnsUlfM3WitlgYflyhHYoKol/szxQ= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= @@ -222,6 +231,7 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -241,6 +251,8 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= @@ -260,7 +272,10 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -269,12 +284,15 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= diff --git a/pkg/i18n/locale.en.json b/pkg/i18n/locale.en.json index ca38155..50bea93 100644 --- a/pkg/i18n/locale.en.json +++ b/pkg/i18n/locale.en.json @@ -1,7 +1,12 @@ { "next": "Next", + "email": "Email", "username": "Username", + "nickname": "Nickname", "password": "Password", + "magicToken": "Magic Token", "signinTitle": "Sign In", - "signinCaption": "Sign in to Solarpass to explore entire Solar Network. Explore posts, discover communities, talk with your best friends. All these things in the Solar Network!" + "signinCaption": "Sign in to Solarpass to explore entire Solar Network. Explore posts, discover communities, talk with your best friends. All these things in the Solar Network!", + "signupTitle": "Sign Up", + "signupCaption": "Sign up to create an account on Solarpass, then you can explore the entire Solar Network! Enjoy the next-generation Internet Ecosystem!" } \ No newline at end of file diff --git a/pkg/i18n/locale.zh.json b/pkg/i18n/locale.zh.json index b63a2b9..72af9a2 100644 --- a/pkg/i18n/locale.zh.json +++ b/pkg/i18n/locale.zh.json @@ -1,7 +1,12 @@ { "next": "下一步", + "email": "邮件地址", "username": "用户名", + "nickname": "昵称", "password": "密码", + "magicToken": "魔法令牌", "signinTitle": "登陆", - "signinCaption": "登陆 Solarpass 以探索整个 Solar Network,浏览帖子、探索社区、和你的好朋友聊八卦,一切尽在 Solar Network!" + "signinCaption": "登陆 Solarpass 以探索整个 Solar Network,浏览帖子、探索社区、和你的好朋友聊八卦,一切尽在 Solar Network!", + "signupTitle": "注册", + "signupCaption": "注册以在 Solarpass 创建一个账号,之后你就可以探索整个 Solar Network,享受下一代互联网生态系统!" } diff --git a/pkg/server/accounts_api.go b/pkg/server/accounts_api.go index 47683cf..205fd7a 100644 --- a/pkg/server/accounts_api.go +++ b/pkg/server/accounts_api.go @@ -2,6 +2,7 @@ package server import ( "fmt" + "git.solsynth.dev/hydrogen/passport/pkg/utils" "strconv" "time" @@ -83,7 +84,7 @@ func editUserinfo(c *fiber.Ctx) error { Birthday time.Time `json:"birthday"` } - if err := BindAndValidate(c, &data); err != nil { + if err := utils.BindAndValidate(c, &data); err != nil { return err } @@ -133,7 +134,7 @@ func doRegister(c *fiber.Ctx) error { MagicToken string `json:"magic_token"` } - if err := BindAndValidate(c, &data); err != nil { + if err := utils.BindAndValidate(c, &data); err != nil { return err } else if viper.GetBool("use_registration_magic_token") && len(data.MagicToken) <= 0 { return fmt.Errorf("missing magic token in request") @@ -162,7 +163,7 @@ func doRegisterConfirm(c *fiber.Ctx) error { Code string `json:"code" validate:"required"` } - if err := BindAndValidate(c, &data); err != nil { + if err := utils.BindAndValidate(c, &data); err != nil { return err } diff --git a/pkg/server/auth_api.go b/pkg/server/auth_api.go index 596242f..0a38d88 100644 --- a/pkg/server/auth_api.go +++ b/pkg/server/auth_api.go @@ -2,6 +2,7 @@ package server import ( "fmt" + "git.solsynth.dev/hydrogen/passport/pkg/utils" "time" "github.com/gofiber/fiber/v2" @@ -15,7 +16,7 @@ func doAuthenticate(c *fiber.Ctx) error { Password string `json:"password" validate:"required"` } - if err := BindAndValidate(c, &data); err != nil { + if err := utils.BindAndValidate(c, &data); err != nil { return err } @@ -47,7 +48,7 @@ func doMultiFactorAuthenticate(c *fiber.Ctx) error { Code string `json:"code" validate:"required"` } - if err := BindAndValidate(c, &data); err != nil { + if err := utils.BindAndValidate(c, &data); err != nil { return err } @@ -84,7 +85,7 @@ func getToken(c *fiber.Ctx) error { GrantType string `json:"grant_type" form:"grant_type"` } - if err := BindAndValidate(c, &data); err != nil { + if err := utils.BindAndValidate(c, &data); err != nil { return err } diff --git a/pkg/server/friendships_api.go b/pkg/server/friendships_api.go index 75aeabc..59c7ba4 100644 --- a/pkg/server/friendships_api.go +++ b/pkg/server/friendships_api.go @@ -3,6 +3,7 @@ package server import ( "git.solsynth.dev/hydrogen/passport/pkg/models" "git.solsynth.dev/hydrogen/passport/pkg/services" + "git.solsynth.dev/hydrogen/passport/pkg/utils" "github.com/gofiber/fiber/v2" ) @@ -70,7 +71,7 @@ func editFriendship(c *fiber.Ctx) error { Status uint8 `json:"status"` } - if err := BindAndValidate(c, &data); err != nil { + if err := utils.BindAndValidate(c, &data); err != nil { return fiber.NewError(fiber.StatusBadRequest, err.Error()) } diff --git a/pkg/server/notifications_api.go b/pkg/server/notifications_api.go index 1f3ff94..e2c76d6 100644 --- a/pkg/server/notifications_api.go +++ b/pkg/server/notifications_api.go @@ -1,6 +1,7 @@ package server import ( + "git.solsynth.dev/hydrogen/passport/pkg/utils" "time" "git.solsynth.dev/hydrogen/passport/pkg/database" @@ -72,7 +73,7 @@ func addNotifySubscriber(c *fiber.Ctx) error { DeviceID string `json:"device_id" validate:"required"` } - if err := BindAndValidate(c, &data); err != nil { + if err := utils.BindAndValidate(c, &data); err != nil { return err } diff --git a/pkg/server/notify_api.go b/pkg/server/notify_api.go index a3aeb88..5785fdf 100644 --- a/pkg/server/notify_api.go +++ b/pkg/server/notify_api.go @@ -3,6 +3,7 @@ package server import ( "git.solsynth.dev/hydrogen/passport/pkg/models" "git.solsynth.dev/hydrogen/passport/pkg/services" + "git.solsynth.dev/hydrogen/passport/pkg/utils" "github.com/gofiber/fiber/v2" ) @@ -18,7 +19,7 @@ func notifyUser(c *fiber.Ctx) error { UserID uint `json:"user_id" validate:"required"` } - if err := BindAndValidate(c, &data); err != nil { + if err := utils.BindAndValidate(c, &data); err != nil { return err } diff --git a/pkg/server/page_api.go b/pkg/server/page_api.go index 680956e..1f25188 100644 --- a/pkg/server/page_api.go +++ b/pkg/server/page_api.go @@ -3,6 +3,7 @@ package server import ( "git.solsynth.dev/hydrogen/passport/pkg/database" "git.solsynth.dev/hydrogen/passport/pkg/models" + "git.solsynth.dev/hydrogen/passport/pkg/utils" "github.com/gofiber/fiber/v2" ) @@ -47,7 +48,7 @@ func editPersonalPage(c *fiber.Ctx) error { Links []models.AccountPageLinks `json:"links"` } - if err := BindAndValidate(c, &data); err != nil { + if err := utils.BindAndValidate(c, &data); err != nil { return err } diff --git a/pkg/server/ui/auth.go b/pkg/server/ui/auth.go deleted file mode 100644 index e7b4697..0000000 --- a/pkg/server/ui/auth.go +++ /dev/null @@ -1,26 +0,0 @@ -package ui - -import ( - "github.com/gofiber/fiber/v2" - "github.com/nicksnyder/go-i18n/v2/i18n" -) - -func signinPage(c *fiber.Ctx) error { - localizer := c.Locals("localizer").(*i18n.Localizer) - - next, _ := localizer.LocalizeMessage(&i18n.Message{ID: "next"}) - username, _ := localizer.LocalizeMessage(&i18n.Message{ID: "username"}) - password, _ := localizer.LocalizeMessage(&i18n.Message{ID: "password"}) - title, _ := localizer.LocalizeMessage(&i18n.Message{ID: "signinTitle"}) - caption, _ := localizer.LocalizeMessage(&i18n.Message{ID: "signinCaption"}) - - return c.Render("views/signin", fiber.Map{ - "i18n": fiber.Map{ - "next": next, - "username": username, - "password": password, - "title": title, - "caption": caption, - }, - }, "views/layouts/auth") -} diff --git a/pkg/server/ui/index.go b/pkg/server/ui/index.go index 9bc372b..921e455 100644 --- a/pkg/server/ui/index.go +++ b/pkg/server/ui/index.go @@ -4,5 +4,10 @@ import "github.com/gofiber/fiber/v2" func MapUserInterface(A *fiber.App) { pages := A.Group("/").Name("Pages") + + pages.Get("/sign-up", signupPage) pages.Get("/sign-in", signinPage) + + pages.Post("/sign-up", signupAction) + pages.Post("/sign-in", signinAction) } diff --git a/pkg/server/ui/signin.go b/pkg/server/ui/signin.go new file mode 100644 index 0000000..945533f --- /dev/null +++ b/pkg/server/ui/signin.go @@ -0,0 +1,77 @@ +package ui + +import ( + "fmt" + "git.solsynth.dev/hydrogen/passport/pkg/services" + "git.solsynth.dev/hydrogen/passport/pkg/utils" + "github.com/gofiber/fiber/v2" + "github.com/nicksnyder/go-i18n/v2/i18n" + "github.com/sujit-baniya/flash" +) + +func signinPage(c *fiber.Ctx) error { + localizer := c.Locals("localizer").(*i18n.Localizer) + + next, _ := localizer.LocalizeMessage(&i18n.Message{ID: "next"}) + username, _ := localizer.LocalizeMessage(&i18n.Message{ID: "username"}) + password, _ := localizer.LocalizeMessage(&i18n.Message{ID: "password"}) + signup, _ := localizer.LocalizeMessage(&i18n.Message{ID: "signupTitle"}) + title, _ := localizer.LocalizeMessage(&i18n.Message{ID: "signinTitle"}) + caption, _ := localizer.LocalizeMessage(&i18n.Message{ID: "signinCaption"}) + + return c.Render("views/signin", fiber.Map{ + "info": flash.Get(c)["message"], + "i18n": fiber.Map{ + "next": next, + "username": username, + "password": password, + "signup": signup, + "title": title, + "caption": caption, + }, + }, "views/layouts/auth") +} + +func signinAction(c *fiber.Ctx) error { + var data struct { + Username string `form:"username" validate:"required"` + Password string `form:"password" validate:"required"` + } + + if err := utils.BindAndValidate(c, &data); err != nil { + return flash.WithInfo(c, fiber.Map{ + "message": err.Error(), + }).Redirect("/sign-in") + } + + user, err := services.LookupAccount(data.Username) + if err != nil { + return flash.WithInfo(c, fiber.Map{ + "message": fmt.Sprintf("account was not found: %v", err.Error()), + }).Redirect("/sign-in") + } + + ticket, err := services.NewTicket(user, c.IP(), c.Get(fiber.HeaderUserAgent)) + if err != nil { + return flash.WithInfo(c, fiber.Map{ + "message": fmt.Sprintf("unable setup ticket: %v", err.Error()), + }).Redirect("/sign-in") + } + + ticket, err = services.ActiveTicketWithPassword(ticket, data.Password) + if err != nil { + return flash.WithInfo(c, fiber.Map{ + "message": fmt.Sprintf("invalid password: %v", err.Error()), + }).Redirect("/sign-in") + } + + if ticket.IsAvailable() != nil { + return flash.WithInfo(c, fiber.Map{ + "message": "multi factor authenticate required", + }).Redirect("/sign-in") + } else { + return flash.WithInfo(c, fiber.Map{ + "message": "done", + }).Redirect("/sign-in") + } +} diff --git a/pkg/server/ui/signup.go b/pkg/server/ui/signup.go new file mode 100644 index 0000000..744e897 --- /dev/null +++ b/pkg/server/ui/signup.go @@ -0,0 +1,86 @@ +package ui + +import ( + "fmt" + "git.solsynth.dev/hydrogen/passport/pkg/database" + "git.solsynth.dev/hydrogen/passport/pkg/models" + "git.solsynth.dev/hydrogen/passport/pkg/services" + "git.solsynth.dev/hydrogen/passport/pkg/utils" + "github.com/gofiber/fiber/v2" + "github.com/nicksnyder/go-i18n/v2/i18n" + "github.com/spf13/viper" + "github.com/sujit-baniya/flash" +) + +func signupPage(c *fiber.Ctx) error { + localizer := c.Locals("localizer").(*i18n.Localizer) + + next, _ := localizer.LocalizeMessage(&i18n.Message{ID: "next"}) + email, _ := localizer.LocalizeMessage(&i18n.Message{ID: "email"}) + nickname, _ := localizer.LocalizeMessage(&i18n.Message{ID: "nickname"}) + username, _ := localizer.LocalizeMessage(&i18n.Message{ID: "username"}) + password, _ := localizer.LocalizeMessage(&i18n.Message{ID: "password"}) + magicToken, _ := localizer.LocalizeMessage(&i18n.Message{ID: "magicToken"}) + signin, _ := localizer.LocalizeMessage(&i18n.Message{ID: "signinTitle"}) + title, _ := localizer.LocalizeMessage(&i18n.Message{ID: "signupTitle"}) + caption, _ := localizer.LocalizeMessage(&i18n.Message{ID: "signupCaption"}) + + return c.Render("views/signup", fiber.Map{ + "info": flash.Get(c)["message"], + "use_magic_token": viper.GetBool("use_registration_magic_token"), + "i18n": fiber.Map{ + "next": next, + "email": email, + "username": username, + "nickname": nickname, + "password": password, + "magic_token": magicToken, + "signin": signin, + "title": title, + "caption": caption, + }, + }, "views/layouts/auth") +} + +func signupAction(c *fiber.Ctx) error { + var data struct { + Name string `form:"name" validate:"required,lowercase,alphanum,min=4,max=16"` + Nick string `form:"nick" validate:"required,min=4,max=24"` + Email string `form:"email" validate:"required,email"` + Password string `form:"password" validate:"required,min=4,max=32"` + MagicToken string `form:"magic_token"` + } + + if err := utils.BindAndValidate(c, &data); err != nil { + return flash.WithInfo(c, fiber.Map{ + "message": err.Error(), + }).Redirect("/sign-up") + } else if viper.GetBool("use_registration_magic_token") && len(data.MagicToken) <= 0 { + return flash.WithInfo(c, fiber.Map{ + "message": "magic token was required", + }).Redirect("/sign-up") + } else if viper.GetBool("use_registration_magic_token") { + if tk, err := services.ValidateMagicToken(data.MagicToken, models.RegistrationMagicToken); err != nil { + return flash.WithInfo(c, fiber.Map{ + "message": fmt.Sprintf("magic token was invalid: %v", err.Error()), + }).Redirect("/sign-up") + } else { + database.C.Delete(&tk) + } + } + + if _, err := services.CreateAccount( + data.Name, + data.Nick, + data.Email, + data.Password, + ); err != nil { + return flash.WithInfo(c, fiber.Map{ + "message": err.Error(), + }).Redirect("/sign-up") + } else { + return flash.WithInfo(c, fiber.Map{ + "message": "account has been created. now you can sign in!", + }).Redirect("/sign-in") + } +} diff --git a/pkg/services/ticket.go b/pkg/services/ticket.go index 5379a2e..e0608b3 100644 --- a/pkg/services/ticket.go +++ b/pkg/services/ticket.go @@ -34,14 +34,15 @@ func NewTicket(user models.Account, ip, ua string) (models.AuthTicket, error) { } ticket = models.AuthTicket{ - Claims: []string{"*"}, - Audiences: []string{"passport"}, - IpAddress: ip, - UserAgent: ua, - RequireMFA: DetectRisk(user, ip, ua), - ExpiredAt: lo.ToPtr(time.Now().Add(2 * time.Hour)), - AvailableAt: nil, - AccountID: user.ID, + Claims: []string{"*"}, + Audiences: []string{"passport"}, + IpAddress: ip, + UserAgent: ua, + RequireMFA: DetectRisk(user, ip, ua), + RequireAuthenticate: true, + ExpiredAt: lo.ToPtr(time.Now().Add(2 * time.Hour)), + AvailableAt: nil, + AccountID: user.ID, } err := database.C.Save(&ticket).Error @@ -81,7 +82,7 @@ func ActiveTicketWithPassword(ticket models.AuthTicket, password string) (models if ticket.AvailableAt != nil { return ticket, nil } else if !ticket.RequireAuthenticate { - return ticket, fmt.Errorf("detected risk, multi factor authentication required") + return ticket, nil } if factor, err := GetPasswordFactor(ticket.AccountID); err != nil { diff --git a/pkg/server/utils.go b/pkg/utils/request.go similarity index 96% rename from pkg/server/utils.go rename to pkg/utils/request.go index 8502c7f..40ee754 100644 --- a/pkg/server/utils.go +++ b/pkg/utils/request.go @@ -1,4 +1,4 @@ -package server +package utils import ( "github.com/go-playground/validator/v10" diff --git a/pkg/views/layouts/auth.gohtml b/pkg/views/layouts/auth.gohtml index 926a029..48762bc 100644 --- a/pkg/views/layouts/auth.gohtml +++ b/pkg/views/layouts/auth.gohtml @@ -5,8 +5,16 @@
-
- {{embed}} +
+ {{if ne .info nil}} +
+
{{.info}}
+
+ {{end}} + +
+ {{embed}} +
@@ -20,9 +28,19 @@ align-items: center; } - .wrapper-card { + .wrapper-middleware { width: 100%; - max-width: 720px; + min-width: 0; + max-width: min(800px, 100dvw); + + margin: 1rem; + + display: flex; + flex-direction: column; + gap: 1rem; + } + + .wrapper-card { transition: all .3s; height: auto; overflow: auto; @@ -31,9 +49,25 @@ justify-content: center; border-radius: 28px; padding: 56px; - margin: 2rem; gap: 0 2rem; - background-color: #ebf1fa; + background-color: var(--md-sys-color-surface); + color: var(--md-sys-color-on-surface) + } + + .alert { + width: 100%; + max-width: 800px; + padding: 16px; + border-radius: 16px; + background-color: var(--md-sys-color-secondary-container); + color: var(--md-sys-color-on-secondary-container); + display: flex; + gap: 8px; + } + + .alert .content { + flex-grow: 1; + text-transform: capitalize; } .logo { diff --git a/pkg/views/partials/header.gohtml b/pkg/views/partials/header.gohtml index 036c18f..e10ba0f 100644 --- a/pkg/views/partials/header.gohtml +++ b/pkg/views/partials/header.gohtml @@ -10,6 +10,11 @@ + +