-
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.
Fixed bug in AddUser function in the loginDatabase. Also added signup…
… functionality and the function for it in the loginController
- Loading branch information
Showing
5 changed files
with
36 additions
and
16 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,16 +1,35 @@ | ||
package controller | ||
|
||
import ( | ||
"TODO/models" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
|
||
"TODO/database" | ||
"TODO/models" | ||
"fmt" | ||
) | ||
|
||
// This function will be called through the JS and handle any signup requirements | ||
// the c variable here contains all the required credentials | ||
func Signup(c *fiber.Ctx) error { | ||
func Signup(ctx *fiber.Ctx) error { | ||
var creds models.User | ||
return c.Status(fiber.StatusOK).JSON(fiber.Map{ | ||
"success": true, | ||
}) | ||
// First we need to parse the variable ctx to receive the credentials | ||
err := ctx.BodyParser(&creds) | ||
if err != nil { | ||
fmt.Println("Error with parsing credentials") | ||
} | ||
|
||
// Once we have the required data, we need to make sure the user isn't a duplicate | ||
err = database.AddUser(creds) | ||
if err != nil { | ||
// In this case, we know the user is a duplicate, so we returen an error message | ||
return ctx.Status(fiber.StatusOK).JSON(fiber.Map{ | ||
"success": false, | ||
"message": "User already exists. Please login or use a different email address.", | ||
}) | ||
} else { | ||
return ctx.Status(fiber.StatusOK).JSON(fiber.Map{ | ||
"success": true, | ||
"message": "Account created.", | ||
}) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -48,5 +48,5 @@ func main() { | |
}) | ||
}) | ||
|
||
app.Listen(":8080") | ||
app.Listen("127.0.0.1:8080") | ||
} |
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