diff --git a/.DS_Store b/.DS_Store
index 685250b..19b956a 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/.env b/.env
deleted file mode 100644
index 70ce67d..0000000
--- a/.env
+++ /dev/null
@@ -1,5 +0,0 @@
-MONGO_URI="mongodb://adminLinh:linhporo1@localhost:27017"
-API_TEST_PORT=":8080"
-REDIS_URI="redis://localhost:6379/0"
-SMTP_PASS="btmp judz ebys pfxw"
-EMAIL_VERIFY_SECRET="WDc&4+&vYP(n'}?LHNE#5M?IE|g(c812"
diff --git a/Template/email.html b/Template/email.html
index d227ca7..89ca0c6 100644
--- a/Template/email.html
+++ b/Template/email.html
@@ -62,7 +62,7 @@
data-darkreader-inline-color=""
>
-
+
+
+ |
|
Not you? If you didn't request a code to sign up for
- HubSpot, you can safely ignore this email. An account was
+ TotodayShop, you can safely ignore this email. An account was
not created.
|
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
new file mode 100644
index 0000000..bf0f585
--- /dev/null
+++ b/docker/docker-compose.yml
@@ -0,0 +1,25 @@
+version: '3.5'
+
+services:
+ mongodb:
+ image: mongo
+ restart: unless-stopped
+ container_name: mongo-user
+ environment:
+ MONGO_INITDB_ROOT_USERNAME: adminLinh
+ MONGO_INITDB_ROOT_PASSWORD: linhporo1
+ ports:
+ - "27018:27017"
+ volumes:
+ - ./mongo-data:/data/db
+
+ redis:
+ image: redis
+ container_name: redis-user
+ restart: unless-stopped
+ ports:
+ - "6379:6379"
+ volumes:
+ - ./redis-data:/data
+
+
diff --git a/docker/mongo-data/.mongodb/mongosh/658a51aa4f9cbdd4fac1f672_log b/docker/mongo-data/.mongodb/mongosh/658a51aa4f9cbdd4fac1f672_log
new file mode 100644
index 0000000..53445f2
--- /dev/null
+++ b/docker/mongo-data/.mongodb/mongosh/658a51aa4f9cbdd4fac1f672_log
@@ -0,0 +1,9 @@
+{"t":{"$date":"2023-12-26T04:08:10.113Z"},"s":"I","c":"MONGOSH","id":1000000000,"ctx":"log","msg":"Starting log","attr":{"execPath":"/usr/bin/mongosh","envInfo":{"EDITOR":null,"NODE_OPTIONS":null,"TERM":null},"version":"2.0.2","distributionKind":"compiled","buildArch":"arm64","buildPlatform":"linux","buildTarget":"linux-arm64","buildTime":"2023-10-14T12:00:56.963Z","gitVersion":"5737e60cdbcd551f6a355b38fc9b5b6cc19ac5a4","nodeVersion":"v20.8.1","opensslVersion":"3.0.10+quic","sharedOpenssl":false,"runtimeArch":"arm64","runtimePlatform":"linux","deps":{"nodeDriverVersion":"6.0.0","libmongocryptVersion":"1.9.0-20230828+git8e7f69f1c0","libmongocryptNodeBindingsVersion":"6.0.0"}}}
+{"t":{"$date":"2023-12-26T04:08:10.149Z"},"s":"I","c":"MONGOSH","id":1000000048,"ctx":"config","msg":"Loading global configuration file","attr":{"filename":"/etc/mongosh.conf","found":false}}
+{"t":{"$date":"2023-12-26T04:08:10.158Z"},"s":"E","c":"DEVTOOLS-CONNECT","id":1000000041,"ctx":"mongosh-deps","msg":"Missing optional dependency","attr":{"name":"saslprep","error":"Cannot find module 'saslprep'"}}
+{"t":{"$date":"2023-12-26T04:08:10.160Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000042,"ctx":"mongosh-connect","msg":"Initiating connection attempt","attr":{"uri":"mongodb://127.0.0.1:27017/admin?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.2","driver":{"name":"nodejs|mongosh","version":"6.0.0|2.0.2"},"devtoolsConnectVersion":"2.4.1","host":"127.0.0.1:27017"}}
+{"t":{"$date":"2023-12-26T04:08:10.161Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000035,"ctx":"mongosh-connect","msg":"Server heartbeat succeeded","attr":{"connectionId":"127.0.0.1:27017"}}
+{"t":{"$date":"2023-12-26T04:08:10.167Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000037,"ctx":"mongosh-connect","msg":"Connection attempt finished"}
+{"t":{"$date":"2023-12-26T04:08:10.175Z"},"s":"I","c":"MONGOSH","id":1000000004,"ctx":"connect","msg":"Connecting to server","attr":{"session_id":"658a51aa4f9cbdd4fac1f672","userId":null,"telemetryAnonymousId":"658a51aa4f9cbdd4fac1f671","connectionUri":"mongodb://:27017/admin?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.2","is_atlas":false,"is_localhost":true,"is_do":false,"server_version":"7.0.3","node_version":"v20.8.1","mongosh_version":"2.0.2","server_os":"linux","server_arch":"aarch64","is_enterprise":false,"auth_type":null,"is_data_federation":false,"is_stream":false,"dl_version":null,"atlas_version":null,"is_genuine":true,"non_genuine_server_name":"mongodb","is_local_atlas":false,"fcv":"7.0","api_version":null,"api_strict":null,"api_deprecation_errors":null}}
+{"t":{"$date":"2023-12-26T04:08:10.189Z"},"s":"I","c":"MONGOSH","id":1000000010,"ctx":"shell-api","msg":"Initialized context","attr":{"method":"setCtx","arguments":{}}}
+{"t":{"$date":"2023-12-26T04:08:10.302Z"},"s":"I","c":"MONGOSH-SNIPPETS","id":1000000019,"ctx":"snippets","msg":"Loaded snippets","attr":{"installdir":"/data/db/.mongodb/mongosh/snippets"}}
diff --git a/docker/mongo-data/.mongodb/mongosh/658a51aae84b58e8e476844b_log b/docker/mongo-data/.mongodb/mongosh/658a51aae84b58e8e476844b_log
new file mode 100644
index 0000000..79e25ad
--- /dev/null
+++ b/docker/mongo-data/.mongodb/mongosh/658a51aae84b58e8e476844b_log
@@ -0,0 +1,15 @@
+{"t":{"$date":"2023-12-26T04:08:10.521Z"},"s":"I","c":"MONGOSH","id":1000000000,"ctx":"log","msg":"Starting log","attr":{"execPath":"/usr/bin/mongosh","envInfo":{"EDITOR":null,"NODE_OPTIONS":null,"TERM":null},"version":"2.0.2","distributionKind":"compiled","buildArch":"arm64","buildPlatform":"linux","buildTarget":"linux-arm64","buildTime":"2023-10-14T12:00:56.963Z","gitVersion":"5737e60cdbcd551f6a355b38fc9b5b6cc19ac5a4","nodeVersion":"v20.8.1","opensslVersion":"3.0.10+quic","sharedOpenssl":false,"runtimeArch":"arm64","runtimePlatform":"linux","deps":{"nodeDriverVersion":"6.0.0","libmongocryptVersion":"1.9.0-20230828+git8e7f69f1c0","libmongocryptNodeBindingsVersion":"6.0.0"}}}
+{"t":{"$date":"2023-12-26T04:08:10.552Z"},"s":"I","c":"MONGOSH","id":1000000005,"ctx":"config","msg":"User updated"}
+{"t":{"$date":"2023-12-26T04:08:10.560Z"},"s":"I","c":"MONGOSH","id":1000000048,"ctx":"config","msg":"Loading global configuration file","attr":{"filename":"/etc/mongosh.conf","found":false}}
+{"t":{"$date":"2023-12-26T04:08:10.562Z"},"s":"E","c":"DEVTOOLS-CONNECT","id":1000000041,"ctx":"mongosh-deps","msg":"Missing optional dependency","attr":{"name":"saslprep","error":"Cannot find module 'saslprep'"}}
+{"t":{"$date":"2023-12-26T04:08:10.567Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000042,"ctx":"mongosh-connect","msg":"Initiating connection attempt","attr":{"uri":"mongodb://127.0.0.1:27017/admin?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.2","driver":{"name":"nodejs|mongosh","version":"6.0.0|2.0.2"},"devtoolsConnectVersion":"2.4.1","host":"127.0.0.1:27017"}}
+{"t":{"$date":"2023-12-26T04:08:10.568Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000035,"ctx":"mongosh-connect","msg":"Server heartbeat succeeded","attr":{"connectionId":"127.0.0.1:27017"}}
+{"t":{"$date":"2023-12-26T04:08:10.569Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000037,"ctx":"mongosh-connect","msg":"Connection attempt finished"}
+{"t":{"$date":"2023-12-26T04:08:10.575Z"},"s":"I","c":"MONGOSH","id":1000000004,"ctx":"connect","msg":"Connecting to server","attr":{"session_id":"658a51aae84b58e8e476844b","userId":null,"telemetryAnonymousId":"658a51aa4f9cbdd4fac1f671","connectionUri":"mongodb://:27017/admin?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.2","is_atlas":false,"is_localhost":true,"is_do":false,"server_version":"7.0.3","node_version":"v20.8.1","mongosh_version":"2.0.2","server_os":"linux","server_arch":"aarch64","is_enterprise":false,"auth_type":null,"is_data_federation":false,"is_stream":false,"dl_version":null,"atlas_version":null,"is_genuine":true,"non_genuine_server_name":"mongodb","is_local_atlas":false,"fcv":"7.0","api_version":null,"api_strict":null,"api_deprecation_errors":null}}
+{"t":{"$date":"2023-12-26T04:08:10.587Z"},"s":"I","c":"MONGOSH","id":1000000010,"ctx":"shell-api","msg":"Initialized context","attr":{"method":"setCtx","arguments":{}}}
+{"t":{"$date":"2023-12-26T04:08:10.588Z"},"s":"I","c":"MONGOSH-SNIPPETS","id":1000000024,"ctx":"snippets","msg":"Fetching snippet index","attr":{"refreshMode":"allow-cached"}}
+{"t":{"$date":"2023-12-26T04:08:10.588Z"},"s":"I","c":"MONGOSH-SNIPPETS","id":1000000019,"ctx":"snippets","msg":"Loaded snippets","attr":{"installdir":"/data/db/.mongodb/mongosh/snippets"}}
+{"t":{"$date":"2023-12-26T04:08:10.612Z"},"s":"I","c":"MONGOSH-SNIPPETS","id":1000000028,"ctx":"snippets","msg":"Modifying snippets package.json failed","attr":{"error":"ENOENT: no such file or directory, open '/data/db/.mongodb/mongosh/snippets/package.json'"}}
+{"t":{"$date":"2023-12-26T04:08:10.613Z"},"s":"I","c":"MONGOSH","id":1000000002,"ctx":"repl","msg":"Started REPL","attr":{"version":"2.0.2"}}
+{"t":{"$date":"2023-12-26T04:08:10.728Z"},"s":"I","c":"MONGOSH","id":1000000011,"ctx":"shell-api","msg":"Performed API call","attr":{"method":"createUser","class":"Database","db":"admin","arguments":{}}}
+{"t":{"$date":"2023-12-26T04:08:10.767Z"},"s":"I","c":"MONGOSH","id":1000000045,"ctx":"analytics","msg":"Flushed outstanding data","attr":{"flushError":"connect ECONNREFUSED 0.0.0.0:443","flushDuration":3}}
diff --git a/docker/mongo-data/.mongodb/mongosh/am-658a51aa4f9cbdd4fac1f671.json b/docker/mongo-data/.mongodb/mongosh/am-658a51aa4f9cbdd4fac1f671.json
new file mode 100644
index 0000000..e1cb597
--- /dev/null
+++ b/docker/mongo-data/.mongodb/mongosh/am-658a51aa4f9cbdd4fac1f671.json
@@ -0,0 +1 @@
+{"count":3,"timestamp":1703563690524}
\ No newline at end of file
diff --git a/docker/mongo-data/.mongodb/mongosh/config b/docker/mongo-data/.mongodb/mongosh/config
new file mode 100644
index 0000000..a62d93c
--- /dev/null
+++ b/docker/mongo-data/.mongodb/mongosh/config
@@ -0,0 +1 @@
+{"userId":"658a51aa4f9cbdd4fac1f671","telemetryAnonymousId":"658a51aa4f9cbdd4fac1f671","enableTelemetry":true}
\ No newline at end of file
diff --git a/docker/mongo-data/.mongodb/mongosh/mongosh_repl_history b/docker/mongo-data/.mongodb/mongosh/mongosh_repl_history
new file mode 100644
index 0000000..e69de29
diff --git a/docker/mongo-data/.mongodb/mongosh/snippets/package.json b/docker/mongo-data/.mongodb/mongosh/snippets/package.json
new file mode 100644
index 0000000..9e26dfe
--- /dev/null
+++ b/docker/mongo-data/.mongodb/mongosh/snippets/package.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/docker/mongo-data/WiredTiger b/docker/mongo-data/WiredTiger
new file mode 100644
index 0000000..1bc57ba
--- /dev/null
+++ b/docker/mongo-data/WiredTiger
@@ -0,0 +1,2 @@
+WiredTiger
+WiredTiger 11.2.0: (November 10, 2022)
diff --git a/docker/mongo-data/WiredTiger.lock b/docker/mongo-data/WiredTiger.lock
new file mode 100644
index 0000000..3d84206
--- /dev/null
+++ b/docker/mongo-data/WiredTiger.lock
@@ -0,0 +1 @@
+WiredTiger lock file
diff --git a/docker/mongo-data/WiredTiger.turtle b/docker/mongo-data/WiredTiger.turtle
new file mode 100644
index 0000000..543e0fd
--- /dev/null
+++ b/docker/mongo-data/WiredTiger.turtle
@@ -0,0 +1,6 @@
+WiredTiger version string
+WiredTiger 11.2.0: (November 10, 2022)
+WiredTiger version
+major=11,minor=2,patch=0
+file:WiredTiger.wt
+access_pattern_hint=none,allocation_size=4KB,app_metadata=,assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none,write_timestamp=off),block_allocation=best,block_compressor=,cache_resident=false,checksum=on,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,readonly=false,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,tiered_object=false,tiered_storage=(auth_token=,bucket=,bucket_prefix=,cache_directory=,local_retention=300,name=,object_target_size=0),value_format=S,verbose=[],version=(major=1,minor=1),write_timestamp_usage=none,checkpoint=(WiredTigerCheckpoint.3829=(addr="018381e4a4fca4788481e4f60a3dab8581e42f5ee472808080e3012fc0e24fc0",order=3829,time=1703919333,size=32768,newest_start_durable_ts=0,oldest_start_ts=0,newest_txn=4211,newest_stop_durable_ts=0,newest_stop_ts=-1,newest_stop_txn=-11,prepare=0,write_gen=11486,run_write_gen=9)),checkpoint_backup_info=,checkpoint_lsn=(2,3193088)
diff --git a/docker/mongo-data/WiredTiger.wt b/docker/mongo-data/WiredTiger.wt
new file mode 100644
index 0000000..3f964a1
Binary files /dev/null and b/docker/mongo-data/WiredTiger.wt differ
diff --git a/docker/mongo-data/WiredTigerHS.wt b/docker/mongo-data/WiredTigerHS.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/docker/mongo-data/WiredTigerHS.wt differ
diff --git a/docker/mongo-data/_mdb_catalog.wt b/docker/mongo-data/_mdb_catalog.wt
new file mode 100644
index 0000000..c579fd3
Binary files /dev/null and b/docker/mongo-data/_mdb_catalog.wt differ
diff --git a/docker/mongo-data/collection-0-1350336485432446823.wt b/docker/mongo-data/collection-0-1350336485432446823.wt
new file mode 100644
index 0000000..f054370
Binary files /dev/null and b/docker/mongo-data/collection-0-1350336485432446823.wt differ
diff --git a/docker/mongo-data/collection-0-7047784008155958742.wt b/docker/mongo-data/collection-0-7047784008155958742.wt
new file mode 100644
index 0000000..34ccfca
Binary files /dev/null and b/docker/mongo-data/collection-0-7047784008155958742.wt differ
diff --git a/docker/mongo-data/collection-2-1350336485432446823.wt b/docker/mongo-data/collection-2-1350336485432446823.wt
new file mode 100644
index 0000000..4aaa22c
Binary files /dev/null and b/docker/mongo-data/collection-2-1350336485432446823.wt differ
diff --git a/docker/mongo-data/collection-4-1350336485432446823.wt b/docker/mongo-data/collection-4-1350336485432446823.wt
new file mode 100644
index 0000000..e663eb4
Binary files /dev/null and b/docker/mongo-data/collection-4-1350336485432446823.wt differ
diff --git a/docker/mongo-data/collection-7-1350336485432446823.wt b/docker/mongo-data/collection-7-1350336485432446823.wt
new file mode 100644
index 0000000..132cf81
Binary files /dev/null and b/docker/mongo-data/collection-7-1350336485432446823.wt differ
diff --git a/docker/mongo-data/diagnostic.data/metrics.2023-12-26T04-08-10Z-00000 b/docker/mongo-data/diagnostic.data/metrics.2023-12-26T04-08-10Z-00000
new file mode 100644
index 0000000..31078ad
Binary files /dev/null and b/docker/mongo-data/diagnostic.data/metrics.2023-12-26T04-08-10Z-00000 differ
diff --git a/docker/mongo-data/diagnostic.data/metrics.2023-12-26T04-08-14Z-00000 b/docker/mongo-data/diagnostic.data/metrics.2023-12-26T04-08-14Z-00000
new file mode 100644
index 0000000..e6dabb1
Binary files /dev/null and b/docker/mongo-data/diagnostic.data/metrics.2023-12-26T04-08-14Z-00000 differ
diff --git a/docker/mongo-data/diagnostic.data/metrics.2023-12-28T07-31-11Z-00000 b/docker/mongo-data/diagnostic.data/metrics.2023-12-28T07-31-11Z-00000
new file mode 100644
index 0000000..4f8689a
Binary files /dev/null and b/docker/mongo-data/diagnostic.data/metrics.2023-12-28T07-31-11Z-00000 differ
diff --git a/docker/mongo-data/diagnostic.data/metrics.interim b/docker/mongo-data/diagnostic.data/metrics.interim
new file mode 100644
index 0000000..ea135e7
Binary files /dev/null and b/docker/mongo-data/diagnostic.data/metrics.interim differ
diff --git a/docker/mongo-data/index-1-1350336485432446823.wt b/docker/mongo-data/index-1-1350336485432446823.wt
new file mode 100644
index 0000000..d619848
Binary files /dev/null and b/docker/mongo-data/index-1-1350336485432446823.wt differ
diff --git a/docker/mongo-data/index-2-7047784008155958742.wt b/docker/mongo-data/index-2-7047784008155958742.wt
new file mode 100644
index 0000000..9c8c26e
Binary files /dev/null and b/docker/mongo-data/index-2-7047784008155958742.wt differ
diff --git a/docker/mongo-data/index-3-1350336485432446823.wt b/docker/mongo-data/index-3-1350336485432446823.wt
new file mode 100644
index 0000000..5ef89bc
Binary files /dev/null and b/docker/mongo-data/index-3-1350336485432446823.wt differ
diff --git a/docker/mongo-data/index-5-1350336485432446823.wt b/docker/mongo-data/index-5-1350336485432446823.wt
new file mode 100644
index 0000000..f02d739
Binary files /dev/null and b/docker/mongo-data/index-5-1350336485432446823.wt differ
diff --git a/docker/mongo-data/index-6-1350336485432446823.wt b/docker/mongo-data/index-6-1350336485432446823.wt
new file mode 100644
index 0000000..bd36873
Binary files /dev/null and b/docker/mongo-data/index-6-1350336485432446823.wt differ
diff --git a/docker/mongo-data/index-8-1350336485432446823.wt b/docker/mongo-data/index-8-1350336485432446823.wt
new file mode 100644
index 0000000..ac3035d
Binary files /dev/null and b/docker/mongo-data/index-8-1350336485432446823.wt differ
diff --git a/docker/mongo-data/index-9-1350336485432446823.wt b/docker/mongo-data/index-9-1350336485432446823.wt
new file mode 100644
index 0000000..5ad50fe
Binary files /dev/null and b/docker/mongo-data/index-9-1350336485432446823.wt differ
diff --git a/docker/mongo-data/journal/WiredTigerLog.0000000002 b/docker/mongo-data/journal/WiredTigerLog.0000000002
new file mode 100644
index 0000000..e5e470b
Binary files /dev/null and b/docker/mongo-data/journal/WiredTigerLog.0000000002 differ
diff --git a/docker/mongo-data/journal/WiredTigerPreplog.0000000001 b/docker/mongo-data/journal/WiredTigerPreplog.0000000001
new file mode 100644
index 0000000..aa52a21
Binary files /dev/null and b/docker/mongo-data/journal/WiredTigerPreplog.0000000001 differ
diff --git a/docker/mongo-data/journal/WiredTigerPreplog.0000000002 b/docker/mongo-data/journal/WiredTigerPreplog.0000000002
new file mode 100644
index 0000000..aa52a21
Binary files /dev/null and b/docker/mongo-data/journal/WiredTigerPreplog.0000000002 differ
diff --git a/docker/mongo-data/mongod.lock b/docker/mongo-data/mongod.lock
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/docker/mongo-data/mongod.lock
@@ -0,0 +1 @@
+1
diff --git a/docker/mongo-data/sizeStorer.wt b/docker/mongo-data/sizeStorer.wt
new file mode 100644
index 0000000..a108fc4
Binary files /dev/null and b/docker/mongo-data/sizeStorer.wt differ
diff --git a/docker/mongo-data/storage.bson b/docker/mongo-data/storage.bson
new file mode 100644
index 0000000..276b694
Binary files /dev/null and b/docker/mongo-data/storage.bson differ
diff --git a/docker/redis-data/dump.rdb b/docker/redis-data/dump.rdb
new file mode 100644
index 0000000..1e27f0a
Binary files /dev/null and b/docker/redis-data/dump.rdb differ
diff --git a/models/models.go b/models/models.go
index ea58cfc..2290f0c 100644
--- a/models/models.go
+++ b/models/models.go
@@ -97,3 +97,10 @@ type EmailTemplate struct {
AlternativeLink string `json:"alternativeLink"`
QrCode template.URL
}
+
+type RedisOTP struct {
+ Email string `json:"email"`
+ User string `json:"user"`
+ CreatedDate int64 `json:"created_date"`
+ HashOTP string `json:"hashOTP"`
+}
diff --git a/rest-api/init-api.go b/rest-api/init-api.go
index db07dfa..66ca3e2 100644
--- a/rest-api/init-api.go
+++ b/rest-api/init-api.go
@@ -3,12 +3,10 @@ package rest_api
import (
"fmt"
"github.com/gorilla/mux"
- "linhdevtran99/rest-api/models"
"linhdevtran99/rest-api/rest-api/routes"
"linhdevtran99/rest-api/utils"
"log"
"net/http"
- "time"
)
type APIServer struct {
@@ -42,29 +40,7 @@ func (s *APIServer) Run() {
func (s *APIServer) TestRoute(w http.ResponseWriter, r *http.Request) error {
if r.Method == http.MethodGet {
- fmt.Println("hit")
-
- //serect := os.Getenv("EMAIL_VERIFY_SECRET")
-
- //_, otp := services.GeneratorOtp("hello", "nhocdl.poro1@gmail.com", 12, serect)
- //fmt.Println(otp.HashOTP)
- //fmt.Println(otp.PureOTP)
-
- //utils.EncryptAESMailLink("nhocdl.poro2@gmail.com", serect, w)
- preUserData := &models.PreusersMongo{
- Username: "thewind121212",
- Email: "nhocdl.poro1@gmail.com",
- PhoneNumber: "0918327132",
- HashPassword: "it ok now ",
- CreatedDate: time.Now(),
- UpdateDate: time.Now(),
- VerifySentCount: 1,
- }
-
- _ = preUserData
-
- //services.WriteOTPInRedis(preUserData, "tranduy linh ", w)
-
+ fmt.Println("hello")
}
return nil
diff --git a/rest-api/routes/auth.go b/rest-api/routes/auth.go
index 1bf4ec3..21b6e5e 100644
--- a/rest-api/routes/auth.go
+++ b/rest-api/routes/auth.go
@@ -2,6 +2,7 @@ package routes
import (
"encoding/json"
+ "fmt"
"github.com/gorilla/mux"
"linhdevtran99/rest-api/models"
"linhdevtran99/rest-api/rest-api/services"
@@ -15,14 +16,25 @@ func RegisterNewAccount(w http.ResponseWriter, r *http.Request) error {
var registerInfo models.CreateUser
_ = json.NewDecoder(r.Body).Decode(®isterInfo)
+ //[ok]
+
//call function check info user type in
validRegisterInfo, responseAPI := services.CheckAndValidRegisterFiled(®isterInfo)
+ //[fairy ok]
+
if responseAPI != nil {
return utils.WriteJSON(w, responseAPI.Code, responseAPI.Err.Error())
}
+
+ fmt.Println(validRegisterInfo)
+
//call function check data user use in past or not
- isValidData, responseAPI := services.CheckAccountExist(registerInfo.Username, registerInfo.Email)
- if responseAPI != nil {
+
+ isValidData, responseAPI := services.CheckAccountValid(registerInfo.Username, registerInfo.Email)
+
+ fmt.Println(isValidData)
+
+ if isValidData != true {
return utils.WriteJSON(w, responseAPI.Code, responseAPI.Err.Error())
}
@@ -39,15 +51,26 @@ func RegisterNewAccount(w http.ResponseWriter, r *http.Request) error {
services.GenerateVerifyAccount(preUserData, w)
//debug
- if isValidData == true || validRegisterInfo == true {
- return utils.WriteJSON(w, http.StatusOK, "USER HAVE VALID INFO FOR REGISTER ACCOUNT")
- }
+ //if isValidData == true || validRegisterInfo == true {
+ // return utils.WriteJSON(w, http.StatusOK, "USER HAVE VALID INFO FOR REGISTER ACCOUNT")
+ //}
//debug
}
return nil
}
+func Linh(w http.ResponseWriter, r *http.Request) error {
+ if r.Method == http.MethodGet {
+ var registerInfo models.CreateUser
+
+ _ = json.NewDecoder(r.Body).Decode(®isterInfo)
+ fmt.Println(registerInfo)
+
+ }
+ return nil
+}
+
func AuthRouterSetup(router *mux.Router) {
authRouter := router.PathPrefix("/account").Subrouter()
authRouter.Handle("/register", utils.MakeHTTPHandlerFn(RegisterNewAccount)).Methods("POST")
diff --git a/rest-api/services/register.go b/rest-api/services/register.go
index 86df1e1..32a7f41 100644
--- a/rest-api/services/register.go
+++ b/rest-api/services/register.go
@@ -15,6 +15,7 @@ import (
"log"
"net/http"
"os"
+ "strconv"
"sync"
"time"
)
@@ -69,10 +70,11 @@ func CheckAndValidRegisterFiled(registerData *models.CreateUser) (bool, *Respons
}
// CheckAccountExist Checking in db is user input same data in
-func CheckAccountExist(userName string, email string) (bool, *ResponseError) {
+func CheckAccountValid(userName string, email string) (bool, *ResponseError) {
//filter in mongodb
var isValid bool
var errAPI *ResponseError
+ var dataRedisRetrive models.RedisOTP
filter := bson.D{
{"$or", bson.A{
@@ -93,6 +95,23 @@ func CheckAccountExist(userName string, email string) (bool, *ResponseError) {
Err: errors.New("your username or email had been register before"),
}
}
+ retrievedValue, err := utils.Redis.Get(context.Background(), "otp:"+email).Result()
+ err = json.Unmarshal([]byte(retrievedValue), &dataRedisRetrive)
+ if err != nil {
+ fmt.Println("Internal Log: Can't get data from redis")
+ }
+
+ timeDiff := time.Now().Unix() - dataRedisRetrive.CreatedDate
+
+ if timeDiff < 30 {
+ isValid = false
+ fmt.Println("Internal Log: Rate limit send verify mail")
+ errAPI = &ResponseError{
+ Code: http.StatusBadRequest,
+ Err: errors.New("wait " + strconv.FormatInt(30-timeDiff, 10) + " to send verify mail again"),
+ }
+
+ }
return isValid, errAPI
}
@@ -139,13 +158,13 @@ func createMailVerify(registerInfo *models.PreusersMongo, otpChan chan models.Ot
os.WriteFile("./temp/"+qrFileName, decodedImage, 0666)
emailBody := utils.BuildEmail(opt.PureOTP, mailVerify.LinkMail, qrFileName)
- m.SetHeader("From", "kotomi.poro1@gmail.com")
+ m.SetHeader("From", "admin@wliafdew.dev")
m.SetHeader("To", registerInfo.Email)
m.SetHeader("Subject", "Thanks For Join My Business")
m.SetBody("text/html", emailBody)
m.Embed("./temp/" + qrFileName)
- d := mail.NewDialer("smtp.gmail.com", 587, "kotomi.poro1@gmail.com", smtpPass)
+ d := mail.NewDialer("mail.wliafdew.dev", 465, "admin@wliafdew.dev", smtpPass)
d.StartTLSPolicy = mail.MandatoryStartTLS
// Send the email to Bob, Cora and Dan.
@@ -208,19 +227,19 @@ func writeOTPInRedis(registerInfo *models.PreusersMongo, otpChan chan models.Otp
otp := <-otpChan
- data := map[string]string{
- "email": registerInfo.Email,
- "user": registerInfo.Username,
- "create_date": registerInfo.CreatedDate.String(),
- "hashOTP": otp.HashOTP,
+ dataRedis := &models.RedisOTP{
+ Email: registerInfo.Email,
+ User: registerInfo.Username,
+ CreatedDate: registerInfo.CreatedDate.Unix(),
+ HashOTP: otp.HashOTP,
}
- jsonData, err := json.Marshal(data)
+ jsonData, err := json.Marshal(dataRedis)
if err != nil {
fmt.Println("Internal log: Can't stringfy json data")
_ = utils.WriteJSONInternalError(w, "Can't stringfy json data")
}
- status := utils.Redis.Set(context.Background(), "otp:nhocdl.poro1@gmail.com", string(jsonData), time.Minute*2)
+ status := utils.Redis.Set(context.Background(), "otp:"+registerInfo.Email, string(jsonData), time.Hour*24)
fmt.Println(status.Err())
diff --git a/utils/crypto.go b/utils/crypto.go
index 527c9c7..5ed6703 100644
--- a/utils/crypto.go
+++ b/utils/crypto.go
@@ -30,7 +30,7 @@ type MyCustomClaims struct {
func buildTokenLink(token string, w http.ResponseWriter) (string, string) {
tokenCustomTrim := strings.ReplaceAll(token, ".", "&")
- emailVerifyLink := "http://www.totoday.com/?p=" + tokenCustomTrim
+ emailVerifyLink := "https://api.wliafdew.dev/?p=" + tokenCustomTrim
png, err := qrcode.Encode(emailVerifyLink, qrcode.Low, 200)
if err != nil {
fmt.Println("Internal log: error create qr ")
@@ -79,7 +79,7 @@ func EncryptAESMailLink(registerInfo *models.PreusersMongo, w http.ResponseWrite
//func DecryptAESMailLink(data string, key string) string {
//}
-//OTP
+//OTP+++++++++++++OTP//
func GenOTP(registerInfo *models.PreusersMongo, counter uint64, otpDigits int, w http.ResponseWriter, otpChan chan models.OtpGenerate, wg *sync.WaitGroup) chan models.OtpGenerate {
diff --git a/utils/mail-template.go b/utils/mail-template.go
index 1826cd9..e58f562 100644
--- a/utils/mail-template.go
+++ b/utils/mail-template.go
@@ -27,7 +27,6 @@ func BuildEmail(otp string, mailLink string, fileName string) string {
var result bytes.Buffer
_ = tmpl.Execute(&result, data)
- fmt.Println(result.String())
return result.String()
}