Spaces:
Sleeping
Sleeping
Commit ·
f71a293
1
Parent(s): 1985cbb
Deploy files from GitHub repository
Browse files- .env.example +9 -0
- .github/workflows/main_huggingface.yml +52 -0
- .gitignore +6 -0
- Dockerfile +30 -0
- LICENSE +201 -0
- README.md +8 -0
- config/config.go +34 -0
- config/database_connection_config.go +61 -0
- controller/auth/auth_change_password_controller.go +21 -0
- controller/auth/auth_login_controller.go +20 -0
- controller/auth/auth_register_controller.go +20 -0
- controller/controller.go +65 -0
- controller/home_controller.go +9 -0
- controller/user/user_profile_controller.go +21 -0
- controller/user/user_update_profile_controller.go +25 -0
- go.mod +67 -0
- go.sum +168 -0
- main.go +14 -0
- middleware/authentication_middleware.go +37 -0
- middleware/middleware.go +31 -0
- middleware/response_middleware.go +45 -0
- models/authentication_payload_model.go +7 -0
- models/custom_claim.go +8 -0
- models/database_orm_model.go +31 -0
- models/exception_model.go +12 -0
- models/model.go +1 -0
- models/request_model.go +42 -0
- models/response_model.go +25 -0
- repositories/account_repository.go +87 -0
- repositories/repository.go +117 -0
- router/auth_route.go +15 -0
- router/router.go +21 -0
- router/user_route.go +15 -0
- services/authentication_service.go +71 -0
- services/jwt_service.go +80 -0
- services/register_service.go +46 -0
- services/service.go +42 -0
- services/user_profile_service.go +97 -0
- utils/Logger.go +28 -0
- utils/api_response.go +53 -0
- utils/helper.go +11 -0
- utils/util.go +9 -0
- views/index.html +61 -0
- views/login.html +77 -0
- views/profile.html +108 -0
- views/register.html +88 -0
- views/script.js +1 -0
- views/scripts/script.js +270 -0
- views/style/styles.css +291 -0
.env.example
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
DB_HOST =
|
| 2 |
+
DB_USER =
|
| 3 |
+
DB_PASSWORD =
|
| 4 |
+
DB_PORT =
|
| 5 |
+
DB_NAME =
|
| 6 |
+
SALT =
|
| 7 |
+
HOST_ADDRESS =
|
| 8 |
+
HOST_PORT =
|
| 9 |
+
LOG_PATH = logs
|
.github/workflows/main_huggingface.yml
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Deploy to Huggingface
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
|
| 8 |
+
jobs:
|
| 9 |
+
deploy-to-huggingface:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
|
| 12 |
+
steps:
|
| 13 |
+
# Checkout repository
|
| 14 |
+
- name: Checkout Repository
|
| 15 |
+
uses: actions/checkout@v3
|
| 16 |
+
|
| 17 |
+
# Setup Git
|
| 18 |
+
- name: Setup Git for Huggingface
|
| 19 |
+
run: |
|
| 20 |
+
git config --global user.email "abdan.hafidz@gmail.com"
|
| 21 |
+
git config --global user.name "abdanhafidz"
|
| 22 |
+
|
| 23 |
+
# Clone Huggingface Space Repository
|
| 24 |
+
- name: Clone Huggingface Space
|
| 25 |
+
env:
|
| 26 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 27 |
+
run: |
|
| 28 |
+
git clone https://huggingface.co/spaces/lifedebugger/pweb-api space
|
| 29 |
+
|
| 30 |
+
# Update Git Remote URL and Pull Latest Changes
|
| 31 |
+
- name: Update Remote and Pull Changes
|
| 32 |
+
env:
|
| 33 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 34 |
+
run: |
|
| 35 |
+
cd space
|
| 36 |
+
git remote set-url origin https://lifedebugger:$HF_TOKEN@huggingface.co/spaces/lifedebugger/pweb-api
|
| 37 |
+
git pull origin main || echo "No changes to pull"
|
| 38 |
+
|
| 39 |
+
# Copy Files to Huggingface Space
|
| 40 |
+
- name: Copy Files to Space
|
| 41 |
+
run: |
|
| 42 |
+
rsync -av --exclude='.git' ./ space/
|
| 43 |
+
|
| 44 |
+
# Commit and Push to Huggingface Space
|
| 45 |
+
- name: Commit and Push to Huggingface
|
| 46 |
+
env:
|
| 47 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 48 |
+
run: |
|
| 49 |
+
cd space
|
| 50 |
+
git add .
|
| 51 |
+
git commit -m "Deploy files from GitHub repository" || echo "No changes to commit"
|
| 52 |
+
git push origin main || echo "No changes to push"
|
.gitignore
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
vendor/
|
| 3 |
+
quzuu-be.exe
|
| 4 |
+
.qodo
|
| 5 |
+
.error
|
| 6 |
+
logs/
|
Dockerfile
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Gunakan image dasar Golang versi 1.21.6
|
| 2 |
+
FROM golang:1.24.1 AS builder
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy go.mod dan go.sum
|
| 8 |
+
COPY go.mod go.sum ./
|
| 9 |
+
|
| 10 |
+
# Download dependencies
|
| 11 |
+
RUN go mod download
|
| 12 |
+
|
| 13 |
+
# Copy seluruh kode
|
| 14 |
+
COPY . .
|
| 15 |
+
|
| 16 |
+
# Buat file .env dengan variabel environment yang dibutuhkan
|
| 17 |
+
RUN echo "DB_HOST=aws-0-ap-southeast-1.pooler.supabase.com" >> .env && \
|
| 18 |
+
echo "DB_USER=postgres.soqmbegvnpowforfhjki" >> .env && \
|
| 19 |
+
echo "DB_PASSWORD=PwebAPI2025" >> .env && \
|
| 20 |
+
echo "DB_PORT=5432" >> .env && \
|
| 21 |
+
echo "DB_NAME=postgres" >> .env && \
|
| 22 |
+
echo "HOST_ADDRESS = 0.0.0.0" >> .env && \
|
| 23 |
+
echo "HOST_PORT = 7860" >> .env && \
|
| 24 |
+
echo "SALT=OkeGASOKEGASTAMBAHDUASORANGG45" >> .env
|
| 25 |
+
|
| 26 |
+
# Build aplikasi
|
| 27 |
+
RUN go build -o main .
|
| 28 |
+
|
| 29 |
+
# Jalankan aplikasi
|
| 30 |
+
CMD ["./main"]
|
LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright 2025 Abdan Hafidz
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Pweb Api
|
| 3 |
+
emoji: 📉
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
config/config.go
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package config
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"os"
|
| 5 |
+
"strconv"
|
| 6 |
+
|
| 7 |
+
"github.com/joho/godotenv"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
var TCP_ADDRESS string
|
| 11 |
+
var LOG_PATH string
|
| 12 |
+
|
| 13 |
+
var HOST_ADDRESS string
|
| 14 |
+
var HOST_PORT string
|
| 15 |
+
var EMAIL_VERIFICATION_DURATION int
|
| 16 |
+
|
| 17 |
+
var SMTP_SENDER_EMAIL string
|
| 18 |
+
var SMTP_SENDER_PASSWORD string
|
| 19 |
+
var SMTP_HOST string
|
| 20 |
+
var SMTP_PORT string
|
| 21 |
+
|
| 22 |
+
func init() {
|
| 23 |
+
godotenv.Load()
|
| 24 |
+
HOST_ADDRESS = os.Getenv("HOST_ADDRESS")
|
| 25 |
+
HOST_PORT = os.Getenv("HOST_PORT")
|
| 26 |
+
TCP_ADDRESS = HOST_ADDRESS + ":" + HOST_PORT
|
| 27 |
+
LOG_PATH = os.Getenv("LOG_PATH")
|
| 28 |
+
EMAIL_VERIFICATION_DURATION, _ = strconv.Atoi(os.Getenv("EMAIL_VERIFICATION_DURATION"))
|
| 29 |
+
SMTP_SENDER_EMAIL = os.Getenv("SMTP_SENDER_EMAIL")
|
| 30 |
+
SMTP_SENDER_PASSWORD = os.Getenv("SMTP_SENDER_PASSWORD")
|
| 31 |
+
SMTP_HOST = os.Getenv("SMTP_HOST")
|
| 32 |
+
SMTP_PORT = os.Getenv("SMTP_PORT")
|
| 33 |
+
// Menampilkan nilai variabel lingkungan
|
| 34 |
+
}
|
config/database_connection_config.go
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package config
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"fmt"
|
| 5 |
+
"log"
|
| 6 |
+
"os"
|
| 7 |
+
|
| 8 |
+
"gorm.io/driver/postgres"
|
| 9 |
+
"gorm.io/gorm"
|
| 10 |
+
"gorm.io/gorm/logger"
|
| 11 |
+
|
| 12 |
+
"github.com/joho/godotenv"
|
| 13 |
+
"pweb-api.abdanhafidz.com/models"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
var DB *gorm.DB
|
| 17 |
+
var err error
|
| 18 |
+
var Salt string
|
| 19 |
+
|
| 20 |
+
func init() {
|
| 21 |
+
godotenv.Load()
|
| 22 |
+
if err != nil {
|
| 23 |
+
fmt.Println("Gagal membaca file .env")
|
| 24 |
+
return
|
| 25 |
+
}
|
| 26 |
+
os.Setenv("TZ", "Asia/Jakarta")
|
| 27 |
+
dbHost := os.Getenv("DB_HOST")
|
| 28 |
+
dbPort := os.Getenv("DB_PORT")
|
| 29 |
+
dbUser := os.Getenv("DB_USER")
|
| 30 |
+
dbPassword := os.Getenv("DB_PASSWORD")
|
| 31 |
+
dbName := os.Getenv("DB_NAME")
|
| 32 |
+
Salt := os.Getenv("SALT")
|
| 33 |
+
dsn := "host=" + dbHost + " user=" + dbUser + " password=" + dbPassword + " dbname=" + dbName + " port=" + dbPort + " sslmode=disable TimeZone=Asia/Jakarta"
|
| 34 |
+
DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{TranslateError: true})
|
| 35 |
+
if err != nil {
|
| 36 |
+
panic(err)
|
| 37 |
+
}
|
| 38 |
+
if Salt == "" {
|
| 39 |
+
Salt = "D3f4u|t"
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// Call AutoMigrateAll to perform auto-migration
|
| 43 |
+
AutoMigrateAll(DB)
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
func AutoMigrateAll(db *gorm.DB) {
|
| 47 |
+
// Enable logger to see SQL logs
|
| 48 |
+
db.Logger.LogMode(logger.Info)
|
| 49 |
+
|
| 50 |
+
// Auto-migrate all models
|
| 51 |
+
err := db.AutoMigrate(
|
| 52 |
+
&models.Account{},
|
| 53 |
+
&models.AccountDetails{},
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
if err != nil {
|
| 57 |
+
log.Fatal(err)
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
fmt.Println("Migration completed successfully.")
|
| 61 |
+
}
|
controller/auth/auth_change_password_controller.go
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package auth
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/gin-gonic/gin"
|
| 5 |
+
"pweb-api.abdanhafidz.com/controller"
|
| 6 |
+
"pweb-api.abdanhafidz.com/models"
|
| 7 |
+
"pweb-api.abdanhafidz.com/services"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
func ChangePassword(c *gin.Context) {
|
| 11 |
+
authentication := services.AuthenticationService{}
|
| 12 |
+
changePasswordController := controller.Controller[models.ChangePasswordRequest, models.Account, models.AuthenticatedUser]{
|
| 13 |
+
Service: &authentication.Service,
|
| 14 |
+
}
|
| 15 |
+
changePasswordController.HeaderParse(c, func() {
|
| 16 |
+
changePasswordController.Service.Constructor.Id = uint(changePasswordController.AccountData.UserID)
|
| 17 |
+
})
|
| 18 |
+
changePasswordController.RequestJSON(c, func() {
|
| 19 |
+
authentication.Update(changePasswordController.Request.OldPassword, changePasswordController.Request.NewPassword)
|
| 20 |
+
})
|
| 21 |
+
}
|
controller/auth/auth_login_controller.go
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package auth
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/gin-gonic/gin"
|
| 5 |
+
"pweb-api.abdanhafidz.com/controller"
|
| 6 |
+
"pweb-api.abdanhafidz.com/models"
|
| 7 |
+
"pweb-api.abdanhafidz.com/services"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
func Login(c *gin.Context) {
|
| 11 |
+
authentication := services.AuthenticationService{}
|
| 12 |
+
loginController := controller.Controller[models.LoginRequest, models.Account, models.AuthenticatedUser]{
|
| 13 |
+
Service: &authentication.Service,
|
| 14 |
+
}
|
| 15 |
+
loginController.RequestJSON(c, func() {
|
| 16 |
+
loginController.Service.Constructor.Email = loginController.Request.Email
|
| 17 |
+
loginController.Service.Constructor.Password = loginController.Request.Password
|
| 18 |
+
authentication.Authenticate()
|
| 19 |
+
})
|
| 20 |
+
}
|
controller/auth/auth_register_controller.go
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package auth
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/gin-gonic/gin"
|
| 5 |
+
"pweb-api.abdanhafidz.com/controller"
|
| 6 |
+
"pweb-api.abdanhafidz.com/models"
|
| 7 |
+
"pweb-api.abdanhafidz.com/services"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
func Register(c *gin.Context) {
|
| 11 |
+
register := services.RegisterService{}
|
| 12 |
+
registerController := controller.Controller[models.RegisterRequest, models.Account, models.Account]{
|
| 13 |
+
Service: ®ister.Service,
|
| 14 |
+
}
|
| 15 |
+
registerController.RequestJSON(c, func() {
|
| 16 |
+
registerController.Service.Constructor.Password = registerController.Request.Password
|
| 17 |
+
registerController.Service.Constructor.Email = registerController.Request.Email
|
| 18 |
+
register.Create()
|
| 19 |
+
})
|
| 20 |
+
}
|
controller/controller.go
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package controller
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/gin-gonic/gin"
|
| 5 |
+
"pweb-api.abdanhafidz.com/models"
|
| 6 |
+
"pweb-api.abdanhafidz.com/services"
|
| 7 |
+
"pweb-api.abdanhafidz.com/utils"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
type (
|
| 11 |
+
Controllers interface {
|
| 12 |
+
RequestJSON(c *gin.Context)
|
| 13 |
+
Response(c *gin.Context)
|
| 14 |
+
}
|
| 15 |
+
Controller[T1 any, T2 any, T3 any] struct {
|
| 16 |
+
AccountData models.AccountData
|
| 17 |
+
Request T1
|
| 18 |
+
Service *services.Service[T2, T3]
|
| 19 |
+
}
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
func (controller *Controller[T1, T2, T3]) HeaderParse(c *gin.Context, act func()) {
|
| 23 |
+
cParam, _ := c.Get("accountData")
|
| 24 |
+
if cParam != nil {
|
| 25 |
+
controller.AccountData = cParam.(models.AccountData)
|
| 26 |
+
}
|
| 27 |
+
act()
|
| 28 |
+
}
|
| 29 |
+
func (controller *Controller[T1, T2, T3]) RequestJSON(c *gin.Context, act func()) {
|
| 30 |
+
cParam, _ := c.Get("accountData")
|
| 31 |
+
if cParam != nil {
|
| 32 |
+
controller.AccountData = cParam.(models.AccountData)
|
| 33 |
+
}
|
| 34 |
+
errBinding := c.ShouldBindJSON(&controller.Request)
|
| 35 |
+
if errBinding != nil {
|
| 36 |
+
utils.ResponseFAIL(c, 400, models.Exception{
|
| 37 |
+
BadRequest: true,
|
| 38 |
+
Message: "Invalid Request!, recheck your request, there's must be some problem about required parameter or type parameter",
|
| 39 |
+
})
|
| 40 |
+
return
|
| 41 |
+
} else {
|
| 42 |
+
act()
|
| 43 |
+
controller.Response(c)
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
func (controller *Controller[T1, T2, T3]) Response(c *gin.Context) {
|
| 47 |
+
switch {
|
| 48 |
+
case controller.Service.Error != nil:
|
| 49 |
+
utils.LogError(controller.Service.Error)
|
| 50 |
+
utils.ResponseFAIL(c, 500, models.Exception{
|
| 51 |
+
InternalServerError: true,
|
| 52 |
+
Message: "Internal Server Error",
|
| 53 |
+
})
|
| 54 |
+
case controller.Service.Exception.DataDuplicate:
|
| 55 |
+
utils.ResponseFAIL(c, 400, controller.Service.Exception)
|
| 56 |
+
case controller.Service.Exception.Unauthorized:
|
| 57 |
+
utils.ResponseFAIL(c, 401, controller.Service.Exception)
|
| 58 |
+
case controller.Service.Exception.DataNotFound:
|
| 59 |
+
utils.ResponseFAIL(c, 404, controller.Service.Exception)
|
| 60 |
+
case controller.Service.Exception.Message != "":
|
| 61 |
+
utils.ResponseFAIL(c, 400, controller.Service.Exception)
|
| 62 |
+
default:
|
| 63 |
+
utils.ResponseOK(c, controller.Service.Result)
|
| 64 |
+
}
|
| 65 |
+
}
|
controller/home_controller.go
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package controller
|
| 2 |
+
|
| 3 |
+
import "github.com/gin-gonic/gin"
|
| 4 |
+
|
| 5 |
+
func HomeController(c *gin.Context) {
|
| 6 |
+
c.JSON(200, gin.H{
|
| 7 |
+
"message": "PWEB API 2025 by Abdan Hafidz!",
|
| 8 |
+
})
|
| 9 |
+
}
|
controller/user/user_profile_controller.go
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package user
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/gin-gonic/gin"
|
| 5 |
+
"pweb-api.abdanhafidz.com/controller"
|
| 6 |
+
"pweb-api.abdanhafidz.com/models"
|
| 7 |
+
"pweb-api.abdanhafidz.com/services"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
func Profile(c *gin.Context) {
|
| 11 |
+
userProfile := services.UserProfileService{}
|
| 12 |
+
userProfileController := controller.Controller[any, models.AccountDetails, models.UserProfileResponse]{
|
| 13 |
+
Service: &userProfile.Service,
|
| 14 |
+
}
|
| 15 |
+
userProfileController.HeaderParse(c, func() {
|
| 16 |
+
userProfileController.Service.Constructor.AccountId = uint(userProfileController.AccountData.UserID)
|
| 17 |
+
userProfile.Retrieve()
|
| 18 |
+
userProfileController.Response(c)
|
| 19 |
+
},
|
| 20 |
+
)
|
| 21 |
+
}
|
controller/user/user_update_profile_controller.go
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package user
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/gin-gonic/gin"
|
| 5 |
+
"pweb-api.abdanhafidz.com/controller"
|
| 6 |
+
"pweb-api.abdanhafidz.com/models"
|
| 7 |
+
"pweb-api.abdanhafidz.com/services"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
func UpdateProfile(c *gin.Context) {
|
| 11 |
+
userProfile := services.UserProfileService{}
|
| 12 |
+
userUpdateProfileController := controller.Controller[models.AccountDetails, models.AccountDetails, models.UserProfileResponse]{
|
| 13 |
+
Service: &userProfile.Service,
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
userUpdateProfileController.RequestJSON(c, func() {
|
| 17 |
+
userUpdateProfileController.Service.Constructor = userUpdateProfileController.Request
|
| 18 |
+
userUpdateProfileController.HeaderParse(c, func() {
|
| 19 |
+
userUpdateProfileController.Service.Constructor.AccountId = uint(userUpdateProfileController.AccountData.UserID)
|
| 20 |
+
|
| 21 |
+
})
|
| 22 |
+
userProfile.Update()
|
| 23 |
+
},
|
| 24 |
+
)
|
| 25 |
+
}
|
go.mod
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module pweb-api.abdanhafidz.com
|
| 2 |
+
|
| 3 |
+
go 1.24.0
|
| 4 |
+
|
| 5 |
+
require (
|
| 6 |
+
github.com/gin-gonic/gin v1.10.0
|
| 7 |
+
github.com/golang-jwt/jwt/v5 v5.2.1
|
| 8 |
+
github.com/gosimple/slug v1.15.0
|
| 9 |
+
github.com/joho/godotenv v1.5.1
|
| 10 |
+
github.com/satori/go.uuid v1.2.0
|
| 11 |
+
golang.org/x/crypto v0.36.0
|
| 12 |
+
google.golang.org/api v0.228.0
|
| 13 |
+
gorm.io/driver/postgres v1.5.11
|
| 14 |
+
gorm.io/gorm v1.25.12
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
require (
|
| 18 |
+
cloud.google.com/go/auth v0.15.0 // indirect
|
| 19 |
+
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
|
| 20 |
+
cloud.google.com/go/compute/metadata v0.6.0 // indirect
|
| 21 |
+
github.com/bytedance/sonic v1.13.1 // indirect
|
| 22 |
+
github.com/bytedance/sonic/loader v0.2.4 // indirect
|
| 23 |
+
github.com/cloudwego/base64x v0.1.5 // indirect
|
| 24 |
+
github.com/felixge/httpsnoop v1.0.4 // indirect
|
| 25 |
+
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
| 26 |
+
github.com/gin-contrib/sse v1.0.0 // indirect
|
| 27 |
+
github.com/go-logr/logr v1.4.2 // indirect
|
| 28 |
+
github.com/go-logr/stdr v1.2.2 // indirect
|
| 29 |
+
github.com/go-playground/locales v0.14.1 // indirect
|
| 30 |
+
github.com/go-playground/universal-translator v0.18.1 // indirect
|
| 31 |
+
github.com/go-playground/validator/v10 v10.25.0 // indirect
|
| 32 |
+
github.com/goccy/go-json v0.10.5 // indirect
|
| 33 |
+
github.com/google/s2a-go v0.1.9 // indirect
|
| 34 |
+
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
|
| 35 |
+
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
|
| 36 |
+
github.com/gosimple/unidecode v1.0.1 // indirect
|
| 37 |
+
github.com/jackc/pgpassfile v1.0.0 // indirect
|
| 38 |
+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
| 39 |
+
github.com/jackc/pgx/v5 v5.7.2 // indirect
|
| 40 |
+
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
| 41 |
+
github.com/jinzhu/inflection v1.0.0 // indirect
|
| 42 |
+
github.com/jinzhu/now v1.1.5 // indirect
|
| 43 |
+
github.com/json-iterator/go v1.1.12 // indirect
|
| 44 |
+
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
| 45 |
+
github.com/leodido/go-urn v1.4.0 // indirect
|
| 46 |
+
github.com/mattn/go-isatty v0.0.20 // indirect
|
| 47 |
+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
| 48 |
+
github.com/modern-go/reflect2 v1.0.2 // indirect
|
| 49 |
+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
| 50 |
+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
| 51 |
+
github.com/ugorji/go/codec v1.2.12 // indirect
|
| 52 |
+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
| 53 |
+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
|
| 54 |
+
go.opentelemetry.io/otel v1.34.0 // indirect
|
| 55 |
+
go.opentelemetry.io/otel/metric v1.34.0 // indirect
|
| 56 |
+
go.opentelemetry.io/otel/trace v1.34.0 // indirect
|
| 57 |
+
golang.org/x/arch v0.15.0 // indirect
|
| 58 |
+
golang.org/x/net v0.37.0 // indirect
|
| 59 |
+
golang.org/x/oauth2 v0.28.0 // indirect
|
| 60 |
+
golang.org/x/sync v0.12.0 // indirect
|
| 61 |
+
golang.org/x/sys v0.31.0 // indirect
|
| 62 |
+
golang.org/x/text v0.23.0 // indirect
|
| 63 |
+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 // indirect
|
| 64 |
+
google.golang.org/grpc v1.71.0 // indirect
|
| 65 |
+
google.golang.org/protobuf v1.36.6 // indirect
|
| 66 |
+
gopkg.in/yaml.v3 v3.0.1 // indirect
|
| 67 |
+
)
|
go.sum
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cloud.google.com/go/auth v0.15.0 h1:Ly0u4aA5vG/fsSsxu98qCQBemXtAtJf+95z9HK+cxps=
|
| 2 |
+
cloud.google.com/go/auth v0.15.0/go.mod h1:WJDGqZ1o9E9wKIL+IwStfyn/+s59zl4Bi+1KQNVXLZ8=
|
| 3 |
+
cloud.google.com/go/auth/oauth2adapt v0.2.8 h1:keo8NaayQZ6wimpNSmW5OPc283g65QNIiLpZnkHRbnc=
|
| 4 |
+
cloud.google.com/go/auth/oauth2adapt v0.2.8/go.mod h1:XQ9y31RkqZCcwJWNSx2Xvric3RrU88hAYYbjDWYDL+c=
|
| 5 |
+
cloud.google.com/go/compute/metadata v0.6.0 h1:A6hENjEsCDtC1k8byVsgwvVcioamEHvZ4j01OwKxG9I=
|
| 6 |
+
cloud.google.com/go/compute/metadata v0.6.0/go.mod h1:FjyFAW1MW0C203CEOMDTu3Dk1FlqW3Rga40jzHL4hfg=
|
| 7 |
+
github.com/bytedance/sonic v1.13.1 h1:Jyd5CIvdFnkOWuKXr+wm4Nyk2h0yAFsr8ucJgEasO3g=
|
| 8 |
+
github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
|
| 9 |
+
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
| 10 |
+
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
|
| 11 |
+
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
| 12 |
+
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
|
| 13 |
+
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
|
| 14 |
+
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
|
| 15 |
+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
| 16 |
+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
| 17 |
+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
| 18 |
+
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
| 19 |
+
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
| 20 |
+
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
| 21 |
+
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
| 22 |
+
github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E=
|
| 23 |
+
github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=
|
| 24 |
+
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
|
| 25 |
+
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
| 26 |
+
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
| 27 |
+
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
| 28 |
+
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
| 29 |
+
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
| 30 |
+
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
| 31 |
+
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
| 32 |
+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
| 33 |
+
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
| 34 |
+
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
| 35 |
+
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
| 36 |
+
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
| 37 |
+
github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8=
|
| 38 |
+
github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
|
| 39 |
+
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
| 40 |
+
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
| 41 |
+
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
| 42 |
+
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
| 43 |
+
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
| 44 |
+
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
| 45 |
+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
| 46 |
+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
| 47 |
+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
| 48 |
+
github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0=
|
| 49 |
+
github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM=
|
| 50 |
+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
| 51 |
+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
| 52 |
+
github.com/googleapis/enterprise-certificate-proxy v0.3.6 h1:GW/XbdyBFQ8Qe+YAmFU9uHLo7OnF5tL52HFAgMmyrf4=
|
| 53 |
+
github.com/googleapis/enterprise-certificate-proxy v0.3.6/go.mod h1:MkHOF77EYAE7qfSuSS9PU6g4Nt4e11cnsDUowfwewLA=
|
| 54 |
+
github.com/googleapis/gax-go/v2 v2.14.1 h1:hb0FFeiPaQskmvakKu5EbCbpntQn48jyHuvrkurSS/Q=
|
| 55 |
+
github.com/googleapis/gax-go/v2 v2.14.1/go.mod h1:Hb/NubMaVM88SrNkvl8X/o8XWwDJEPqouaLeN2IUxoA=
|
| 56 |
+
github.com/gosimple/slug v1.15.0 h1:wRZHsRrRcs6b0XnxMUBM6WK1U1Vg5B0R7VkIf1Xzobo=
|
| 57 |
+
github.com/gosimple/slug v1.15.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
|
| 58 |
+
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
|
| 59 |
+
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
|
| 60 |
+
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
| 61 |
+
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
| 62 |
+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
| 63 |
+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
| 64 |
+
github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
|
| 65 |
+
github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
|
| 66 |
+
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
| 67 |
+
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
| 68 |
+
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
| 69 |
+
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
| 70 |
+
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
| 71 |
+
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
| 72 |
+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
| 73 |
+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
| 74 |
+
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
| 75 |
+
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
| 76 |
+
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
| 77 |
+
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
| 78 |
+
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
| 79 |
+
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
| 80 |
+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
| 81 |
+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
| 82 |
+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
| 83 |
+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
| 84 |
+
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
| 85 |
+
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
| 86 |
+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
| 87 |
+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
| 88 |
+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
| 89 |
+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
| 90 |
+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
| 91 |
+
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
| 92 |
+
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
| 93 |
+
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
|
| 94 |
+
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
|
| 95 |
+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
| 96 |
+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
| 97 |
+
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
| 98 |
+
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
| 99 |
+
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
| 100 |
+
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
| 101 |
+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
| 102 |
+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
| 103 |
+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
| 104 |
+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
| 105 |
+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
| 106 |
+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
| 107 |
+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
| 108 |
+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
| 109 |
+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
| 110 |
+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
| 111 |
+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
| 112 |
+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
| 113 |
+
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
| 114 |
+
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
| 115 |
+
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
| 116 |
+
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
| 117 |
+
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
| 118 |
+
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
| 119 |
+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 h1:rgMkmiGfix9vFJDcDi1PK8WEQP4FLQwLDfhp5ZLpFeE=
|
| 120 |
+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0/go.mod h1:ijPqXp5P6IRRByFVVg9DY8P5HkxkHE5ARIa+86aXPf4=
|
| 121 |
+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 h1:CV7UdSGJt/Ao6Gp4CXckLxVRRsRgDHoI8XjbL3PDl8s=
|
| 122 |
+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0/go.mod h1:FRmFuRJfag1IZ2dPkHnEoSFVgTVPUd2qf5Vi69hLb8I=
|
| 123 |
+
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
|
| 124 |
+
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
|
| 125 |
+
go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=
|
| 126 |
+
go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=
|
| 127 |
+
go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A=
|
| 128 |
+
go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU=
|
| 129 |
+
go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk=
|
| 130 |
+
go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w=
|
| 131 |
+
go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=
|
| 132 |
+
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
|
| 133 |
+
golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw=
|
| 134 |
+
golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE=
|
| 135 |
+
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
|
| 136 |
+
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
|
| 137 |
+
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
|
| 138 |
+
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
| 139 |
+
golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc=
|
| 140 |
+
golang.org/x/oauth2 v0.28.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
|
| 141 |
+
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
|
| 142 |
+
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
| 143 |
+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 144 |
+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
| 145 |
+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
| 146 |
+
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
| 147 |
+
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
| 148 |
+
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
|
| 149 |
+
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
| 150 |
+
google.golang.org/api v0.228.0 h1:X2DJ/uoWGnY5obVjewbp8icSL5U4FzuCfy9OjbLSnLs=
|
| 151 |
+
google.golang.org/api v0.228.0/go.mod h1:wNvRS1Pbe8r4+IfBIniV8fwCpGwTrYa+kMUDiC5z5a4=
|
| 152 |
+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 h1:iK2jbkWL86DXjEx0qiHcRE9dE4/Ahua5k6V8OWFb//c=
|
| 153 |
+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4/go.mod h1:LuRYeWDFV6WOn90g357N17oMCaxpgCnbi/44qJvDn2I=
|
| 154 |
+
google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg=
|
| 155 |
+
google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=
|
| 156 |
+
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
| 157 |
+
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
| 158 |
+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
| 159 |
+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
| 160 |
+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
| 161 |
+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
| 162 |
+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
| 163 |
+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
| 164 |
+
gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
|
| 165 |
+
gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
|
| 166 |
+
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
|
| 167 |
+
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
|
| 168 |
+
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
main.go
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package main
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"fmt"
|
| 5 |
+
|
| 6 |
+
"pweb-api.abdanhafidz.com/config"
|
| 7 |
+
"pweb-api.abdanhafidz.com/router"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
func main() {
|
| 11 |
+
fmt.Println("Server started on ", config.TCP_ADDRESS, ", port :", config.HOST_PORT)
|
| 12 |
+
router.StartService()
|
| 13 |
+
|
| 14 |
+
}
|
middleware/authentication_middleware.go
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// auth/auth.go
|
| 2 |
+
|
| 3 |
+
package middleware
|
| 4 |
+
|
| 5 |
+
import (
|
| 6 |
+
"github.com/gin-gonic/gin"
|
| 7 |
+
"pweb-api.abdanhafidz.com/models"
|
| 8 |
+
"pweb-api.abdanhafidz.com/services"
|
| 9 |
+
"pweb-api.abdanhafidz.com/utils"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
func AuthUser(c *gin.Context) {
|
| 13 |
+
var currAccData models.AccountData
|
| 14 |
+
if c.Request.Header["Authorization"] != nil {
|
| 15 |
+
token := c.Request.Header["Authorization"]
|
| 16 |
+
|
| 17 |
+
currAccData.UserID, currAccData.VerifyStatus, currAccData.ErrVerif = services.VerifyToken(token[0])
|
| 18 |
+
|
| 19 |
+
if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" {
|
| 20 |
+
currAccData.UserID = 0
|
| 21 |
+
utils.ResponseFAIL(c, 401, models.Exception{Unauthorized: true, Message: "Your session is expired, Please re-Login!"})
|
| 22 |
+
c.Abort()
|
| 23 |
+
return
|
| 24 |
+
} else {
|
| 25 |
+
c.Set("accountData", currAccData)
|
| 26 |
+
c.Next()
|
| 27 |
+
}
|
| 28 |
+
} else {
|
| 29 |
+
currAccData.UserID = 0
|
| 30 |
+
currAccData.VerifyStatus = "no-token"
|
| 31 |
+
currAccData.ErrVerif = nil
|
| 32 |
+
utils.ResponseFAIL(c, 401, models.Exception{Unauthorized: true, Message: "You have to login first!"})
|
| 33 |
+
c.Abort()
|
| 34 |
+
return
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
}
|
middleware/middleware.go
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package middleware
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"math"
|
| 5 |
+
"time"
|
| 6 |
+
|
| 7 |
+
"gorm.io/gorm"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
func RecordCheck(rows *gorm.DB) (string, error) {
|
| 11 |
+
count := rows.RowsAffected
|
| 12 |
+
err := rows.Error
|
| 13 |
+
// fmt.Println(rows)
|
| 14 |
+
// fmt.Println(count)
|
| 15 |
+
if count == 0 {
|
| 16 |
+
return "no-record", err
|
| 17 |
+
} else if err != nil {
|
| 18 |
+
return "query-error", err
|
| 19 |
+
} else {
|
| 20 |
+
return "ok", err
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
func DiffTime(t1 time.Time, t2 time.Time) (int, int, int) {
|
| 25 |
+
hs := t1.Sub(t2).Hours()
|
| 26 |
+
hs, mf := math.Modf(hs)
|
| 27 |
+
ms := mf * 60
|
| 28 |
+
ms, sf := math.Modf(ms)
|
| 29 |
+
ss := sf * 60
|
| 30 |
+
return int(hs), int(ms), int(ss)
|
| 31 |
+
}
|
middleware/response_middleware.go
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package middleware
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"net/http"
|
| 5 |
+
|
| 6 |
+
"github.com/gin-gonic/gin"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
// SendJSON200 sends a JSON response with HTTP status code 200
|
| 10 |
+
func SendJSON200(c *gin.Context, data interface{}) {
|
| 11 |
+
c.JSON(http.StatusOK, gin.H{"status": "success", "data": data})
|
| 12 |
+
return
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
// SendJSON400 sends a JSON response with HTTP status code 400
|
| 16 |
+
func SendJSON400(c *gin.Context, error_status *string, message *string) {
|
| 17 |
+
c.JSON(http.StatusBadRequest, gin.H{"status": "error", "error-status": error_status, "message": message})
|
| 18 |
+
return
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
// SendJSON401 sends a JSON response with HTTP status code 401
|
| 22 |
+
func SendJSON401(c *gin.Context, error_status *string, message *string) {
|
| 23 |
+
c.JSON(http.StatusUnauthorized, gin.H{"status": "error", "error-status": error_status, "message": message})
|
| 24 |
+
return
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
// SendJSON403 sends a JSON response with HTTP status code 403
|
| 28 |
+
func SendJSON403(c *gin.Context, message *string) {
|
| 29 |
+
c.JSON(http.StatusForbidden, gin.H{"status": "error", "message": message})
|
| 30 |
+
return
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// SendJSON404 sends a JSON response with HTTP status code 404
|
| 34 |
+
func SendJSON404(c *gin.Context, message *string) {
|
| 35 |
+
c.JSON(http.StatusNotFound, gin.H{"status": "error", "message": message})
|
| 36 |
+
return
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// SendJSON500 sends a JSON response with HTTP status code 500
|
| 40 |
+
func SendJSON500(c *gin.Context, error_status *string, message *string) {
|
| 41 |
+
c.JSON(http.StatusInternalServerError, gin.H{"status": "error", "error-status": error_status, "message": message})
|
| 42 |
+
return
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
// JSONResponseMiddleware is a middleware that provides functions for sending JSON responses
|
models/authentication_payload_model.go
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package models
|
| 2 |
+
|
| 3 |
+
type AccountData struct {
|
| 4 |
+
UserID uint
|
| 5 |
+
VerifyStatus string
|
| 6 |
+
ErrVerif error
|
| 7 |
+
}
|
models/custom_claim.go
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package models
|
| 2 |
+
|
| 3 |
+
import "github.com/golang-jwt/jwt/v5"
|
| 4 |
+
|
| 5 |
+
type CustomClaims struct {
|
| 6 |
+
jwt.RegisteredClaims
|
| 7 |
+
UserID uint `json:"id"`
|
| 8 |
+
}
|
models/database_orm_model.go
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package models
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"time"
|
| 5 |
+
|
| 6 |
+
uuid "github.com/satori/go.uuid"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
type Account struct {
|
| 10 |
+
Id uint `gorm:"primaryKey" json:"id"`
|
| 11 |
+
UUID uuid.UUID `gorm:"type:uuid" json:"uuid" `
|
| 12 |
+
Email string `gorm:"uniqueIndex" json:"email"`
|
| 13 |
+
Password string `json:"password"`
|
| 14 |
+
IsEmailVerified bool `json:"is_email_verified"`
|
| 15 |
+
IsDetailCompleted bool `json:"is_detail_completed"`
|
| 16 |
+
CreatedAt time.Time `json:"created_at"`
|
| 17 |
+
DeletedAt *time.Time `json:"deleted_at" gorm:"default:null"`
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
type AccountDetails struct {
|
| 21 |
+
ID uint `gorm:"primaryKey" json:"id"`
|
| 22 |
+
AccountId uint `json:"account_id"`
|
| 23 |
+
InitialName string `json:"initial_name"`
|
| 24 |
+
FullName *string `json:"full_name"`
|
| 25 |
+
University *string `json:"university"`
|
| 26 |
+
PhoneNumber *string `json:"phone_number"`
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// Gorm table name settings
|
| 30 |
+
func (Account) TableName() string { return "account" }
|
| 31 |
+
func (AccountDetails) TableName() string { return "account_details" }
|
models/exception_model.go
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package models
|
| 2 |
+
|
| 3 |
+
type Exception struct {
|
| 4 |
+
Unauthorized bool `json:"unauthorized,omitempty"`
|
| 5 |
+
BadRequest bool `json:"bad_request,omitempty"`
|
| 6 |
+
DataNotFound bool `json:"data_not_found,omitempty"`
|
| 7 |
+
InternalServerError bool `json:"internal_server_error,omitempty"`
|
| 8 |
+
DataDuplicate bool `json:"data_duplicate,omitempty"`
|
| 9 |
+
QueryError bool `json:"query_error,omitempty"`
|
| 10 |
+
InvalidPasswordLength bool `json:"invalid_password_length,omitempty"`
|
| 11 |
+
Message string `json:"message,omitempty"`
|
| 12 |
+
}
|
models/model.go
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
package models
|
models/request_model.go
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package models
|
| 2 |
+
|
| 3 |
+
type LoginRequest struct {
|
| 4 |
+
Email string `json:"email" binding:"required"`
|
| 5 |
+
Password string `json:"password" binding:"required"`
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
type RegisterRequest struct {
|
| 9 |
+
Name string `json:"name"`
|
| 10 |
+
Email string `json:"email" binding:"required,email"`
|
| 11 |
+
Phone int `json:"phone"`
|
| 12 |
+
Password string `json:"password" binding:"required"`
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
type ChangePasswordRequest struct {
|
| 16 |
+
OldPassword string `json:"old_password" binding:"required" `
|
| 17 |
+
NewPassword string `json:"new_password" binding:"required" `
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
type CreateVerifyEmailRequest struct {
|
| 21 |
+
Token uint `json:"token" binding:"required"`
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
type OptionsRequest struct {
|
| 25 |
+
OptionName string `json:"option_name" binding:"required"`
|
| 26 |
+
OptionValue []string `json:"option_values" binding:"required"`
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
type ExternalAuthRequest struct {
|
| 30 |
+
OauthID string `json:"oauth_id" binding:"required"`
|
| 31 |
+
OauthProvider string `json:"oauth_provider" binding:"required"`
|
| 32 |
+
IsAgreeTerms bool `json:"is_agree_terms"`
|
| 33 |
+
IsSexualDisease bool `json:"is_sexual_disease"`
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
type ForgotPasswordRequest struct {
|
| 37 |
+
Email string `json:"email" binding:"required,email"`
|
| 38 |
+
}
|
| 39 |
+
type ValidateForgotPasswordRequest struct {
|
| 40 |
+
Token uint `json:"token" binding:"required"`
|
| 41 |
+
NewPassword string `json:"new_password"`
|
| 42 |
+
}
|
models/response_model.go
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package models
|
| 2 |
+
|
| 3 |
+
type SuccessResponse struct {
|
| 4 |
+
Status string `json:"status"`
|
| 5 |
+
Message string `json:"message"`
|
| 6 |
+
Data any `json:"data"`
|
| 7 |
+
MetaData any `json:"meta_data"`
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
type ErrorResponse struct {
|
| 11 |
+
Status string `json:"status"`
|
| 12 |
+
Message string `json:"message"`
|
| 13 |
+
Errors Exception `json:"errors"`
|
| 14 |
+
MetaData any `json:"meta_data"`
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
type AuthenticatedUser struct {
|
| 18 |
+
Account Account `json:"account"`
|
| 19 |
+
Token string `json:"token"`
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
type UserProfileResponse struct {
|
| 23 |
+
Account Account `json:"account"`
|
| 24 |
+
Details AccountDetails `json:"details"`
|
| 25 |
+
}
|
repositories/account_repository.go
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package repositories
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"pweb-api.abdanhafidz.com/models"
|
| 5 |
+
)
|
| 6 |
+
|
| 7 |
+
func GetAccountbyEmail(email string) Repository[models.Account, models.Account] {
|
| 8 |
+
repo := Construct[models.Account, models.Account](
|
| 9 |
+
models.Account{Email: email},
|
| 10 |
+
)
|
| 11 |
+
repo.Transactions(
|
| 12 |
+
WhereGivenConstructor[models.Account, models.Account],
|
| 13 |
+
Find[models.Account, models.Account],
|
| 14 |
+
)
|
| 15 |
+
return *repo
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
func GetAllAccount() Repository[models.Account, []models.Account] {
|
| 19 |
+
repo := Construct[models.Account, []models.Account](
|
| 20 |
+
models.Account{},
|
| 21 |
+
)
|
| 22 |
+
repo.Transactions(
|
| 23 |
+
Find[models.Account, []models.Account],
|
| 24 |
+
)
|
| 25 |
+
return *repo
|
| 26 |
+
}
|
| 27 |
+
func GetAccountById(AccountId uint) Repository[models.Account, models.Account] {
|
| 28 |
+
repo := Construct[models.Account, models.Account](
|
| 29 |
+
models.Account{Id: AccountId},
|
| 30 |
+
)
|
| 31 |
+
repo.Transactions(
|
| 32 |
+
WhereGivenConstructor[models.Account, models.Account],
|
| 33 |
+
Find[models.Account, models.Account],
|
| 34 |
+
)
|
| 35 |
+
return *repo
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
func UpdateAccount(account models.Account) Repository[models.Account, models.Account] {
|
| 39 |
+
repo := Construct[models.Account, models.Account](
|
| 40 |
+
account,
|
| 41 |
+
)
|
| 42 |
+
repo.Transaction.Save(&repo.Constructor)
|
| 43 |
+
repo.Result = repo.Constructor
|
| 44 |
+
return *repo
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
func GetDetailAccountById(AccountId uint) Repository[models.AccountDetails, models.AccountDetails] {
|
| 48 |
+
repo := Construct[models.AccountDetails, models.AccountDetails](
|
| 49 |
+
models.AccountDetails{AccountId: AccountId},
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
// fmt.Println("Account ID:", repo.Constructor.AccountId)
|
| 53 |
+
repo.Transactions(
|
| 54 |
+
WhereGivenConstructor[models.AccountDetails, models.AccountDetails],
|
| 55 |
+
Find[models.AccountDetails, models.AccountDetails],
|
| 56 |
+
)
|
| 57 |
+
return *repo
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
func CreateAccount(account models.Account) Repository[models.Account, models.Account] {
|
| 61 |
+
repo := Construct[models.Account, models.Account](
|
| 62 |
+
account,
|
| 63 |
+
)
|
| 64 |
+
Create(repo)
|
| 65 |
+
return *repo
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
func CreateAccountDetails(accountDetails models.AccountDetails) Repository[models.AccountDetails, models.AccountDetails] {
|
| 69 |
+
repo := Construct[models.AccountDetails, models.AccountDetails](
|
| 70 |
+
accountDetails,
|
| 71 |
+
)
|
| 72 |
+
Create(repo)
|
| 73 |
+
return *repo
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
func UpdateAccountDetails(accountDetails models.AccountDetails) Repository[models.AccountDetails, models.AccountDetails] {
|
| 77 |
+
repo := Construct[models.AccountDetails, models.AccountDetails](
|
| 78 |
+
models.AccountDetails{AccountId: accountDetails.AccountId},
|
| 79 |
+
)
|
| 80 |
+
repo.Transaction.Where("account_id = ?", accountDetails.AccountId).First(&repo.Constructor)
|
| 81 |
+
accountDetails.ID = repo.Constructor.ID
|
| 82 |
+
// fmt.Println(repo.Constructor)
|
| 83 |
+
// fmt.Println(accountDetails)
|
| 84 |
+
repo.Transaction.Updates(accountDetails)
|
| 85 |
+
repo.Result = accountDetails
|
| 86 |
+
return *repo
|
| 87 |
+
}
|
repositories/repository.go
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package repositories
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"gorm.io/gorm"
|
| 5 |
+
"pweb-api.abdanhafidz.com/config"
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
type Repositories interface {
|
| 9 |
+
FindAllPaginate()
|
| 10 |
+
Where()
|
| 11 |
+
Find()
|
| 12 |
+
Create()
|
| 13 |
+
Update()
|
| 14 |
+
CustomQuery()
|
| 15 |
+
Delete()
|
| 16 |
+
}
|
| 17 |
+
type PaginationConstructor struct {
|
| 18 |
+
Limit int
|
| 19 |
+
Offset int
|
| 20 |
+
Filter string
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
type CustomQueryConstructor struct {
|
| 24 |
+
SQL string
|
| 25 |
+
Values interface{}
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
type Repository[TConstructor any, TResult any] struct {
|
| 29 |
+
Constructor TConstructor
|
| 30 |
+
Pagination PaginationConstructor
|
| 31 |
+
CustomQuery CustomQueryConstructor
|
| 32 |
+
Result TResult
|
| 33 |
+
Transaction *gorm.DB
|
| 34 |
+
RowsCount int
|
| 35 |
+
NoRecord bool
|
| 36 |
+
RowsError error
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repository[TConstructor, TResult] {
|
| 40 |
+
if len(constructor) == 1 {
|
| 41 |
+
return &Repository[TConstructor, TResult]{
|
| 42 |
+
Constructor: constructor[0],
|
| 43 |
+
Transaction: config.DB,
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
return &Repository[TConstructor, TResult]{
|
| 47 |
+
Constructor: constructor[0],
|
| 48 |
+
Transaction: config.DB.Begin(),
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) {
|
| 53 |
+
for _, tx := range transactions {
|
| 54 |
+
repo.Transaction = tx(repo)
|
| 55 |
+
if repo.RowsError != nil {
|
| 56 |
+
return
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 62 |
+
tx := repo.Transaction.Where(&repo.Constructor)
|
| 63 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 64 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 65 |
+
repo.RowsError = tx.Error
|
| 66 |
+
return tx
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
func Find[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 70 |
+
tx := repo.Transaction.Find(&repo.Result)
|
| 71 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 72 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 73 |
+
repo.RowsError = tx.Error
|
| 74 |
+
return tx
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 78 |
+
tx := repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result)
|
| 79 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 80 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 81 |
+
repo.RowsError = tx.Error
|
| 82 |
+
return tx
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
func Create[T1 any](repo *Repository[T1, T1]) *gorm.DB {
|
| 86 |
+
tx := repo.Transaction.Create(&repo.Constructor)
|
| 87 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 88 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 89 |
+
repo.RowsError = tx.Error
|
| 90 |
+
repo.Result = repo.Constructor
|
| 91 |
+
return tx
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
func Update[T1 any](repo *Repository[T1, T1]) *gorm.DB {
|
| 95 |
+
tx := repo.Transaction.Updates(&repo.Constructor)
|
| 96 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 97 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 98 |
+
repo.RowsError = tx.Error
|
| 99 |
+
repo.Result = repo.Constructor
|
| 100 |
+
return tx
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
func Delete[T1 any](repo *Repository[T1, T1]) *gorm.DB {
|
| 104 |
+
tx := repo.Transaction.Delete(&repo.Constructor)
|
| 105 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 106 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 107 |
+
repo.RowsError = tx.Error
|
| 108 |
+
return tx
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 112 |
+
tx := repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result)
|
| 113 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 114 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 115 |
+
repo.RowsError = tx.Error
|
| 116 |
+
return tx
|
| 117 |
+
}
|
router/auth_route.go
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package router
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/gin-gonic/gin"
|
| 5 |
+
AuthController "pweb-api.abdanhafidz.com/controller/auth"
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
func AuthRoute(router *gin.Engine) {
|
| 9 |
+
routerGroup := router.Group("/api/v1/auth")
|
| 10 |
+
{
|
| 11 |
+
routerGroup.POST("/login", AuthController.Login)
|
| 12 |
+
routerGroup.POST("/register", AuthController.Register)
|
| 13 |
+
|
| 14 |
+
}
|
| 15 |
+
}
|
router/router.go
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package router
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"log"
|
| 5 |
+
|
| 6 |
+
"github.com/gin-gonic/gin"
|
| 7 |
+
"pweb-api.abdanhafidz.com/config"
|
| 8 |
+
"pweb-api.abdanhafidz.com/controller"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
func StartService() {
|
| 12 |
+
router := gin.Default()
|
| 13 |
+
router.GET("/", controller.HomeController)
|
| 14 |
+
|
| 15 |
+
AuthRoute(router)
|
| 16 |
+
UserRoute(router)
|
| 17 |
+
err := router.Run(config.TCP_ADDRESS)
|
| 18 |
+
if err != nil {
|
| 19 |
+
log.Fatalf("Failed to run server: %v", err)
|
| 20 |
+
}
|
| 21 |
+
}
|
router/user_route.go
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package router
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/gin-gonic/gin"
|
| 5 |
+
UserController "pweb-api.abdanhafidz.com/controller/user"
|
| 6 |
+
"pweb-api.abdanhafidz.com/middleware"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
func UserRoute(router *gin.Engine) {
|
| 10 |
+
routerGroup := router.Group("/api/v1/user")
|
| 11 |
+
{
|
| 12 |
+
routerGroup.GET("/me", middleware.AuthUser, UserController.Profile)
|
| 13 |
+
routerGroup.PUT("/me", middleware.AuthUser, UserController.UpdateProfile)
|
| 14 |
+
}
|
| 15 |
+
}
|
services/authentication_service.go
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package services
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"errors"
|
| 5 |
+
|
| 6 |
+
"pweb-api.abdanhafidz.com/models"
|
| 7 |
+
"pweb-api.abdanhafidz.com/repositories"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
type AuthenticationService struct {
|
| 11 |
+
Service[models.Account, models.AuthenticatedUser]
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
func (s *AuthenticationService) Authenticate() {
|
| 15 |
+
accountData := repositories.GetAccountbyEmail(s.Constructor.Email)
|
| 16 |
+
if accountData.NoRecord {
|
| 17 |
+
s.Exception.DataNotFound = true
|
| 18 |
+
s.Exception.Message = "there is no account with given credentials!"
|
| 19 |
+
return
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
if VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil {
|
| 23 |
+
s.Exception.Unauthorized = true
|
| 24 |
+
s.Exception.Message = "incorrect password!"
|
| 25 |
+
return
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
token, err_tok := GenerateToken(&accountData.Result)
|
| 29 |
+
|
| 30 |
+
if err_tok != nil {
|
| 31 |
+
s.Error = errors.Join(s.Error, err_tok)
|
| 32 |
+
return
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
accountData.Result.Password = "SECRET"
|
| 36 |
+
s.Result = models.AuthenticatedUser{
|
| 37 |
+
Account: accountData.Result,
|
| 38 |
+
Token: token,
|
| 39 |
+
}
|
| 40 |
+
s.Error = accountData.RowsError
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
func (s *AuthenticationService) Update(oldPassword string, newPassword string) {
|
| 44 |
+
if len(newPassword) < 8 {
|
| 45 |
+
s.Exception.InvalidPasswordLength = true
|
| 46 |
+
s.Exception.Message = "Password must have at least 8 characters!"
|
| 47 |
+
return
|
| 48 |
+
}
|
| 49 |
+
accountData := repositories.GetAccountById(s.Constructor.Id)
|
| 50 |
+
|
| 51 |
+
if accountData.NoRecord {
|
| 52 |
+
s.Exception.DataNotFound = true
|
| 53 |
+
s.Exception.Message = "there is no account with given credentials!"
|
| 54 |
+
return
|
| 55 |
+
}
|
| 56 |
+
if VerifyPassword(accountData.Result.Password, oldPassword) != nil {
|
| 57 |
+
s.Exception.Unauthorized = true
|
| 58 |
+
s.Exception.Message = "incorrect old password!"
|
| 59 |
+
return
|
| 60 |
+
}
|
| 61 |
+
hashed_password, _ := HashPassword(newPassword)
|
| 62 |
+
accountData.Result.Password = hashed_password
|
| 63 |
+
changePassword := repositories.UpdateAccount(accountData.Result)
|
| 64 |
+
changePassword.Result.Password = "SECRET"
|
| 65 |
+
s.Result = models.AuthenticatedUser{
|
| 66 |
+
Account: changePassword.Result,
|
| 67 |
+
}
|
| 68 |
+
s.Error = changePassword.RowsError
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// LoginHandler handles user login
|
services/jwt_service.go
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package services
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"errors"
|
| 5 |
+
"strings"
|
| 6 |
+
"time"
|
| 7 |
+
|
| 8 |
+
"github.com/golang-jwt/jwt/v5"
|
| 9 |
+
"golang.org/x/crypto/bcrypt"
|
| 10 |
+
"pweb-api.abdanhafidz.com/config"
|
| 11 |
+
"pweb-api.abdanhafidz.com/models"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
var salt = config.Salt
|
| 15 |
+
var secretKey = []byte(salt)
|
| 16 |
+
|
| 17 |
+
func GenerateToken(user *models.Account) (string, error) {
|
| 18 |
+
claims := models.CustomClaims{
|
| 19 |
+
UserID: user.Id,
|
| 20 |
+
RegisteredClaims: jwt.RegisteredClaims{
|
| 21 |
+
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Hour * 24)), // Token berlaku 24 jam
|
| 22 |
+
IssuedAt: jwt.NewNumericDate(time.Now()),
|
| 23 |
+
Issuer: "apabdanhafidz.com",
|
| 24 |
+
},
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
// Buat token dengan metode signing
|
| 28 |
+
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
| 29 |
+
return token.SignedString(secretKey)
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
func ExtractBearerToken(authHeader string) (string, error) {
|
| 33 |
+
parts := strings.Split(authHeader, " ")
|
| 34 |
+
if len(parts) != 2 || parts[0] != "Bearer" {
|
| 35 |
+
return "", errors.New("invalid authorization header format")
|
| 36 |
+
}
|
| 37 |
+
return parts[1], nil
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
func VerifyToken(bearerToken string) (uint, string, error) {
|
| 41 |
+
// fmt.Println("bearerToken :", bearerToken)
|
| 42 |
+
|
| 43 |
+
tokenData, err := ExtractBearerToken(bearerToken)
|
| 44 |
+
if err != nil {
|
| 45 |
+
return 0, "invalid-token", err
|
| 46 |
+
} else {
|
| 47 |
+
// fmt.Println("Extracted Token:", tokenData)
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
token, err := jwt.ParseWithClaims(tokenData, &models.CustomClaims{}, func(token *jwt.Token) (interface{}, error) {
|
| 51 |
+
return secretKey, nil
|
| 52 |
+
})
|
| 53 |
+
|
| 54 |
+
if err != nil {
|
| 55 |
+
return 0, "invalid-token", err
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// Extract the claims
|
| 59 |
+
claims, ok := token.Claims.(*models.CustomClaims)
|
| 60 |
+
if !ok || !token.Valid {
|
| 61 |
+
return 0, "invalid-token", err
|
| 62 |
+
}
|
| 63 |
+
if claims.ExpiresAt != nil && claims.ExpiresAt.Time.Before(time.Now()) {
|
| 64 |
+
return 0, "expired", err
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
return claims.UserID, "valid", err
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
func VerifyPassword(hashedPassword, password string) error {
|
| 71 |
+
err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
|
| 72 |
+
if err != nil {
|
| 73 |
+
return errors.New("invalid password")
|
| 74 |
+
}
|
| 75 |
+
return nil
|
| 76 |
+
}
|
| 77 |
+
func HashPassword(password string) (string, error) {
|
| 78 |
+
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
|
| 79 |
+
return string(bytes), err
|
| 80 |
+
}
|
services/register_service.go
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package services
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"errors"
|
| 5 |
+
|
| 6 |
+
uuid "github.com/satori/go.uuid"
|
| 7 |
+
"gorm.io/gorm"
|
| 8 |
+
"pweb-api.abdanhafidz.com/models"
|
| 9 |
+
"pweb-api.abdanhafidz.com/repositories"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
type RegisterService struct {
|
| 13 |
+
Service[models.Account, models.Account]
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
func (s *RegisterService) Create() {
|
| 17 |
+
if len(s.Constructor.Password) < 8 {
|
| 18 |
+
s.Exception.InvalidPasswordLength = true
|
| 19 |
+
s.Exception.Message = "Password must have at least 8 characters!"
|
| 20 |
+
return
|
| 21 |
+
}
|
| 22 |
+
hashed_password, err_hash := HashPassword(s.Constructor.Password)
|
| 23 |
+
s.Error = err_hash
|
| 24 |
+
s.Constructor.Password = hashed_password
|
| 25 |
+
s.Constructor.UUID = uuid.NewV4()
|
| 26 |
+
accountCreated := repositories.CreateAccount(s.Constructor)
|
| 27 |
+
if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
|
| 28 |
+
s.Exception.DataDuplicate = true
|
| 29 |
+
s.Exception.Message = "Account with email " + s.Constructor.Email + " already exists!"
|
| 30 |
+
return
|
| 31 |
+
} else if errors.Is(accountCreated.RowsError, gorm.ErrModelAccessibleFieldsRequired) || errors.Is(accountCreated.RowsError, gorm.ErrInvalidData) || errors.Is(accountCreated.RowsError, gorm.ErrInvalidValue) || errors.Is(accountCreated.RowsError, gorm.ErrInvalidField) {
|
| 32 |
+
s.Exception.BadRequest = true
|
| 33 |
+
s.Exception.Message = "Bad request!"
|
| 34 |
+
return
|
| 35 |
+
}
|
| 36 |
+
userProfile := UserProfileService{}
|
| 37 |
+
userProfile.Constructor.AccountId = accountCreated.Result.Id
|
| 38 |
+
userProfile.Create()
|
| 39 |
+
if userProfile.Error != nil {
|
| 40 |
+
s.Error = userProfile.Error
|
| 41 |
+
return
|
| 42 |
+
}
|
| 43 |
+
s.Error = accountCreated.RowsError
|
| 44 |
+
s.Result = accountCreated.Result
|
| 45 |
+
s.Result.Password = "SECRET"
|
| 46 |
+
}
|
services/service.go
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package services
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"time"
|
| 5 |
+
|
| 6 |
+
"pweb-api.abdanhafidz.com/models"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
type (
|
| 10 |
+
Services interface {
|
| 11 |
+
Retrieve()
|
| 12 |
+
Update()
|
| 13 |
+
Create()
|
| 14 |
+
Delete()
|
| 15 |
+
Validate()
|
| 16 |
+
Authenticate()
|
| 17 |
+
Authorize()
|
| 18 |
+
}
|
| 19 |
+
IService interface {
|
| 20 |
+
Implements()
|
| 21 |
+
}
|
| 22 |
+
Service[TConstructor any, TResult any] struct {
|
| 23 |
+
Constructor TConstructor
|
| 24 |
+
Result TResult
|
| 25 |
+
Exception models.Exception
|
| 26 |
+
Error error
|
| 27 |
+
}
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Service[TConstructor, TResult] {
|
| 31 |
+
if len(constructor) == 1 {
|
| 32 |
+
return &Service[TConstructor, TResult]{}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
return &Service[TConstructor, TResult]{
|
| 36 |
+
Constructor: constructor[0],
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
func CalculateDueTime(duration time.Duration) time.Time {
|
| 41 |
+
return time.Now().Add(duration)
|
| 42 |
+
}
|
services/user_profile_service.go
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package services
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"regexp"
|
| 5 |
+
"strings"
|
| 6 |
+
|
| 7 |
+
"pweb-api.abdanhafidz.com/models"
|
| 8 |
+
"pweb-api.abdanhafidz.com/repositories"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
type UserProfileService struct {
|
| 12 |
+
Service[models.AccountDetails, models.UserProfileResponse]
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
// SanitizePhoneNumber membersihkan dan menormalkan nomor telepon ke format +62
|
| 16 |
+
func SanitizePhoneNumber(input string) string {
|
| 17 |
+
// Hilangkan semua spasi dan strip
|
| 18 |
+
input = strings.ReplaceAll(input, " ", "")
|
| 19 |
+
input = strings.ReplaceAll(input, "-", "")
|
| 20 |
+
input = strings.ReplaceAll(input, "(", "")
|
| 21 |
+
input = strings.ReplaceAll(input, ")", "")
|
| 22 |
+
|
| 23 |
+
// Hilangkan semua karakter non-digit kecuali +
|
| 24 |
+
re := regexp.MustCompile(`[^0-9\+]`)
|
| 25 |
+
input = re.ReplaceAllString(input, "")
|
| 26 |
+
|
| 27 |
+
// Handle nomor diawali 0 (contoh: 0812...) menjadi +62812...
|
| 28 |
+
if strings.HasPrefix(input, "0") {
|
| 29 |
+
input = "+62" + input[1:]
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
// Handle jika diawali dengan 62 tanpa + (contoh: 62812...)
|
| 33 |
+
if strings.HasPrefix(input, "62") && !strings.HasPrefix(input, "+62") {
|
| 34 |
+
input = "+" + input
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
// Handle jika tidak ada awalan +62 sama sekali (contoh: 8123456789)
|
| 38 |
+
if !strings.HasPrefix(input, "+62") {
|
| 39 |
+
if strings.HasPrefix(input, "8") {
|
| 40 |
+
input = "+62" + input
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
return input
|
| 45 |
+
}
|
| 46 |
+
func (s *UserProfileService) Create() {
|
| 47 |
+
userProfile := repositories.CreateAccountDetails(s.Constructor)
|
| 48 |
+
s.Error = userProfile.RowsError
|
| 49 |
+
if userProfile.NoRecord {
|
| 50 |
+
s.Exception.DataNotFound = true
|
| 51 |
+
s.Exception.Message = "There is no account with given credentials!"
|
| 52 |
+
return
|
| 53 |
+
}
|
| 54 |
+
s.Result = models.UserProfileResponse{
|
| 55 |
+
Account: repositories.GetAccountById(s.Constructor.AccountId).Result,
|
| 56 |
+
Details: userProfile.Result,
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
func (s *UserProfileService) Retrieve() {
|
| 60 |
+
userProfile := repositories.GetDetailAccountById(s.Constructor.AccountId)
|
| 61 |
+
s.Error = userProfile.RowsError
|
| 62 |
+
if userProfile.NoRecord {
|
| 63 |
+
s.Exception.DataNotFound = true
|
| 64 |
+
s.Exception.Message = "There is no account with given credentials!"
|
| 65 |
+
return
|
| 66 |
+
}
|
| 67 |
+
s.Result = models.UserProfileResponse{
|
| 68 |
+
Account: repositories.GetAccountById(s.Constructor.AccountId).Result,
|
| 69 |
+
Details: userProfile.Result,
|
| 70 |
+
}
|
| 71 |
+
s.Result.Account.Password = "SECRET"
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
func (s *UserProfileService) Update() {
|
| 75 |
+
if s.Constructor.PhoneNumber != nil {
|
| 76 |
+
phoneNumber := *s.Constructor.PhoneNumber
|
| 77 |
+
*s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber)
|
| 78 |
+
}
|
| 79 |
+
userProfile := repositories.UpdateAccountDetails(s.Constructor)
|
| 80 |
+
s.Error = userProfile.RowsError
|
| 81 |
+
if userProfile.NoRecord {
|
| 82 |
+
s.Exception.DataNotFound = true
|
| 83 |
+
s.Exception.Message = "There is no account with given credentials!"
|
| 84 |
+
return
|
| 85 |
+
}
|
| 86 |
+
account := repositories.GetAccountById(s.Constructor.AccountId)
|
| 87 |
+
account.Result.IsDetailCompleted = (userProfile.Result.InitialName != "" &&
|
| 88 |
+
userProfile.Result.FullName != nil &&
|
| 89 |
+
userProfile.Result.PhoneNumber != nil &&
|
| 90 |
+
userProfile.Result.University != nil)
|
| 91 |
+
repositories.UpdateAccount(account.Result)
|
| 92 |
+
s.Result = models.UserProfileResponse{
|
| 93 |
+
Account: account.Result,
|
| 94 |
+
Details: userProfile.Result,
|
| 95 |
+
}
|
| 96 |
+
s.Result.Account.Password = "SECRET"
|
| 97 |
+
}
|
utils/Logger.go
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package utils
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"log"
|
| 5 |
+
"os"
|
| 6 |
+
|
| 7 |
+
"pweb-api.abdanhafidz.com/config"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
func LogError(errorLogged error) {
|
| 11 |
+
log.Println("Error Log :", errorLogged)
|
| 12 |
+
|
| 13 |
+
_, err := os.Stat(config.LOG_PATH + "/error_log.txt")
|
| 14 |
+
if os.IsNotExist(err) {
|
| 15 |
+
_, err = os.Create(config.LOG_PATH + "/error_log.txt")
|
| 16 |
+
if err != nil {
|
| 17 |
+
log.Fatalf("Gagal buka file log: %v", err)
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
file, err := os.OpenFile(config.LOG_PATH+"/error_log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
|
| 22 |
+
|
| 23 |
+
if err != nil {
|
| 24 |
+
log.Fatalf("Gagal buka file log: %v", err)
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
log.SetOutput(file)
|
| 28 |
+
}
|
utils/api_response.go
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package utils
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"net/http"
|
| 5 |
+
"reflect"
|
| 6 |
+
|
| 7 |
+
"pweb-api.abdanhafidz.com/models"
|
| 8 |
+
"pweb-api.abdanhafidz.com/services"
|
| 9 |
+
|
| 10 |
+
"github.com/gin-gonic/gin"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
func ResponseOK(c *gin.Context, data any) {
|
| 14 |
+
res := models.SuccessResponse{
|
| 15 |
+
Status: "success",
|
| 16 |
+
Message: "Data retrieved successfully!",
|
| 17 |
+
Data: data,
|
| 18 |
+
MetaData: c.Request.Body,
|
| 19 |
+
}
|
| 20 |
+
c.JSON(http.StatusOK, res)
|
| 21 |
+
return
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
func ResponseFAIL(c *gin.Context, status int, exception models.Exception) {
|
| 25 |
+
message := exception.Message
|
| 26 |
+
exception.Message = ""
|
| 27 |
+
res := models.ErrorResponse{
|
| 28 |
+
Status: "error",
|
| 29 |
+
Message: message,
|
| 30 |
+
Errors: exception,
|
| 31 |
+
MetaData: c.Request.Body,
|
| 32 |
+
}
|
| 33 |
+
c.AbortWithStatusJSON(status, res)
|
| 34 |
+
return
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
func SendResponse(c *gin.Context, data services.Service[any, any]) {
|
| 38 |
+
if reflect.ValueOf(data.Exception).IsNil() {
|
| 39 |
+
ResponseOK(c, data)
|
| 40 |
+
} else {
|
| 41 |
+
if data.Exception.Unauthorized {
|
| 42 |
+
ResponseFAIL(c, 401, data.Exception)
|
| 43 |
+
} else if data.Exception.BadRequest {
|
| 44 |
+
ResponseFAIL(c, 400, data.Exception)
|
| 45 |
+
} else if data.Exception.DataNotFound {
|
| 46 |
+
ResponseFAIL(c, 404, data.Exception)
|
| 47 |
+
} else if data.Exception.InternalServerError {
|
| 48 |
+
ResponseFAIL(c, 500, data.Exception)
|
| 49 |
+
} else {
|
| 50 |
+
ResponseFAIL(c, 403, data.Exception)
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
}
|
utils/helper.go
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package utils
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/gin-gonic/gin"
|
| 5 |
+
"pweb-api.abdanhafidz.com/models"
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
func GetAccount(c *gin.Context) models.AccountData {
|
| 9 |
+
cParam, _ := c.Get("accountData")
|
| 10 |
+
return cParam.(models.AccountData)
|
| 11 |
+
}
|
utils/util.go
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package utils
|
| 2 |
+
|
| 3 |
+
func ternaryMessage(condition bool, valueIfTrue string, valueIfFalse string) string {
|
| 4 |
+
if condition {
|
| 5 |
+
return valueIfTrue
|
| 6 |
+
} else {
|
| 7 |
+
return valueIfFalse
|
| 8 |
+
}
|
| 9 |
+
}
|
views/index.html
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Welcome to Abdan Hafidz Portal</title>
|
| 7 |
+
<link rel="stylesheet" href="style/styles.css">
|
| 8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
|
| 9 |
+
<script src="scripts/scripts.js"></script>
|
| 10 |
+
</head>
|
| 11 |
+
<body>
|
| 12 |
+
<!-- Loading Indicator -->
|
| 13 |
+
<div class="loading" id="loadingIndicator" style="display: none;">
|
| 14 |
+
<div class="loading-spinner"></div>
|
| 15 |
+
</div>
|
| 16 |
+
|
| 17 |
+
<!-- Header -->
|
| 18 |
+
<header>
|
| 19 |
+
<div class="container">
|
| 20 |
+
<nav>
|
| 21 |
+
<div class="logo">Abdan Hafidz Portal</div>
|
| 22 |
+
<div class="nav-links" id="navLinks">
|
| 23 |
+
<!-- Links will be dynamically added based on auth state -->
|
| 24 |
+
</div>
|
| 25 |
+
</nav>
|
| 26 |
+
</div>
|
| 27 |
+
</header>
|
| 28 |
+
|
| 29 |
+
<!-- Welcome Section -->
|
| 30 |
+
<section class="auth-section">
|
| 31 |
+
<div class="container">
|
| 32 |
+
<div class="auth-container">
|
| 33 |
+
<h2 class="auth-title">Welcome to Abdan Hafidz Portal</h2>
|
| 34 |
+
<p style="text-align: center; margin-bottom: 2rem;">
|
| 35 |
+
Your personal dashboard for managing your profile and settings.
|
| 36 |
+
</p>
|
| 37 |
+
<div style="display: flex; justify-content: center; gap: 1rem;">
|
| 38 |
+
<a href="login.html" class="btn">Login</a>
|
| 39 |
+
<a href="register.html" class="btn btn-outline">Register</a>
|
| 40 |
+
</div>
|
| 41 |
+
</div>
|
| 42 |
+
</div>
|
| 43 |
+
</section>
|
| 44 |
+
|
| 45 |
+
<!-- Footer -->
|
| 46 |
+
<footer>
|
| 47 |
+
<div class="container">
|
| 48 |
+
<p>© 2025 Abdan Hafidz Portal. All rights reserved.</p>
|
| 49 |
+
</div>
|
| 50 |
+
</footer>
|
| 51 |
+
|
| 52 |
+
<script>
|
| 53 |
+
$(document).ready(function() {
|
| 54 |
+
// Check if user is already logged in
|
| 55 |
+
if (isLoggedIn()) {
|
| 56 |
+
window.location.href = 'profile.html';
|
| 57 |
+
}
|
| 58 |
+
});
|
| 59 |
+
</script>
|
| 60 |
+
</body>
|
| 61 |
+
</html>
|
views/login.html
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Login - Abdan Hafidz Portal</title>
|
| 7 |
+
<link rel="stylesheet" href="style/styles.css">
|
| 8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
|
| 9 |
+
<script src="scripts/scripts.js"></script>
|
| 10 |
+
</head>
|
| 11 |
+
<body>
|
| 12 |
+
<!-- Loading Indicator -->
|
| 13 |
+
<div class="loading" id="loadingIndicator" style="display: none;">
|
| 14 |
+
<div class="loading-spinner"></div>
|
| 15 |
+
</div>
|
| 16 |
+
|
| 17 |
+
<!-- Header -->
|
| 18 |
+
<header>
|
| 19 |
+
<div class="container">
|
| 20 |
+
<nav>
|
| 21 |
+
<div class="logo">Abdan Hafidz Portal</div>
|
| 22 |
+
<div class="nav-links" id="navLinks">
|
| 23 |
+
<!-- Links will be dynamically added based on auth state -->
|
| 24 |
+
</div>
|
| 25 |
+
</nav>
|
| 26 |
+
</div>
|
| 27 |
+
</header>
|
| 28 |
+
|
| 29 |
+
<!-- Login Page -->
|
| 30 |
+
<section class="auth-section">
|
| 31 |
+
<div class="container">
|
| 32 |
+
<div class="auth-container">
|
| 33 |
+
<h2 class="auth-title">Login to Your Account</h2>
|
| 34 |
+
<div id="loginAlert" style="display: none;"></div>
|
| 35 |
+
<form id="loginForm">
|
| 36 |
+
<div class="form-group">
|
| 37 |
+
<label for="loginEmail">Email Address</label>
|
| 38 |
+
<input type="email" class="form-control" id="loginEmail" placeholder="Enter your email" required>
|
| 39 |
+
</div>
|
| 40 |
+
<div class="form-group">
|
| 41 |
+
<label for="loginPassword">Password</label>
|
| 42 |
+
<input type="password" class="form-control" id="loginPassword" placeholder="Enter your password" required>
|
| 43 |
+
</div>
|
| 44 |
+
<button type="submit" class="btn" style="width: 100%;">Login</button>
|
| 45 |
+
<div class="form-footer">
|
| 46 |
+
<p>Don't have an account? <a href="register.html">Register Now</a></p>
|
| 47 |
+
</div>
|
| 48 |
+
</form>
|
| 49 |
+
</div>
|
| 50 |
+
</div>
|
| 51 |
+
</section>
|
| 52 |
+
|
| 53 |
+
<!-- Footer -->
|
| 54 |
+
<footer>
|
| 55 |
+
<div class="container">
|
| 56 |
+
<p>© 2025 Abdan Hafidz Portal. All rights reserved.</p>
|
| 57 |
+
</div>
|
| 58 |
+
</footer>
|
| 59 |
+
|
| 60 |
+
<script>
|
| 61 |
+
$(document).ready(function() {
|
| 62 |
+
// Check if user is already logged in
|
| 63 |
+
if (isLoggedIn()) {
|
| 64 |
+
window.location.href = 'profile.html';
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
// Login Form Submission
|
| 68 |
+
$('#loginForm').on('submit', function(e) {
|
| 69 |
+
e.preventDefault();
|
| 70 |
+
const email = $('#loginEmail').val();
|
| 71 |
+
const password = $('#loginPassword').val();
|
| 72 |
+
login(email, password);
|
| 73 |
+
});
|
| 74 |
+
});
|
| 75 |
+
</script>
|
| 76 |
+
</body>
|
| 77 |
+
</html>
|
views/profile.html
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>My Profile - Abdan Hafidz Portal</title>
|
| 7 |
+
<link rel="stylesheet" href="style/styles.css">
|
| 8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
|
| 9 |
+
<script src="scripts/scripts.js"></script>
|
| 10 |
+
</head>
|
| 11 |
+
<body>
|
| 12 |
+
<!-- Loading Indicator -->
|
| 13 |
+
<div class="loading" id="loadingIndicator" style="display: none;">
|
| 14 |
+
<div class="loading-spinner"></div>
|
| 15 |
+
</div>
|
| 16 |
+
|
| 17 |
+
<!-- Header -->
|
| 18 |
+
<header>
|
| 19 |
+
<div class="container">
|
| 20 |
+
<nav>
|
| 21 |
+
<div class="logo">Abdan Hafidz Portal</div>
|
| 22 |
+
<div class="nav-links" id="navLinks">
|
| 23 |
+
<!-- Links will be dynamically added based on auth state -->
|
| 24 |
+
</div>
|
| 25 |
+
</nav>
|
| 26 |
+
</div>
|
| 27 |
+
</header>
|
| 28 |
+
|
| 29 |
+
<!-- Profile Page -->
|
| 30 |
+
<section>
|
| 31 |
+
<div class="container">
|
| 32 |
+
<div class="profile-container">
|
| 33 |
+
<div class="profile-header">
|
| 34 |
+
<div class="profile-avatar" id="profileInitials">U</div>
|
| 35 |
+
<div class="profile-title">
|
| 36 |
+
<h1 id="profileName">User Profile</h1>
|
| 37 |
+
<p class="profile-email" id="profileEmail">email@example.com</p>
|
| 38 |
+
</div>
|
| 39 |
+
</div>
|
| 40 |
+
<div id="profileAlert" style="display: none;"></div>
|
| 41 |
+
<form id="profileForm">
|
| 42 |
+
<div class="profile-form">
|
| 43 |
+
<div class="form-group">
|
| 44 |
+
<label for="profileFullName">Full Name</label>
|
| 45 |
+
<input type="text" class="form-control" id="profileFullName" placeholder="Enter your full name">
|
| 46 |
+
</div>
|
| 47 |
+
<div class="form-group">
|
| 48 |
+
<label for="profileInitialName">Initial Name</label>
|
| 49 |
+
<input type="text" class="form-control" id="profileInitialName" placeholder="Enter your initials">
|
| 50 |
+
</div>
|
| 51 |
+
<div class="form-group">
|
| 52 |
+
<label for="profileUniversity">University</label>
|
| 53 |
+
<input type="text" class="form-control" id="profileUniversity" placeholder="Enter your university">
|
| 54 |
+
</div>
|
| 55 |
+
<div class="form-group">
|
| 56 |
+
<label for="profilePhone">Phone Number</label>
|
| 57 |
+
<input type="tel" class="form-control" id="profilePhone" placeholder="Enter your phone number">
|
| 58 |
+
</div>
|
| 59 |
+
</div>
|
| 60 |
+
<div class="profile-actions">
|
| 61 |
+
<button type="submit" class="btn">Save Changes</button>
|
| 62 |
+
<button type="button" class="btn btn-danger" id="logoutBtn">Logout</button>
|
| 63 |
+
</div>
|
| 64 |
+
</form>
|
| 65 |
+
</div>
|
| 66 |
+
</div>
|
| 67 |
+
</section>
|
| 68 |
+
|
| 69 |
+
<!-- Footer -->
|
| 70 |
+
<footer>
|
| 71 |
+
<div class="container">
|
| 72 |
+
<p>© 2025 Abdan Hafidz Portal. All rights reserved.</p>
|
| 73 |
+
</div>
|
| 74 |
+
</footer>
|
| 75 |
+
|
| 76 |
+
<script>
|
| 77 |
+
$(document).ready(function() {
|
| 78 |
+
// Check if user is logged in
|
| 79 |
+
if (!isLoggedIn()) {
|
| 80 |
+
window.location.href = 'login.html';
|
| 81 |
+
return;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
// Fetch user profile data
|
| 85 |
+
fetchUserProfile();
|
| 86 |
+
|
| 87 |
+
// Profile Form Submission
|
| 88 |
+
$('#profileForm').on('submit', function(e) {
|
| 89 |
+
e.preventDefault();
|
| 90 |
+
const profileData = {
|
| 91 |
+
fullName: $('#profileFullName').val(),
|
| 92 |
+
initialName: $('#profileInitialName').val(),
|
| 93 |
+
university: $('#profileUniversity').val(),
|
| 94 |
+
phoneNumber: $('#profilePhone').val()
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
updateUserProfile(profileData);
|
| 98 |
+
});
|
| 99 |
+
|
| 100 |
+
// Logout Button
|
| 101 |
+
$('#logoutBtn').on('click', function(e) {
|
| 102 |
+
e.preventDefault();
|
| 103 |
+
logout();
|
| 104 |
+
});
|
| 105 |
+
});
|
| 106 |
+
</script>
|
| 107 |
+
</body>
|
| 108 |
+
</html>
|
views/register.html
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Register - Abdan Hafidz Portal</title>
|
| 7 |
+
<link rel="stylesheet" href="style/styles.css">
|
| 8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
|
| 9 |
+
<script src="scripts/scripts.js"></script>
|
| 10 |
+
</head>
|
| 11 |
+
<body>
|
| 12 |
+
<!-- Loading Indicator -->
|
| 13 |
+
<div class="loading" id="loadingIndicator" style="display: none;">
|
| 14 |
+
<div class="loading-spinner"></div>
|
| 15 |
+
</div>
|
| 16 |
+
|
| 17 |
+
<!-- Header -->
|
| 18 |
+
<header>
|
| 19 |
+
<div class="container">
|
| 20 |
+
<nav>
|
| 21 |
+
<div class="logo">Abdan Hafidz Portal</div>
|
| 22 |
+
<div class="nav-links" id="navLinks">
|
| 23 |
+
<!-- Links will be dynamically added based on auth state -->
|
| 24 |
+
</div>
|
| 25 |
+
</nav>
|
| 26 |
+
</div>
|
| 27 |
+
</header>
|
| 28 |
+
|
| 29 |
+
<!-- Register Page -->
|
| 30 |
+
<section class="auth-section">
|
| 31 |
+
<div class="container">
|
| 32 |
+
<div class="auth-container">
|
| 33 |
+
<h2 class="auth-title">Create an Account</h2>
|
| 34 |
+
<div id="registerAlert" style="display: none;"></div>
|
| 35 |
+
<form id="registerForm">
|
| 36 |
+
<div class="form-group">
|
| 37 |
+
<label for="registerEmail">Email Address</label>
|
| 38 |
+
<input type="email" class="form-control" id="registerEmail" placeholder="Enter your email" required>
|
| 39 |
+
</div>
|
| 40 |
+
<div class="form-group">
|
| 41 |
+
<label for="registerPassword">Password</label>
|
| 42 |
+
<input type="password" class="form-control" id="registerPassword" placeholder="Create a password" required>
|
| 43 |
+
</div>
|
| 44 |
+
<div class="form-group">
|
| 45 |
+
<label for="confirmPassword">Confirm Password</label>
|
| 46 |
+
<input type="password" class="form-control" id="confirmPassword" placeholder="Confirm your password" required>
|
| 47 |
+
</div>
|
| 48 |
+
<button type="submit" class="btn" style="width: 100%;">Register</button>
|
| 49 |
+
<div class="form-footer">
|
| 50 |
+
<p>Already have an account? <a href="login.html">Login</a></p>
|
| 51 |
+
</div>
|
| 52 |
+
</form>
|
| 53 |
+
</div>
|
| 54 |
+
</div>
|
| 55 |
+
</section>
|
| 56 |
+
|
| 57 |
+
<!-- Footer -->
|
| 58 |
+
<footer>
|
| 59 |
+
<div class="container">
|
| 60 |
+
<p>© 2025 Abdan Hafidz Portal. All rights reserved.</p>
|
| 61 |
+
</div>
|
| 62 |
+
</footer>
|
| 63 |
+
|
| 64 |
+
<script>
|
| 65 |
+
$(document).ready(function() {
|
| 66 |
+
// Check if user is already logged in
|
| 67 |
+
if (isLoggedIn()) {
|
| 68 |
+
window.location.href = 'profile.html';
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// Register Form Submission
|
| 72 |
+
$('#registerForm').on('submit', function(e) {
|
| 73 |
+
e.preventDefault();
|
| 74 |
+
const email = $('#registerEmail').val();
|
| 75 |
+
const password = $('#registerPassword').val();
|
| 76 |
+
const confirmPassword = $('#confirmPassword').val();
|
| 77 |
+
|
| 78 |
+
if (password !== confirmPassword) {
|
| 79 |
+
showAlert('registerAlert', 'danger', 'Passwords do not match.');
|
| 80 |
+
return;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
register(email, password);
|
| 84 |
+
});
|
| 85 |
+
});
|
| 86 |
+
</script>
|
| 87 |
+
</body>
|
| 88 |
+
</html>
|
views/script.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
views/scripts/script.js
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Configuration
|
| 2 |
+
const API_BASE_URL = 'http://api-pweb.abdanhafidz.com';
|
| 3 |
+
const TOKEN_COOKIE_NAME = 'auth_token';
|
| 4 |
+
|
| 5 |
+
// Utility Functions
|
| 6 |
+
function setCookie(name, value, days) {
|
| 7 |
+
let expires = '';
|
| 8 |
+
if (days) {
|
| 9 |
+
const date = new Date();
|
| 10 |
+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
| 11 |
+
expires = '; expires=' + date.toUTCString();
|
| 12 |
+
}
|
| 13 |
+
document.cookie = name + '=' + (value || '') + expires + '; path=/';
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
function getCookie(name) {
|
| 17 |
+
const nameEQ = name + '=';
|
| 18 |
+
const ca = document.cookie.split(';');
|
| 19 |
+
for (let i = 0; i < ca.length; i++) {
|
| 20 |
+
let c = ca[i];
|
| 21 |
+
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
| 22 |
+
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
| 23 |
+
}
|
| 24 |
+
return null;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
function eraseCookie(name) {
|
| 28 |
+
document.cookie = name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function showLoading() {
|
| 32 |
+
$('#loadingIndicator').show();
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
function hideLoading() {
|
| 36 |
+
$('#loadingIndicator').hide();
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
function showAlert(elementId, type, message) {
|
| 40 |
+
const alertElement = $(`#${elementId}`);
|
| 41 |
+
alertElement.attr('class', `alert alert-${type}`);
|
| 42 |
+
alertElement.html(message);
|
| 43 |
+
alertElement.show();
|
| 44 |
+
|
| 45 |
+
// Auto hide after 5 seconds
|
| 46 |
+
setTimeout(() => {
|
| 47 |
+
alertElement.hide();
|
| 48 |
+
}, 5000);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
function isLoggedIn() {
|
| 52 |
+
return !!getCookie(TOKEN_COOKIE_NAME);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function updateNavLinks() {
|
| 56 |
+
const navLinks = $('#navLinks');
|
| 57 |
+
navLinks.empty();
|
| 58 |
+
|
| 59 |
+
if (isLoggedIn()) {
|
| 60 |
+
navLinks.append('<a href="profile.html" id="navProfile">Profile</a>');
|
| 61 |
+
navLinks.append('<a href="#" id="navLogout">Logout</a>');
|
| 62 |
+
} else {
|
| 63 |
+
navLinks.append('<a href="login.html" id="navLogin">Login</a>');
|
| 64 |
+
navLinks.append('<a href="register.html" id="navRegister">Register</a>');
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
// Attach event listeners to nav links
|
| 68 |
+
$('#navLogout').on('click', function(e) {
|
| 69 |
+
e.preventDefault();
|
| 70 |
+
logout();
|
| 71 |
+
});
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
function setAuthToken(token) {
|
| 75 |
+
setCookie(TOKEN_COOKIE_NAME, token, 7); // Store token for 7 days
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
function getAuthToken() {
|
| 79 |
+
return getCookie(TOKEN_COOKIE_NAME);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
function getAuthHeader() {
|
| 83 |
+
const token = getAuthToken();
|
| 84 |
+
return token ? { 'Authorization': `Bearer ${token}` } : {};
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
// Auth Functions
|
| 88 |
+
function login(email, password) {
|
| 89 |
+
showLoading();
|
| 90 |
+
|
| 91 |
+
$.ajax({
|
| 92 |
+
url: `${API_BASE_URL}/auth/login`,
|
| 93 |
+
type: 'POST',
|
| 94 |
+
contentType: 'application/json',
|
| 95 |
+
data: JSON.stringify({
|
| 96 |
+
email: email,
|
| 97 |
+
password: password
|
| 98 |
+
}),
|
| 99 |
+
success: function(response) {
|
| 100 |
+
if (response.status === 'success') {
|
| 101 |
+
setAuthToken(response.data.token);
|
| 102 |
+
showAlert('loginAlert', 'success', 'Login successful! Redirecting to your profile...');
|
| 103 |
+
setTimeout(() => {
|
| 104 |
+
window.location.href = 'profile.html';
|
| 105 |
+
}, 1000);
|
| 106 |
+
} else {
|
| 107 |
+
showAlert('loginAlert', 'danger', 'Login failed. Please check your credentials.');
|
| 108 |
+
}
|
| 109 |
+
},
|
| 110 |
+
error: function(xhr) {
|
| 111 |
+
const message = xhr.responseJSON ? xhr.responseJSON.message : 'An error occurred during login.';
|
| 112 |
+
showAlert('loginAlert', 'danger', message);
|
| 113 |
+
},
|
| 114 |
+
complete: function() {
|
| 115 |
+
hideLoading();
|
| 116 |
+
}
|
| 117 |
+
});
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
function register(email, password) {
|
| 121 |
+
showLoading();
|
| 122 |
+
|
| 123 |
+
$.ajax({
|
| 124 |
+
url: `${API_BASE_URL}/auth/register`,
|
| 125 |
+
type: 'POST',
|
| 126 |
+
contentType: 'application/json',
|
| 127 |
+
data: JSON.stringify({
|
| 128 |
+
email: email,
|
| 129 |
+
password: password
|
| 130 |
+
}),
|
| 131 |
+
success: function(response) {
|
| 132 |
+
if (response.status === 'success') {
|
| 133 |
+
showAlert('registerAlert', 'success', 'Registration successful! Redirecting to login page...');
|
| 134 |
+
setTimeout(() => {
|
| 135 |
+
window.location.href = 'login.html';
|
| 136 |
+
}, 2000);
|
| 137 |
+
} else {
|
| 138 |
+
showAlert('registerAlert', 'danger', 'Registration failed. Please try again.');
|
| 139 |
+
}
|
| 140 |
+
},
|
| 141 |
+
error: function(xhr) {
|
| 142 |
+
const message = xhr.responseJSON ? xhr.responseJSON.message : 'An error occurred during registration.';
|
| 143 |
+
showAlert('registerAlert', 'danger', message);
|
| 144 |
+
},
|
| 145 |
+
complete: function() {
|
| 146 |
+
hideLoading();
|
| 147 |
+
}
|
| 148 |
+
});
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
function logout() {
|
| 152 |
+
eraseCookie(TOKEN_COOKIE_NAME);
|
| 153 |
+
window.location.href = 'login.html';
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
function fetchUserProfile() {
|
| 157 |
+
showLoading();
|
| 158 |
+
|
| 159 |
+
$.ajax({
|
| 160 |
+
url: `${API_BASE_URL}/user/me`,
|
| 161 |
+
type: 'GET',
|
| 162 |
+
headers: getAuthHeader(),
|
| 163 |
+
success: function(response) {
|
| 164 |
+
if (response.status === 'success') {
|
| 165 |
+
const userData = response.data;
|
| 166 |
+
|
| 167 |
+
// Update profile email
|
| 168 |
+
$('#profileEmail').text(userData.account.email);
|
| 169 |
+
|
| 170 |
+
// Update form fields if details exist
|
| 171 |
+
if (userData.details) {
|
| 172 |
+
$('#profileFullName').val(userData.details.full_name || '');
|
| 173 |
+
$('#profileInitialName').val(userData.details.initial_name || '');
|
| 174 |
+
$('#profileUniversity').val(userData.details.university || '');
|
| 175 |
+
$('#profilePhone').val(userData.details.phone_number || '');
|
| 176 |
+
|
| 177 |
+
// Update profile name and initials
|
| 178 |
+
if (userData.details.full_name) {
|
| 179 |
+
$('#profileName').text(userData.details.full_name);
|
| 180 |
+
} else {
|
| 181 |
+
$('#profileName').text('User Profile');
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
if (userData.details.initial_name) {
|
| 185 |
+
$('#profileInitials').text(userData.details.initial_name.substring(0, 2).toUpperCase());
|
| 186 |
+
} else if (userData.details.full_name) {
|
| 187 |
+
const nameParts = userData.details.full_name.split(' ');
|
| 188 |
+
if (nameParts.length > 1) {
|
| 189 |
+
$('#profileInitials').text((nameParts[0][0] + nameParts[1][0]).toUpperCase());
|
| 190 |
+
} else {
|
| 191 |
+
$('#profileInitials').text(nameParts[0][0].toUpperCase());
|
| 192 |
+
}
|
| 193 |
+
} else {
|
| 194 |
+
$('#profileInitials').text(userData.account.email[0].toUpperCase());
|
| 195 |
+
}
|
| 196 |
+
} else {
|
| 197 |
+
$('#profileInitials').text(userData.account.email[0].toUpperCase());
|
| 198 |
+
}
|
| 199 |
+
} else {
|
| 200 |
+
showAlert('profileAlert', 'danger', 'Failed to load profile data.');
|
| 201 |
+
}
|
| 202 |
+
},
|
| 203 |
+
error: function(xhr) {
|
| 204 |
+
if (xhr.status === 401) {
|
| 205 |
+
eraseCookie(TOKEN_COOKIE_NAME);
|
| 206 |
+
window.location.href = 'login.html';
|
| 207 |
+
showAlert('loginAlert', 'danger', 'Session expired. Please login again.');
|
| 208 |
+
} else {
|
| 209 |
+
const message = xhr.responseJSON ? xhr.responseJSON.message : 'An error occurred while fetching profile data.';
|
| 210 |
+
showAlert('profileAlert', 'danger', message);
|
| 211 |
+
}
|
| 212 |
+
},
|
| 213 |
+
complete: function() {
|
| 214 |
+
hideLoading();
|
| 215 |
+
}
|
| 216 |
+
});
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
function updateUserProfile(profileData) {
|
| 220 |
+
showLoading();
|
| 221 |
+
|
| 222 |
+
$.ajax({
|
| 223 |
+
url: `${API_BASE_URL}/user/me`,
|
| 224 |
+
type: 'PUT',
|
| 225 |
+
headers: getAuthHeader(),
|
| 226 |
+
contentType: 'application/json',
|
| 227 |
+
data: JSON.stringify({
|
| 228 |
+
full_name: profileData.fullName,
|
| 229 |
+
initial_name: profileData.initialName,
|
| 230 |
+
university: profileData.university,
|
| 231 |
+
phone_number: profileData.phoneNumber
|
| 232 |
+
}),
|
| 233 |
+
success: function(response) {
|
| 234 |
+
if (response.status === 'success') {
|
| 235 |
+
showAlert('profileAlert', 'success', 'Profile updated successfully!');
|
| 236 |
+
fetchUserProfile(); // Refresh profile data
|
| 237 |
+
} else {
|
| 238 |
+
showAlert('profileAlert', 'danger', 'Failed to update profile data.');
|
| 239 |
+
}
|
| 240 |
+
},
|
| 241 |
+
error: function(xhr) {
|
| 242 |
+
if (xhr.status === 401) {
|
| 243 |
+
eraseCookie(TOKEN_COOKIE_NAME);
|
| 244 |
+
window.location.href = 'login.html';
|
| 245 |
+
showAlert('loginAlert', 'danger', 'Session expired. Please login again.');
|
| 246 |
+
} else {
|
| 247 |
+
const message = xhr.responseJSON ? xhr.responseJSON.message : 'An error occurred while updating profile data.';
|
| 248 |
+
showAlert('profileAlert', 'danger', message);
|
| 249 |
+
}
|
| 250 |
+
},
|
| 251 |
+
complete: function() {
|
| 252 |
+
hideLoading();
|
| 253 |
+
}
|
| 254 |
+
});
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
// Check Authentication State
|
| 258 |
+
$(document).ready(function() {
|
| 259 |
+
updateNavLinks();
|
| 260 |
+
|
| 261 |
+
// Handle logo click
|
| 262 |
+
$('.logo').on('click', function(e) {
|
| 263 |
+
e.preventDefault();
|
| 264 |
+
if (isLoggedIn()) {
|
| 265 |
+
window.location.href = 'profile.html';
|
| 266 |
+
} else {
|
| 267 |
+
window.location.href = 'login.html';
|
| 268 |
+
}
|
| 269 |
+
});
|
| 270 |
+
});
|
views/style/styles.css
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:root {
|
| 2 |
+
--primary-color: #4361ee;
|
| 3 |
+
--secondary-color: #3f37c9;
|
| 4 |
+
--accent-color: #4895ef;
|
| 5 |
+
--light-color: #f8f9fa;
|
| 6 |
+
--dark-color: #212529;
|
| 7 |
+
--success-color: #4cc9f0;
|
| 8 |
+
--danger-color: #e5383b;
|
| 9 |
+
--warning-color: #ffba08;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
* {
|
| 13 |
+
margin: 0;
|
| 14 |
+
padding: 0;
|
| 15 |
+
box-sizing: border-box;
|
| 16 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
body {
|
| 20 |
+
background-color: #f5f7fa;
|
| 21 |
+
color: var(--dark-color);
|
| 22 |
+
min-height: 100vh;
|
| 23 |
+
display: flex;
|
| 24 |
+
flex-direction: column;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.container {
|
| 28 |
+
max-width: 1200px;
|
| 29 |
+
margin: 0 auto;
|
| 30 |
+
padding: 0 20px;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
header {
|
| 34 |
+
background-color: white;
|
| 35 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 36 |
+
padding: 1rem 0;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
nav {
|
| 40 |
+
display: flex;
|
| 41 |
+
justify-content: space-between;
|
| 42 |
+
align-items: center;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.logo {
|
| 46 |
+
font-size: 1.5rem;
|
| 47 |
+
font-weight: bold;
|
| 48 |
+
color: var(--primary-color);
|
| 49 |
+
cursor: pointer;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.nav-links {
|
| 53 |
+
display: flex;
|
| 54 |
+
gap: 20px;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.nav-links a {
|
| 58 |
+
text-decoration: none;
|
| 59 |
+
color: var(--dark-color);
|
| 60 |
+
font-weight: 500;
|
| 61 |
+
transition: color 0.3s;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
.nav-links a:hover {
|
| 65 |
+
color: var(--primary-color);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.btn {
|
| 69 |
+
display: inline-block;
|
| 70 |
+
padding: 0.6rem 1.5rem;
|
| 71 |
+
background-color: var(--primary-color);
|
| 72 |
+
color: white;
|
| 73 |
+
border: none;
|
| 74 |
+
border-radius: 4px;
|
| 75 |
+
cursor: pointer;
|
| 76 |
+
font-size: 1rem;
|
| 77 |
+
font-weight: 500;
|
| 78 |
+
transition: all 0.3s ease;
|
| 79 |
+
text-decoration: none;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.btn:hover {
|
| 83 |
+
background-color: var(--secondary-color);
|
| 84 |
+
transform: translateY(-2px);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
.btn-outline {
|
| 88 |
+
background-color: transparent;
|
| 89 |
+
border: 2px solid var(--primary-color);
|
| 90 |
+
color: var(--primary-color);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-outline:hover {
|
| 94 |
+
background-color: var(--primary-color);
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-danger {
|
| 99 |
+
background-color: var(--danger-color);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.btn-danger:hover {
|
| 103 |
+
background-color: #c1121f;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.auth-section {
|
| 107 |
+
flex: 1;
|
| 108 |
+
display: flex;
|
| 109 |
+
align-items: center;
|
| 110 |
+
justify-content: center;
|
| 111 |
+
padding: 2rem 0;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
.auth-container {
|
| 115 |
+
width: 100%;
|
| 116 |
+
max-width: 450px;
|
| 117 |
+
background-color: white;
|
| 118 |
+
padding: 2.5rem;
|
| 119 |
+
border-radius: 10px;
|
| 120 |
+
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
.auth-title {
|
| 124 |
+
font-size: 1.75rem;
|
| 125 |
+
font-weight: 600;
|
| 126 |
+
color: var(--primary-color);
|
| 127 |
+
margin-bottom: 1.5rem;
|
| 128 |
+
text-align: center;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.form-group {
|
| 132 |
+
margin-bottom: 1.5rem;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
.form-group label {
|
| 136 |
+
display: block;
|
| 137 |
+
margin-bottom: 0.5rem;
|
| 138 |
+
font-weight: 500;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
.form-control {
|
| 142 |
+
width: 100%;
|
| 143 |
+
padding: 0.8rem;
|
| 144 |
+
border: 1px solid #ddd;
|
| 145 |
+
border-radius: 4px;
|
| 146 |
+
font-size: 1rem;
|
| 147 |
+
transition: border-color 0.3s;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
.form-control:focus {
|
| 151 |
+
outline: none;
|
| 152 |
+
border-color: var(--primary-color);
|
| 153 |
+
box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
.form-footer {
|
| 157 |
+
text-align: center;
|
| 158 |
+
margin-top: 1.5rem;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
.form-footer a {
|
| 162 |
+
color: var(--primary-color);
|
| 163 |
+
text-decoration: none;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
.form-footer a:hover {
|
| 167 |
+
text-decoration: underline;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.alert {
|
| 171 |
+
padding: 0.75rem 1rem;
|
| 172 |
+
margin-bottom: 1rem;
|
| 173 |
+
border-radius: 4px;
|
| 174 |
+
font-weight: 500;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
.alert-danger {
|
| 178 |
+
background-color: #f8d7da;
|
| 179 |
+
color: #721c24;
|
| 180 |
+
border: 1px solid #f5c6cb;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.alert-success {
|
| 184 |
+
background-color: #d4edda;
|
| 185 |
+
color: #155724;
|
| 186 |
+
border: 1px solid #c3e6cb;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/* Profile Page Styles */
|
| 190 |
+
.profile-container {
|
| 191 |
+
max-width: 800px;
|
| 192 |
+
margin: 2rem auto;
|
| 193 |
+
background-color: white;
|
| 194 |
+
border-radius: 10px;
|
| 195 |
+
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
| 196 |
+
padding: 2rem;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
.profile-header {
|
| 200 |
+
display: flex;
|
| 201 |
+
align-items: center;
|
| 202 |
+
margin-bottom: 2rem;
|
| 203 |
+
padding-bottom: 1rem;
|
| 204 |
+
border-bottom: 1px solid #eee;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
.profile-avatar {
|
| 208 |
+
width: 80px;
|
| 209 |
+
height: 80px;
|
| 210 |
+
border-radius: 50%;
|
| 211 |
+
background-color: var(--accent-color);
|
| 212 |
+
color: white;
|
| 213 |
+
display: flex;
|
| 214 |
+
align-items: center;
|
| 215 |
+
justify-content: center;
|
| 216 |
+
font-size: 2rem;
|
| 217 |
+
font-weight: bold;
|
| 218 |
+
margin-right: 1.5rem;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
.profile-title h1 {
|
| 222 |
+
font-size: 1.75rem;
|
| 223 |
+
margin-bottom: 0.25rem;
|
| 224 |
+
color: var(--dark-color);
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
.profile-email {
|
| 228 |
+
color: #6c757d;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
.profile-form {
|
| 232 |
+
display: grid;
|
| 233 |
+
grid-template-columns: 1fr 1fr;
|
| 234 |
+
gap: 1.5rem;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
.profile-actions {
|
| 238 |
+
margin-top: 2rem;
|
| 239 |
+
display: flex;
|
| 240 |
+
justify-content: flex-end;
|
| 241 |
+
gap: 1rem;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
footer {
|
| 245 |
+
background-color: white;
|
| 246 |
+
padding: 1.5rem 0;
|
| 247 |
+
border-top: 1px solid #eee;
|
| 248 |
+
margin-top: auto;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
footer p {
|
| 252 |
+
text-align: center;
|
| 253 |
+
color: #6c757d;
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
.loading {
|
| 257 |
+
position: fixed;
|
| 258 |
+
top: 0;
|
| 259 |
+
left: 0;
|
| 260 |
+
width: 100%;
|
| 261 |
+
height: 100%;
|
| 262 |
+
background-color: rgba(255, 255, 255, 0.8);
|
| 263 |
+
display: flex;
|
| 264 |
+
align-items: center;
|
| 265 |
+
justify-content: center;
|
| 266 |
+
z-index: 1000;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
.loading-spinner {
|
| 270 |
+
width: 50px;
|
| 271 |
+
height: 50px;
|
| 272 |
+
border: 5px solid #f3f3f3;
|
| 273 |
+
border-top: 5px solid var(--primary-color);
|
| 274 |
+
border-radius: 50%;
|
| 275 |
+
animation: spin 1s linear infinite;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
@keyframes spin {
|
| 279 |
+
0% { transform: rotate(0deg); }
|
| 280 |
+
100% { transform: rotate(360deg); }
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
@media (max-width: 768px) {
|
| 284 |
+
.profile-form {
|
| 285 |
+
grid-template-columns: 1fr;
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
.auth-container {
|
| 289 |
+
padding: 1.5rem;
|
| 290 |
+
}
|
| 291 |
+
}
|