Skip to content

Commit a590dc3

Browse files
Merge pull request #20 from PavanCodes05/feat/reset-password-otp
feat: implement password reset with OTP verification
2 parents 68b7751 + a0b39e9 commit a590dc3

File tree

15 files changed

+423
-157
lines changed

15 files changed

+423
-157
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ go.work.sum
2626

2727
# log files
2828
*.log
29+
cockroach-data/
30+
31+
.DS_Store

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# golang 1.23
2-
FROM golang:1.23
1+
# golang 1.24
2+
FROM golang:1.24
33

44
# Set the Current Working Directory inside the container
55
WORKDIR /auth_microservice

controller/resetpassword.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package controller
2+
3+
import (
4+
"net/http"
5+
6+
"evolve/modules/resetpassword"
7+
"evolve/util"
8+
)
9+
10+
// ResetPasswordRequest handles password reset OTP request
11+
func ResetPasswordRequest(w http.ResponseWriter, r *http.Request) {
12+
logger := util.SharedLogger
13+
logger.InfoCtx(r, "Reset password request API called")
14+
15+
data, err := util.Body(r)
16+
if err != nil {
17+
logger.ErrorCtx(r, "failed to parse request body", err)
18+
util.JSONResponse(w, http.StatusBadRequest, "Something went wrong. Please try again.", nil)
19+
return
20+
}
21+
22+
email, ok := data["email"].(string)
23+
if !ok || email == "" {
24+
util.JSONResponse(w, http.StatusBadRequest, "Email is required", nil)
25+
return
26+
}
27+
28+
err = resetpassword.RequestPasswordReset(r.Context(), email)
29+
if err != nil {
30+
logger.ErrorCtx(r, "Reset password request failed", err)
31+
util.JSONResponse(w, http.StatusInternalServerError, "Failed to process request", nil)
32+
return
33+
}
34+
35+
util.JSONResponse(w, http.StatusOK, "If the email exists, an OTP has been sent", nil)
36+
}
37+
38+
// ResetPasswordVerify handles OTP verification and password reset
39+
func ResetPasswordVerify(w http.ResponseWriter, r *http.Request) {
40+
logger := util.SharedLogger
41+
logger.InfoCtx(r, "Reset password verify API called")
42+
43+
data, err := util.Body(r)
44+
if err != nil {
45+
logger.ErrorCtx(r, "failed to parse request body", err)
46+
util.JSONResponse(w, http.StatusBadRequest, "Something went wrong. Please try again.", nil)
47+
return
48+
}
49+
50+
email, _ := data["email"].(string)
51+
otp, _ := data["otp"].(string)
52+
newPassword, _ := data["new_password"].(string)
53+
54+
if email == "" || otp == "" || newPassword == "" {
55+
logger.ErrorCtx(r, "missing required fields", nil)
56+
util.JSONResponse(w, http.StatusBadRequest, "Email, OTP, and new password are required", nil)
57+
return
58+
}
59+
60+
err = resetpassword.VerifyAndResetPassword(r.Context(), email, otp, newPassword)
61+
if err != nil {
62+
logger.ErrorCtx(r, "Reset password verify failed", err)
63+
util.JSONResponse(w, http.StatusBadRequest, "Failed to verify OTP. Please try again.", nil)
64+
return
65+
}
66+
67+
util.JSONResponse(w, http.StatusOK, "Password reset successful", nil)
68+
}

db/scripts/init.sql

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
-- Drop tables in reverse dependency order
2+
DROP TABLE IF EXISTS password_reset_otps;
13
DROP TABLE IF EXISTS teamMembers;
2-
DROP TABLE IF EXISTS team;
34
DROP TABLE IF EXISTS access;
45
DROP TABLE IF EXISTS run;
56
DROP TABLE IF EXISTS registerOtp;
7+
DROP TABLE IF EXISTS team;
68
DROP TABLE IF EXISTS users;
79

810
CREATE TABLE IF NOT EXISTS users (
@@ -62,4 +64,17 @@ CREATE TABLE IF NOT EXISTS teamMembers (
6264
PRIMARY KEY (memberId, teamID),
6365
createdAt TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
6466
updatedAt TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL
65-
);
67+
);
68+
69+
-- table to maintain password reset otps
70+
CREATE TABLE IF NOT EXISTS password_reset_otps (
71+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
72+
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
73+
otp_code STRING NOT NULL,
74+
created_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
75+
expires_at TIMESTAMP WITH TIME ZONE NOT NULL,
76+
is_used BOOLEAN DEFAULT FALSE
77+
);
78+
79+
-- indexing for faster lookups
80+
CREATE INDEX IF NOT EXISTS idx_password_reset_user_id ON password_reset_otps(user_id);

