Adding encryption package to encrypt email
This commit is contained in:
		@ -3,6 +3,7 @@ package main
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"myapp/internal/cards"
 | 
			
		||||
	"myapp/internal/cards/encryption"
 | 
			
		||||
	"myapp/internal/models"
 | 
			
		||||
	"myapp/internal/urlsigner"
 | 
			
		||||
	"net/http"
 | 
			
		||||
@ -328,6 +329,7 @@ func (app *application) ForgotPassword(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *application) ShowResetPassword(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	email := r.URL.Query().Get("email")
 | 
			
		||||
	theURL := r.RequestURI
 | 
			
		||||
	testURL := fmt.Sprintf("%s%s", app.config.frontend, theURL)
 | 
			
		||||
 | 
			
		||||
@ -347,8 +349,18 @@ func (app *application) ShowResetPassword(w http.ResponseWriter, r *http.Request
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	encryptor := encryption.Encryption{
 | 
			
		||||
		Key: []byte(app.config.secretkey),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	encryptedEmail, err := encryptor.Encrypt(email)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		app.errorLog.Println("Encryption failed", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	data := make(map[string]interface{})
 | 
			
		||||
	data["email"] = r.URL.Query().Get("email")
 | 
			
		||||
	data["email"] = encryptedEmail
 | 
			
		||||
	if err := app.renderTemplate(w, r, "reset-password", &templateData{
 | 
			
		||||
		Data: data,
 | 
			
		||||
	}); err != nil {
 | 
			
		||||
 | 
			
		||||
@ -85,7 +85,7 @@ func main() {
 | 
			
		||||
		"DSN",
 | 
			
		||||
	)
 | 
			
		||||
	flag.StringVar(&cfg.api, "api", "http://localhost:4001", "URL to api")
 | 
			
		||||
	flag.StringVar(&cfg.secretkey, "secret", "secRetKeY", "secret key")
 | 
			
		||||
	flag.StringVar(&cfg.secretkey, "secretkey", "b47df3d8380241c1177f13bdd69c6a60", "secret key")
 | 
			
		||||
	flag.StringVar(&cfg.frontend, "frontend", "http://localhost:4000", "frontend address")
 | 
			
		||||
 | 
			
		||||
	flag.Parse()
 | 
			
		||||
 | 
			
		||||
@ -34,8 +34,15 @@ Forgot Password
 | 
			
		||||
{{define "js"}}
 | 
			
		||||
<script type="module">
 | 
			
		||||
    import {forgot} from "/static/js/login.js"
 | 
			
		||||
    document.getElementById("reset-btn").addEventListener("click", () => {
 | 
			
		||||
    document.getElementById("reset-btn").addEventListener("click", (event) => {
 | 
			
		||||
        event.preventDefault();
 | 
			
		||||
        forgot({{.API}});
 | 
			
		||||
    })
 | 
			
		||||
    document.getElementById("email").addEventListener("keypress", (event) => {
 | 
			
		||||
        if (event.key === "Enter") {
 | 
			
		||||
            event.preventDefault();
 | 
			
		||||
            forgot({{.API}});
 | 
			
		||||
        }
 | 
			
		||||
    })
 | 
			
		||||
</script>
 | 
			
		||||
{{end}}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user