change to use logging instead of print to stdout

This commit is contained in:
2023-04-03 12:00:01 +10:00
parent f2ac6097d6
commit 5cc67501d3
11 changed files with 88 additions and 87 deletions

View File

@@ -1,8 +1,8 @@
package controllers
import (
"fmt"
"html"
"log"
"net/http"
"strings"
@@ -39,7 +39,7 @@ func Register(c *gin.Context) {
// Default to regular user role if not specified
if input.RoleId == 0 {
fmt.Printf("Register no role specified, defaulting to RoleId of 2.\n")
log.Printf("Register no role specified, defaulting to RoleId of 2.\n")
u.RoleId = 2
} else {
u.RoleId = input.RoleId
@@ -50,9 +50,9 @@ func Register(c *gin.Context) {
// Check if user already exists
testUser, _ := models.GetUserByName(u.UserName)
fmt.Printf("Register checking if user already exists : '%v'\n", testUser)
log.Printf("Register checking if user already exists : '%v'\n", testUser)
if (models.User{} == testUser) {
fmt.Printf("Register confirmed no existing username\n")
log.Printf("Register confirmed no existing username\n")
} else {
c.JSON(http.StatusBadRequest, gin.H{"error": "Attempt to register conflicting username"})
return
@@ -64,7 +64,7 @@ func Register(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"Error hashing password": err.Error()})
return
} else {
fmt.Printf("Register generated hashed password value '%s' from '%s'\n", string(hashedPassword), input.Password)
log.Printf("Register generated hashed password value '%s' from '%s'\n", string(hashedPassword), input.Password)
}
u.Password = string(hashedPassword)
@@ -92,7 +92,7 @@ func Login(c *gin.Context) {
u.UserName = input.Username
u.Password = input.Password
fmt.Printf("Login checking username '%s' and password '%s'\n", u.UserName, u.Password)
log.Printf("Login checking username '%s' and password '%s'\n", u.UserName, u.Password)
token, err := models.LoginCheck(u.UserName, u.Password)