Skip to content

Commit

Permalink
Merge branch 'main' of github.com:LitPad/backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Xlaez committed Jan 17, 2025
2 parents d0365da + 7624bd1 commit 3692da6
Show file tree
Hide file tree
Showing 18 changed files with 509 additions and 39 deletions.
8 changes: 4 additions & 4 deletions initials/initial_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ func createSubscriptionPlans(db *gorm.DB) {
if len(plans) < 1 {
monthlyAmount, _ := decimal.NewFromString("12.99")
annualAmount, _ := decimal.NewFromString("131.88")
plans = []models.SubscriptionPlan{
models.SubscriptionPlan{Amount: monthlyAmount, SubType: choices.ST_MONTHLY},
models.SubscriptionPlan{Amount: annualAmount, SubType: choices.ST_ANNUAL},
plansToCreate := []*models.SubscriptionPlan{
{Amount: monthlyAmount, SubType: choices.ST_MONTHLY},
{Amount: annualAmount, SubType: choices.ST_ANNUAL},
}
db.Create(&plans)
db.Create(&plansToCreate)
}
}

Expand Down
4 changes: 4 additions & 0 deletions models/scopes/scopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ func FollowerFollowingPreloaderScope(db *gorm.DB) *gorm.DB {
return db.Scopes(VerifiedUserScope).Preload("Followers").Preload("Followers.Followers").Preload("Followings").Preload("Followings.Followers").Preload("Followings.Books")
}

func FollowerFollowingUnVerifiedPreloaderScope(db *gorm.DB) *gorm.DB {
return db.Preload("Followers").Preload("Followers.Followers").Preload("Followings").Preload("Followings.Followers").Preload("Followings.Books")
}

func FollowerFollowingBooksPreloaderScope(db *gorm.DB) *gorm.DB {
return db.Scopes(FollowerFollowingPreloaderScope).Preload("Books").Preload("Followers.Followers").Preload("Followings").Preload("Followings.Followers").Preload("Followings.Books")
}
Expand Down
7 changes: 3 additions & 4 deletions routes/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func (ep Endpoint) Register(c *fiber.Ctx) error {

// Create User
db.Save(&user)

// Send Email
go senders.SendEmail(&user, senders.ET_ACTIVATE, user.Otp, nil, nil)

Expand Down Expand Up @@ -200,10 +199,10 @@ func (ep Endpoint) SetNewPassword(c *fiber.Ctx) error {
return c.Status(*errCode).JSON(errData)
}

user := models.User{TokenString: &data.TokenString}
user := models.User{Email: data.Email, TokenString: &data.TokenString}
db.Take(&user, user)
if user.ID == uuid.Nil {
return c.Status(404).JSON(utils.RequestErr(utils.ERR_INCORRECT_TOKEN, "Invalid Token"))
return c.Status(404).JSON(utils.RequestErr(utils.ERR_INCORRECT_TOKEN, "Invalid Email or Token"))
}

if user.IsTokenExpired() {
Expand Down Expand Up @@ -240,7 +239,7 @@ func (ep Endpoint) Login(c *fiber.Ctx) error {
}

user := models.User{Email: data.Email}
db.Scopes(scopes.FollowerFollowingPreloaderScope).Take(&user, user)
db.Scopes(scopes.FollowerFollowingUnVerifiedPreloaderScope).Take(&user, user)
if user.ID == uuid.Nil || !utils.CheckPasswordHash(data.Password, user.Password) {
return c.Status(401).JSON(utils.RequestErr(utils.ERR_INVALID_CREDENTIALS, "Invalid Credentials"))
}
Expand Down
2 changes: 1 addition & 1 deletion routes/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var validator = utils.Validator()
func DecodeJSONBody(c *fiber.Ctx, dst interface{}) (int, *utils.ErrorResponse) {
var errData *utils.ErrorResponse
code := 200
if c.Get("Content-Type") != "application/json" {
if !strings.Contains(c.Get("Content-Type"), "application/json") {
errD := utils.RequestErr(utils.ERR_INVALID_REQUEST, "Content-Type header is not application/json")
errData = &errD
return code, errData
Expand Down
7 changes: 6 additions & 1 deletion senders/emails.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func sortEmail(cfg config.Config, emailType EmailTypeChoice, otp *uint, tokenStr
type EmailContext struct {
Name string
Url *string
Code *int
Code *uint
Text string
}

Expand All @@ -129,6 +129,11 @@ func SendEmail(user *models.User, emailType EmailTypeChoice, otp *uint, tokenStr
data.Url = &url
}

if code, ok := emailData["code"]; ok {
code := code.(*uint)
data.Code = code
}

// Read the HTML file content
_, file, _, ok := runtime.Caller(0)
if !ok {
Expand Down
16 changes: 3 additions & 13 deletions templates/email-activation.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,13 @@
style="cursor:auto;color:#737F8D;font-family:Whitney, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:18px;line-height:24px;text-align:left;">

<p><b>Hey {{.Name}},</b><br>
<p></p>
{{ .Text }}
</p>
<p>{{.Text}}</p><br>
<p style="font-weight: bold; text-align: center;"><b>{{.Code}}</b></p>
</p>

</div>
</td>
</tr>
<tr>

<td style="word-break:break-word;font-size:0px;padding:10px 25px;"
align="center">
<table role="presentation" cellpadding="0" cellspacing="0"
style="border-collapse:separate;" align="center" border="0">
<p>{{ .Code }}</p>
</table>
</td>
</tr>
<tr>

<td style="word-break:break-word;font-size:0px;padding:10px 25px;"
Expand Down
2 changes: 1 addition & 1 deletion templates/password-reset-success.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@

<p><b>Hey {{.Name}},</b><br>
<p></p>
{{ .Text }}</p>
{{.Text}}</p>
</div>
</td>
</tr>
Expand Down
4 changes: 2 additions & 2 deletions templates/password-reset.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@

<p><b>Hey {{.Name}},</b><br>
<p></p>
{{ .Text }}</p>
{{.Text}}</p>

</div>
</td>
Expand All @@ -209,7 +209,7 @@
<table role="presentation" cellpadding="0" cellspacing="0"
style="border-collapse:separate;" align="center" border="0">
<p style="font-style: italic; font-size: 13px; color: #737F8D;">OR: Copy the following link to your browser</p><br>
<a href="{{ .Url }}" style="font-style: italic; font-size: 13px;">{{ .Url }}</a><br>
<a href="{{.Url}}" style="font-style: italic; font-size: 13px;">{{.Url}}</a><br>
</table>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion templates/payment-canceled.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@

<p><b>Hey {{.Name}},</b><br>
<p></p>
{{ .Text }}.</p>
{{.Text}}.</p>
</div>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion templates/payment-failed.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@

<p><b>Hey {{.Name}},</b><br>
<p></p>
{{ .Text }}.</p>
{{.Text}}.</p>
</div>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion templates/payment-success.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@

<p><b>Hey {{.Name}},</b><br>
<p></p>
{{ .Text }}.</p>
{{.Text}}.</p>
</div>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion templates/subscription-expired.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@

<p><b>Hey {{.Name}},</b><br>
<p></p>
{{ .Text }}</p>
{{.Text}}</p>

</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion templates/subscription-expiring.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@

<p><b>Hey {{.Name}},</b><br>
<p></p>
{{ .Text }}</p>
{{.Text}}</p>

</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion templates/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@

<p><b>Hey {{.Name}},</b><br>
<p></p>
{{ .Text }}</p>
{{.Text}}</p>

</div>
</td>
Expand Down
Loading

0 comments on commit 3692da6

Please sign in to comment.