docker-compose.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
services:
44
auth:
5-
image: ghcr.io/evolutionary-algorithms-on-click/auth_microservice:main
5+
# image: ghcr.io/evolutionary-algorithms-on-click/auth_microservice:main
6+
build:
7+
context: .
8+
dockerfile: Dockerfile
69
ports:
710
- "5000:5000"
811
- "5001:5001"
912
environment:
10-
DATABASE_URL : postgresql://[email protected]:26257/defaultdb?sslmode=disable
11-
MAILER_EMAIL : <mailer-email>
12-
MAILER_PASSWORD : <mailer-password>
13-
FRONTEND_URL : http://localhost:3000
14-
HTTP_PORT : 5000
15-
GRPC_PORT : 5001
16-
13+
DATABASE_URL: postgresql://[email protected]:26257/defaultdb?sslmode=disable
14+
MAILER_EMAIL: <mailer-email>
15+
MAILER_PASSWORD: <mailer-password>
16+
FRONTEND_URL: http://localhost:3000
17+
HTTP_PORT: 5000
18+
GRPC_PORT: 5001
19+
ENV: DEVELOPMENT

go.mod

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
module evolve
22

3-
go 1.23.0
3+
go 1.24.0
44

5-
toolchain go1.24.0
5+
toolchain go1.24.4
66

77
require (
88
aidanwoods.dev/go-paseto v1.5.4
99
github.com/google/uuid v1.6.0
10-
github.com/jackc/pgx/v5 v5.7.2
10+
github.com/jackc/pgx/v5 v5.7.6
1111
github.com/rs/cors v1.11.1
12-
google.golang.org/grpc v1.70.0
13-
google.golang.org/protobuf v1.36.5
12+
github.com/rs/zerolog v1.34.0
13+
google.golang.org/grpc v1.76.0
14+
google.golang.org/protobuf v1.36.10
1415
)
1516

1617
require (
1718
aidanwoods.dev/go-result v0.3.1 // indirect
1819
github.com/jackc/pgpassfile v1.0.0 // indirect
1920
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
2021
github.com/jackc/puddle/v2 v2.2.2 // indirect
21-
github.com/mattn/go-colorable v0.1.13 // indirect
22-
github.com/mattn/go-isatty v0.0.19 // indirect
23-
github.com/rs/zerolog v1.34.0 // indirect
22+
github.com/mattn/go-colorable v0.1.14 // indirect
23+
github.com/mattn/go-isatty v0.0.20 // indirect
2424
github.com/stretchr/testify v1.10.0 // indirect
25-
golang.org/x/crypto v0.35.0 // indirect
26-
golang.org/x/net v0.32.0 // indirect
27-
golang.org/x/sync v0.11.0 // indirect
28-
golang.org/x/sys v0.30.0 // indirect
29-
golang.org/x/text v0.22.0 // indirect
30-
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect
25+
golang.org/x/crypto v0.43.0 // indirect
26+
golang.org/x/net v0.46.0 // indirect
27+
golang.org/x/sync v0.17.0 // indirect
28+
golang.org/x/sys v0.37.0 // indirect
29+
golang.org/x/text v0.30.0 // indirect
30+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8 // indirect
3131
)

go.sum

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,32 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
66
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
77
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
88
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9-
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
10-
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
9+
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
10+
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
1111
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
1212
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
1313
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
1414
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
1515
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
16-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
17-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
16+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
17+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
1818
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1919
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2020
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
2121
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
2222
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
2323
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
24-
github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
25-
github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
24+
github.com/jackc/pgx/v5 v5.7.6 h1:rWQc5FwZSPX58r1OQmkuaNicxdmExaEz5A2DO2hUuTk=
25+
github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
2626
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
2727
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
28-
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
2928
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
29+
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
30+
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
3031
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
31-
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
3232
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
33+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
34+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
3335
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3436
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3537
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -43,35 +45,39 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
4345
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
4446
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
4547
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
46-
go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U=
47-
go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=
48-
go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M=
49-
go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8=
50-
go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4=
51-
go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU=
52-
go.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiyYCU9snn1CU=
53-
go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ=
54-
go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM=
55-
go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
56-
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
57-
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
58-
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
59-
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
60-
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
61-
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
48+
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
49+
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
50+
go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=
51+
go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I=
52+
go.opentelemetry.io/otel/metric v1.37.0 h1:mvwbQS5m0tbmqML4NqK+e3aDiO02vsf/WgbsdpcPoZE=
53+
go.opentelemetry.io/otel/metric v1.37.0/go.mod h1:04wGrZurHYKOc+RKeye86GwKiTb9FKm1WHtO+4EVr2E=
54+
go.opentelemetry.io/otel/sdk v1.37.0 h1:ItB0QUqnjesGRvNcmAcU0LyvkVyGJ2xftD29bWdDvKI=
55+
go.opentelemetry.io/otel/sdk v1.37.0/go.mod h1:VredYzxUvuo2q3WRcDnKDjbdvmO0sCzOvVAiY+yUkAg=
56+
go.opentelemetry.io/otel/sdk/metric v1.37.0 h1:90lI228XrB9jCMuSdA0673aubgRobVZFhbjxHHspCPc=
57+
go.opentelemetry.io/otel/sdk/metric v1.37.0/go.mod h1:cNen4ZWfiD37l5NhS+Keb5RXVWZWpRE+9WyVCpbo5ps=
58+
go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4=
59+
go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0=
60+
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
61+
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
62+
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
63+
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
64+
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
65+
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
6266
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6367
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6468
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
65-
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
66-
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
67-
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
68-
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
69-
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1:hgh8P4EuoxpsuKMXX/To36nOFD7vixReXgn8lPGnt+o=
70-
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=
71-
google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ=
72-
google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw=
73-
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
74-
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
69+
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
70+
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
71+
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
72+
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
73+
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
74+
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
75+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8 h1:M1rk8KBnUsBDg1oPGHNCxG4vc1f49epmTO7xscSajMk=
76+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
77+
google.golang.org/grpc v1.76.0 h1:UnVkv1+uMLYXoIz6o7chp59WfQUYA2ex/BXQ9rHZu7A=
78+
google.golang.org/grpc v1.76.0/go.mod h1:Ju12QI8M6iQJtbcsV+awF5a4hfJMLi4X0JLo94ULZ6c=
79+
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
80+
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
7581
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
7682
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
7783
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

