Updating logs from fmt to package log
This commit is contained in:
@@ -5,6 +5,7 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
@@ -79,7 +80,7 @@ func UserSignup() gin.HandlerFunc {
|
|||||||
|
|
||||||
if err := u.Create(); err != nil {
|
if err := u.Create(); err != nil {
|
||||||
if err.Error() != "UNIQUE constraint failed: users.email" {
|
if err.Error() != "UNIQUE constraint failed: users.email" {
|
||||||
fmt.Println(fmt.Errorf("error: %w", err))
|
log.Println(fmt.Errorf("error: %w", err))
|
||||||
c.AbortWithStatus(http.StatusInternalServerError)
|
c.AbortWithStatus(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
@@ -147,7 +148,7 @@ func UserLogin() gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if loginVals.TwoFactor != "" && !checkTwoFactorNotReused(&u.Auth, loginVals.TwoFactor) {
|
if loginVals.TwoFactor != "" && !checkTwoFactorNotReused(&u.Auth, loginVals.TwoFactor) {
|
||||||
fmt.Printf("WARNING: two factor code %v reused for %v\n", loginVals.TwoFactor, u.Uid)
|
log.Printf("WARNING: two factor code %v reused for %v\n", loginVals.TwoFactor, u.Uid)
|
||||||
c.AbortWithStatusJSON(http.StatusUnauthorized, util.FailMsg{Reason: "2fa reused"})
|
c.AbortWithStatusJSON(http.StatusUnauthorized, util.FailMsg{Reason: "2fa reused"})
|
||||||
<-minTime
|
<-minTime
|
||||||
return
|
return
|
||||||
@@ -178,7 +179,7 @@ func UserVerify() gin.HandlerFunc {
|
|||||||
|
|
||||||
claims, err := util.ParseJwt(verifyJwt, models.UserHmac)
|
claims, err := util.ParseJwt(verifyJwt, models.UserHmac)
|
||||||
if err != nil || claims["role"] != "verify" {
|
if err != nil || claims["role"] != "verify" {
|
||||||
fmt.Println("bad claim or role not 'verify'", err)
|
log.Println("bad claim or role not 'verify'", err)
|
||||||
c.AbortWithStatus(http.StatusUnauthorized)
|
c.AbortWithStatus(http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -186,7 +187,7 @@ func UserVerify() gin.HandlerFunc {
|
|||||||
// Yay! Jwt is a verify token, let's verify the linked user
|
// Yay! Jwt is a verify token, let's verify the linked user
|
||||||
uid, err := uuid.Parse(claims["sub"].(string))
|
uid, err := uuid.Parse(claims["sub"].(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("sub should ALWAYS be valid uuid at this point??", err)
|
log.Println("sub should ALWAYS be valid uuid at this point??", err)
|
||||||
c.AbortWithStatus(http.StatusUnauthorized)
|
c.AbortWithStatus(http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -199,7 +200,7 @@ func UserVerify() gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := database.Db.Find(&verifying).Error; err != nil {
|
if err := database.Db.Find(&verifying).Error; err != nil {
|
||||||
fmt.Println("could not find user", err)
|
log.Println("could not find user", err)
|
||||||
c.AbortWithStatus(http.StatusUnauthorized)
|
c.AbortWithStatus(http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -212,7 +213,7 @@ func UserVerify() gin.HandlerFunc {
|
|||||||
|
|
||||||
verifying.Verified = true
|
verifying.Verified = true
|
||||||
if err := verifying.Save(); err != nil {
|
if err := verifying.Save(); err != nil {
|
||||||
fmt.Println("could not verify user", err)
|
log.Println("could not verify user", err)
|
||||||
c.AbortWithStatus(http.StatusInternalServerError)
|
c.AbortWithStatus(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -273,14 +274,14 @@ func UserResetForgottenPassword() gin.HandlerFunc {
|
|||||||
|
|
||||||
claims, err := util.ParseJwt(resetVals.Token, models.UserHmac)
|
claims, err := util.ParseJwt(resetVals.Token, models.UserHmac)
|
||||||
if err != nil || claims["role"] != "reset" {
|
if err != nil || claims["role"] != "reset" {
|
||||||
fmt.Println("bad claim or role not 'reset'", err)
|
log.Println("bad claim or role not 'reset'", err)
|
||||||
c.AbortWithStatus(http.StatusUnauthorized)
|
c.AbortWithStatus(http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uid, err := uuid.Parse(claims["sub"].(string))
|
uid, err := uuid.Parse(claims["sub"].(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("sub should ALWAYS be valid uuid at this point??", err)
|
log.Println("sub should ALWAYS be valid uuid at this point??", err)
|
||||||
c.AbortWithStatus(http.StatusUnauthorized)
|
c.AbortWithStatus(http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -293,14 +294,15 @@ func UserResetForgottenPassword() gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := database.Db.Find(&resetting).Error; err != nil {
|
if err := database.Db.Find(&resetting).Error; err != nil {
|
||||||
fmt.Println("could not find user", err)
|
log.Println("could not find user", err)
|
||||||
c.AbortWithStatus(http.StatusUnauthorized)
|
c.AbortWithStatus(http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resetting.SetPassword(resetVals.NewPassword)
|
resetting.SetPassword(resetVals.NewPassword)
|
||||||
if err := resetting.Save(); err != nil {
|
if err := resetting.Save(); err != nil {
|
||||||
fmt.Println("could not save user", err)
|
log.
|
||||||
|
log.Error("could not save user", err)
|
||||||
c.AbortWithStatus(http.StatusUnauthorized)
|
c.AbortWithStatus(http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -354,7 +356,7 @@ func AdminLogin() gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if loginVals.TwoFactor != "" && !checkTwoFactorNotReused(&a.Auth, loginVals.TwoFactor) {
|
if loginVals.TwoFactor != "" && !checkTwoFactorNotReused(&a.Auth, loginVals.TwoFactor) {
|
||||||
fmt.Printf("WARNING: two factor code %v reused by admin %v\n", loginVals.TwoFactor, a.Uid)
|
log.Printf("WARNING: two factor code %v reused by admin %v\n", loginVals.TwoFactor, a.Uid)
|
||||||
c.AbortWithStatusJSON(http.StatusUnauthorized, util.FailMsg{Reason: "2fa reused"})
|
c.AbortWithStatusJSON(http.StatusUnauthorized, util.FailMsg{Reason: "2fa reused"})
|
||||||
<-minTime
|
<-minTime
|
||||||
return
|
return
|
||||||
@@ -381,7 +383,7 @@ func genericAuth(expectedRole string, hmac []byte) gin.HandlerFunc {
|
|||||||
if strings.HasPrefix(err.Error(), "token ") || err.Error() == "signature is invalid" {
|
if strings.HasPrefix(err.Error(), "token ") || err.Error() == "signature is invalid" {
|
||||||
c.AbortWithStatusJSON(http.StatusUnauthorized, util.FailMsg{Reason: err.Error()})
|
c.AbortWithStatusJSON(http.StatusUnauthorized, util.FailMsg{Reason: err.Error()})
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(err)
|
log.Println(err)
|
||||||
c.AbortWithStatusJSON(http.StatusInternalServerError, util.FailMsg{Reason: "something went wrong"})
|
c.AbortWithStatusJSON(http.StatusInternalServerError, util.FailMsg{Reason: "something went wrong"})
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
@@ -37,7 +37,7 @@ func (b *bucket) take(resource string) bool {
|
|||||||
|
|
||||||
if !regexMatched {
|
if !regexMatched {
|
||||||
// Default to Global
|
// Default to Global
|
||||||
fmt.Printf("defaulting %v to global\n", resource)
|
log.Printf("defaulting %v to global\n", resource)
|
||||||
resource = ""
|
resource = ""
|
||||||
r = (*b.rules)[resource]
|
r = (*b.rules)[resource]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package scheduled
|
package scheduled
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ type Scheduled func() (string, time.Duration)
|
|||||||
|
|
||||||
func ExecuteImmediatelyAndSchedule(f Scheduled) {
|
func ExecuteImmediatelyAndSchedule(f Scheduled) {
|
||||||
print, wait := f()
|
print, wait := f()
|
||||||
fmt.Println(print)
|
log.Println(print)
|
||||||
|
|
||||||
go ExecuteWithDelayAndSchedule(f, wait)
|
go ExecuteWithDelayAndSchedule(f, wait)
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ func ExecuteWithDelayAndSchedule(f Scheduled, wait time.Duration) {
|
|||||||
time.Sleep(wait)
|
time.Sleep(wait)
|
||||||
|
|
||||||
print, nextWait := f()
|
print, nextWait := f()
|
||||||
fmt.Println(print)
|
log.Println(print)
|
||||||
|
|
||||||
go ExecuteWithDelayAndSchedule(f, nextWait)
|
go ExecuteWithDelayAndSchedule(f, nextWait)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package util
|
|||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -32,7 +33,7 @@ type NextMsg struct {
|
|||||||
|
|
||||||
func SendEmail(title string, body string, recipients []string) {
|
func SendEmail(title string, body string, recipients []string) {
|
||||||
//TODO
|
//TODO
|
||||||
fmt.Println("Send", title, body, "to", recipients)
|
log.Println("Send", title, body, "to", recipients)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseJwt(tokenStr string, hmac []byte) (jwt.MapClaims, error) {
|
func ParseJwt(tokenStr string, hmac []byte) (jwt.MapClaims, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user