Remove .env from tracking

This commit is contained in:
Trần Duy Linh 2023-12-30 13:57:45 +07:00
parent 89913a91ff
commit eea1de9c0a
45 changed files with 139 additions and 57 deletions

BIN
.DS_Store vendored

Binary file not shown.

5
.env
View File

@ -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"

View File

@ -62,7 +62,7 @@
data-darkreader-inline-color=""
>
<img
src="https://pos.nvncdn.net/d0f3ca-7136/store/20230906_9BHMhQjv.png"
src="https://firebasestorage.googleapis.com/v0/b/static-only-2ff95.appspot.com/o/totoday%2F20230906_9BHMhQjv.png?alt=media&token=469651a2-829e-4260-a88f-8f5dc629e2a2"
width="120"
height=""
alt="alt_text"
@ -166,13 +166,14 @@
align-items: center;
"
>
<td style="width:100vw; height: auto; display: flex; justify-content: center; align-items: center; margin-bottom: 12px">
<img
src="https://res.cloudinary.com/practicaldev/image/fetch/s--1II67h1R--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://faruknasir.com/images/blog/2021/verification_url.png"
alt="verifi-piture"
width="420"
height=""
style="margin: auto"
/>
</td>
</tr>
<tr>
<td
@ -313,7 +314,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.
</td>
</tr>

25
docker/docker-compose.yml Normal file
View File

@ -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

View File

@ -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://<ip address>: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"}}

View File

@ -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://<ip address>: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}}

View File

@ -0,0 +1 @@
{"count":3,"timestamp":1703563690524}

View File

@ -0,0 +1 @@
{"userId":"658a51aa4f9cbdd4fac1f671","telemetryAnonymousId":"658a51aa4f9cbdd4fac1f671","enableTelemetry":true}

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,2 @@
WiredTiger
WiredTiger 11.2.0: (November 10, 2022)

View File

@ -0,0 +1 @@
WiredTiger lock file

View File

@ -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)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
1

Binary file not shown.

Binary file not shown.

BIN
docker/redis-data/dump.rdb Normal file

Binary file not shown.

View File

@ -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"`
}

View File

@ -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

View File

@ -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(&registerInfo)
//[ok]
//call function check info user type in
validRegisterInfo, responseAPI := services.CheckAndValidRegisterFiled(&registerInfo)
//[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(&registerInfo)
fmt.Println(registerInfo)
}
return nil
}
func AuthRouterSetup(router *mux.Router) {
authRouter := router.PathPrefix("/account").Subrouter()
authRouter.Handle("/register", utils.MakeHTTPHandlerFn(RegisterNewAccount)).Methods("POST")

View File

@ -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())

View File

@ -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 {

View File

@ -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()
}