fix error at route
This commit is contained in:
1 parent
ed6776df74
commit
ad8a9c2fa3
8 files changed
+217
-126
No files matched your search
+8
-8
@@ -136,8 +136,8 @@ func DecryptAESMailLink(linkVerifyInfo *models.LinkVerify, w http.ResponseWriter
|
||||
|
||||
//OTP+++++++++++++OTP//
|
||||
|
||||
// Gen Otp and hash otp
|
||||
func GenOTP(registerInfo *models.PreusersMongo, counter uint64, otpDigits int, w http.ResponseWriter, otpChan chan models.OtpGenerate, wg *sync.WaitGroup) chan models.OtpGenerate {
|
||||
// Gen OTP and hash OTP
|
||||
func GenOTP(registerInfo *models.PreusersMongo, counter uint64, otpDigits int, w http.ResponseWriter, otpChan chan models.OtpGenerate, errorChan error, ctxCancel context.CancelFunc, wg *sync.WaitGroup) {
|
||||
|
||||
serectBase32 := base32.StdEncoding.EncodeToString([]byte(serect + registerInfo.UUID + registerInfo.Email))
|
||||
passCode, err := hotp.GenerateCodeCustom(serectBase32, counter, hotp.ValidateOpts{
|
||||
@@ -146,14 +146,18 @@ func GenOTP(registerInfo *models.PreusersMongo, counter uint64, otpDigits int, w
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
errorChan = errors.New("fail to create OTP")
|
||||
ctxCancel()
|
||||
wg.Done()
|
||||
fmt.Println("Internal log: Fail to create OTP")
|
||||
_ = WriteJSONInternalError(w, "Fail to create OTP")
|
||||
}
|
||||
|
||||
hashed, err := bcrypt.GenerateFromPassword([]byte(passCode), 5)
|
||||
if err != nil {
|
||||
errorChan = errors.New("fail to encrypt OTP")
|
||||
ctxCancel()
|
||||
wg.Done()
|
||||
fmt.Println("Internal log: Fail to encrypt OTP")
|
||||
_ = WriteJSONInternalError(w, "Fail to encrypt OTP")
|
||||
}
|
||||
|
||||
data := models.OtpGenerate{
|
||||
@@ -162,10 +166,6 @@ func GenOTP(registerInfo *models.PreusersMongo, counter uint64, otpDigits int, w
|
||||
}
|
||||
|
||||
otpChan <- data
|
||||
otpChan <- data
|
||||
wg.Done()
|
||||
return otpChan
|
||||
|
||||
}
|
||||
|
||||
//Decrypt OTP and verify otp
|
||||
|
||||
@@ -19,6 +19,7 @@ func WriteJSON(w http.ResponseWriter, status int, v any) error {
|
||||
|
||||
func WriteJSONInternalError(w http.ResponseWriter, v any) error {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
err := json.NewEncoder(w).Encode(v)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user