main.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"aidanwoods.dev/go-paseto"
54
"context"
65
"evolve/config"
76
"evolve/controller"
@@ -11,27 +10,31 @@ import (
1110
"evolve/routes"
1211
"evolve/util"
1312
"fmt"
14-
"github.com/rs/cors"
15-
"google.golang.org/grpc"
1613
"net"
1714
"net/http"
1815
"os"
1916
"runtime"
17+
18+
"aidanwoods.dev/go-paseto"
19+
"github.com/rs/cors"
20+
"google.golang.org/grpc"
2021
)
2122

2223
var (
2324
HTTP_PORT string
2425
GRPC_PORT string
2526
)
2627

27-
func serveHTTP(logger *util.LoggerService) {
28+
func serveHTTP() {
29+
logger := util.SharedLogger
2830
// Register routes.
2931
http.HandleFunc(routes.TEST, controller.Test)
3032
http.HandleFunc(routes.REGISTER, controller.Register)
3133
http.HandleFunc(routes.VERIFY, controller.Verify)
3234
http.HandleFunc(routes.LOGIN, controller.Login)
35+
http.HandleFunc(routes.PASSWORD_RESET, controller.ResetPasswordRequest)
36+
http.HandleFunc(routes.PASSWORD_VERIFY, controller.ResetPasswordVerify)
3337

34-
3538
logger.Info(fmt.Sprintf("Test http server on http://localhost%v/api/test", HTTP_PORT))
3639
corsHandler := cors.New(cors.Options{
3740
AllowedOrigins: []string{os.Getenv("FRONTEND_URL")}, // Allowing frontend to access the server.
@@ -40,15 +43,16 @@ func serveHTTP(logger *util.LoggerService) {
4043
AllowCredentials: true,
4144
}).Handler(http.DefaultServeMux)
4245

43-
handler := util.Log.LogMiddleware(corsHandler)
46+
handler := util.SharedLogger.LogMiddleware(corsHandler)
4447

4548
if err := http.ListenAndServe(HTTP_PORT, handler); err != nil {
4649
logger.Error(fmt.Sprintf("Failed to start server: %v", err), err)
4750
return
4851
}
4952
}
5053

51-
func serveGRPC(logger *util.LoggerService) {
54+
func serveGRPC() {
55+
logger := util.SharedLogger
5256
lis, err := net.Listen("tcp", GRPC_PORT)
5357
if err != nil {
5458
logger.Error(fmt.Sprintf("failed to listen TCP in GRPC PORT%v : %v", GRPC_PORT, err), err)
@@ -68,29 +72,26 @@ func main() {
6872

6973
HTTP_PORT = fmt.Sprintf(":%v", os.Getenv("HTTP_PORT"))
7074
GRPC_PORT = fmt.Sprintf(":%v", os.Getenv("GRPC_PORT"))
71-
72-
logger, err := util.InitLogger(os.Getenv("ENV")) // "DEVELOPMENT" or "PRODUCTION"
75+
76+
logger, err := util.InitLogger(os.Getenv("ENV"))
7377
if err != nil {
7478
fmt.Println("failed to init logger:", err)
7579
return
7680
}
77-
util.Log = logger
78-
79-
81+
util.SharedLogger = logger
8082

8183
// Initialize db with schema.
8284
if err := db.InitDb(context.Background()); err != nil {
8385
logger.Error("failed to init db", err)
84-
logger.Error(err.Error(), err)
8586
return
8687
}
8788

8889
// Initialize key.
8990
key := paseto.NewV4AsymmetricSecretKey()
9091
config.PrivateKey, config.PublicKey = key, key.Public()
9192

92-
go serveHTTP(util.Log)
93-
go serveGRPC(util.Log)
93+
go serveHTTP()
94+
go serveGRPC()
9495

9596
runtime.Goexit()
9697
}

0 commit comments

Comments
 (0)