-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
45 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 |
---|---|---|
@@ -1,31 +1 @@ | ||
package login | ||
|
||
import ( | ||
"github.com/gin-contrib/sessions" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func login(c *gin.Context) { | ||
// Assume the user is authenticated | ||
session := sessions.Default(c) | ||
session.Set("authenticated", true) | ||
err := session.Save() | ||
if err != nil { | ||
return | ||
} | ||
c.JSON(200, gin.H{"message": "authenticated"}) | ||
} | ||
|
||
func secureEndpoint(c *gin.Context) { | ||
if !isLoggedIn(c) { | ||
c.JSON(401, gin.H{"message": "unauthorized"}) | ||
return | ||
} | ||
c.JSON(200, gin.H{"message": "Hello, authorized user!"}) | ||
} | ||
|
||
func isLoggedIn(c *gin.Context) bool { | ||
session := sessions.Default(c) | ||
authenticated := session.Get("authenticated") | ||
return authenticated != nil && authenticated.(bool) | ||
} |
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,46 @@ | ||
package email | ||
|
||
// SendWelcomeMessage sends a welcome message to a new user | ||
func SendWelcomeMessage(username, url, recipient string) error { | ||
message := Message{ | ||
Header: "My App Africa", | ||
UsersName: username, | ||
Introduction: "Hey" + username + ", Welcome to My App Africa", | ||
Content: "Thank you for signing up recipient My App Africa. Please click the link below recipient activate your account.", | ||
URL: url, | ||
Action: "Activate Account", | ||
} | ||
body, err := LoadEmail(message) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = SendEmail(recipient, "Welcome to My App Africa", body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// SendPassWordResetMessage sends a password reset message to a user | ||
func SendPassWordResetMessage(username, url, recipient string) error { | ||
message := Message{ | ||
Header: "My App Africa", | ||
UsersName: username, | ||
Introduction: "Hey" + username, | ||
Content: "You have requested to reset your password. Please click the link below to reset your password.", | ||
URL: url, | ||
Action: "Reset Password", | ||
} | ||
body, err := LoadEmail(message) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = SendEmail(recipient, "Welcome to My App Africa", body) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |