fix: add location middleware to get exact host

This commit is contained in:
Lakhan Samani
2021-08-04 15:55:13 +05:30
parent f88363e6dc
commit 104adfea1d
21 changed files with 102 additions and 70 deletions

View File

@@ -12,7 +12,7 @@ func SetCookie(gc *gin.Context, token string) {
secure := true
httpOnly := true
host := GetHostName(gc.Request.Host)
host := GetHostName(constants.AUTHORIZER_URL)
log.Println("=> cookie host", host)
gc.SetSameSite(http.SameSiteNoneMode)
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", host, secure, httpOnly)
@@ -35,7 +35,7 @@ func DeleteCookie(gc *gin.Context) {
secure = false
}
host := GetHostName(gc.Request.Host)
host := GetHostName(constants.AUTHORIZER_URL)
gc.SetSameSite(http.SameSiteNoneMode)
gc.SetCookie(constants.COOKIE_NAME, "", -1, "/", host, secure, httpOnly)
}

View File

@@ -34,12 +34,17 @@ func SendVerificationMail(toEmail, token string) error {
// SendForgotPasswordMail to send verification email
func SendForgotPasswordMail(toEmail, token, host string) error {
if constants.RESET_PASSWORD_URL == "" {
constants.RESET_PASSWORD_URL = constants.AUTHORIZER_URL + "/app/reset-password"
}
sender := email.NewSender()
// The receiver needs to be in slice as the receive supports multiple receiver
Receiver := []string{toEmail}
Subject := "Reset Password"
message := fmt.Sprintf(`
<!DOCTYPE HTML PULBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
@@ -51,7 +56,7 @@ func SendForgotPasswordMail(toEmail, token, host string) error {
<a href="%s">Reset Password</a>
</body>
</html>
`, host+"/"+constants.FORGOT_PASSWORD_URI+"?token="+token)
`, constants.RESET_PASSWORD_URL+"?token="+token)
bodyMessage := sender.WriteHTMLEmail(Receiver, Subject, message)
return sender.SendMail(Receiver, Subject, bodyMessage)

View File

@@ -19,7 +19,7 @@ type CustomClaim struct {
}
// TODO convert tokenType to enum
func CreateVerificationToken(email string, tokenType string, host string) (string, error) {
func CreateVerificationToken(email string, tokenType string) (string, error) {
t := jwt.New(jwt.GetSigningMethod(constants.JWT_TYPE))
t.Claims = &CustomClaim{
@@ -28,7 +28,7 @@ func CreateVerificationToken(email string, tokenType string, host string) (strin
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
},
tokenType,
UserInfo{Email: email, Host: host},
UserInfo{Email: email, Host: constants.AUTHORIZER_URL},
}
return t.SignedString([]byte(constants.JWT_SECRET))