-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* complete password registration flow * dont load .env on prod * use TLS in db conn * fix not use SSL * add error logs + better error http response scheme * add config object * tryna see resend_api_key issues * woops * use resend api key from config * don't log it cmon
- Loading branch information
Showing
37 changed files
with
1,686 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# flyctl launch added from .gitignore | ||
**/.idea | ||
**/bin | ||
**/.env | ||
**/gin-bin | ||
fly.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Use the official Go base image | ||
FROM golang:1.20 AS build | ||
|
||
# Set the working directory inside the container | ||
WORKDIR /app | ||
|
||
# Copy the Go application source code into the container | ||
COPY . . | ||
|
||
# Build the Go application | ||
RUN go build -o /supernova | ||
|
||
# Expose the port that the Go application will listen on | ||
EXPOSE 3001 | ||
|
||
# Define the command to run your Go application | ||
CMD ["/supernova"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package db | ||
|
||
import ( | ||
"github.com/redis/go-redis/v9" | ||
"github.com/trysupernova/supernova-api/utils" | ||
) | ||
|
||
var Redis *redis.Client | ||
|
||
func SetupRedis() *redis.Client { | ||
Redis = redis.NewClient(&redis.Options{ | ||
Addr: utils.GetConfig().REDIS_URL, | ||
Password: utils.GetConfig().REDIS_PASSWORD, | ||
DB: 0, | ||
}) | ||
return Redis | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package email | ||
|
||
import "github.com/trysupernova/supernova-api/utils" | ||
|
||
const ( | ||
ErrEmailSendFailed utils.AppErrorType = "email_send_failed" | ||
ErrEmailCompileFailed utils.AppErrorType = "email_compile_failed" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package email | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"embed" | ||
"text/template" | ||
|
||
"github.com/Boostport/mjml-go" | ||
"github.com/resendlabs/resend-go" | ||
"github.com/trysupernova/supernova-api/utils" | ||
) | ||
|
||
type EmailClient struct{} | ||
|
||
func New() *EmailClient { | ||
return &EmailClient{} | ||
} | ||
|
||
type EmailSend struct { | ||
From string | ||
To []string | ||
Subject string | ||
Body string | ||
ReplyTo string | ||
} | ||
|
||
func (e *EmailClient) SendEmail(send EmailSend) (string, error) { | ||
apiKey := utils.GetConfig().RESEND_API_KEY | ||
client := resend.NewClient(apiKey) | ||
params := &resend.SendEmailRequest{ | ||
To: send.To, | ||
From: send.From, | ||
Html: send.Body, | ||
Subject: send.Subject, | ||
ReplyTo: send.ReplyTo, | ||
} | ||
|
||
sent, err := client.Emails.Send(params) | ||
if err != nil { | ||
return "", utils.NewAppError(ErrEmailSendFailed, "Failed to send email: "+err.Error()) | ||
} | ||
return sent.Id, nil | ||
} | ||
|
||
//go:embed templates/* | ||
var resources embed.FS | ||
|
||
var tmpl = template.Must(template.ParseFS(resources, "templates/*")) | ||
|
||
func CompileEmailForgotPassword(resetUrl string) (string, error) { | ||
// open a file | ||
// read the contents of the file into a string | ||
var result bytes.Buffer | ||
err := tmpl.Execute(&result, struct { | ||
Url string | ||
}{ | ||
Url: resetUrl, | ||
}) | ||
if err != nil { | ||
return "", err | ||
} | ||
renderedMjml := result.String() | ||
renderedHtml, err := mjml.ToHTML(context.Background(), renderedMjml, mjml.WithMinify(true)) | ||
if err != nil { | ||
return "", utils.NewAppError(ErrEmailSendFailed, "Failed to compile email template to HTML: "+err.Error()) | ||
} | ||
return renderedHtml, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<mjml> | ||
<mj-body> | ||
<mj-section> | ||
<mj-column> | ||
<mj-text font-size="20px" color="#F45E43" font-family="helvetica">Forgot your password?</mj-text> | ||
<mj-text>Please click on the following link to reset your password:</mj-text> | ||
<mj-text> | ||
<a href="{{ .Url }}" target="_blank">Reset Password</a> | ||
</mj-text> | ||
</mj-column> | ||
</mj-section> | ||
</mj-body> | ||
</mjml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<mjml> | ||
<mj-body> | ||
<mj-section> | ||
<mj-column> | ||
<mj-divider border-color="#F45E43"></mj-divider> | ||
|
||
<mj-text font-size="20px" color="#F45E43" font-family="helvetica">Hello World</mj-text> | ||
|
||
</mj-column> | ||
</mj-section> | ||
</mj-body> | ||
</mjml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.