refactor: call database functions from app.Server.Database instead of directly from db
This commit is contained in:
@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/fossyy/filekeeper/app"
|
||||
"github.com/fossyy/filekeeper/cache"
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
googleOauthSetupHandler "github.com/fossyy/filekeeper/handler/auth/google/setup"
|
||||
signinHandler "github.com/fossyy/filekeeper/handler/signin"
|
||||
"github.com/fossyy/filekeeper/session"
|
||||
@ -145,7 +144,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !db.DB.IsEmailRegistered(oauthUser.Email) {
|
||||
if !app.Server.Database.IsEmailRegistered(oauthUser.Email) {
|
||||
code := utils.GenerateRandomString(64)
|
||||
googleOauthSetupHandler.SetupUser[code] = &googleOauthSetupHandler.UnregisteredUser{
|
||||
Code: code,
|
||||
|
@ -3,7 +3,6 @@ package googleOauthSetupHandler
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fossyy/filekeeper/app"
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
signinHandler "github.com/fossyy/filekeeper/handler/signin"
|
||||
"github.com/fossyy/filekeeper/session"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
@ -112,7 +111,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
||||
Password: hashedPassword,
|
||||
}
|
||||
|
||||
err = db.DB.CreateUser(&newUser)
|
||||
err = app.Server.Database.CreateUser(&newUser)
|
||||
if err != nil {
|
||||
component := signupView.Main("Filekeeper - Sign up Page", types.Message{
|
||||
Code: 0,
|
||||
|
@ -5,14 +5,13 @@ import (
|
||||
"github.com/fossyy/filekeeper/view/client/download"
|
||||
"net/http"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
)
|
||||
|
||||
func GET(w http.ResponseWriter, r *http.Request) {
|
||||
userSession := r.Context().Value("user").(types.User)
|
||||
files, err := db.DB.GetFiles(userSession.UserID.String())
|
||||
files, err := app.Server.Database.GetFiles(userSession.UserID.String())
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -5,13 +5,11 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
)
|
||||
|
||||
func GET(w http.ResponseWriter, r *http.Request) {
|
||||
fileID := r.PathValue("id")
|
||||
file, err := db.DB.GetFile(fileID)
|
||||
file, err := app.Server.Database.GetFile(fileID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
|
@ -3,7 +3,6 @@ package forgotPasswordVerifyHandler
|
||||
import (
|
||||
"github.com/fossyy/filekeeper/app"
|
||||
"github.com/fossyy/filekeeper/cache"
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
forgotPasswordHandler "github.com/fossyy/filekeeper/handler/forgotPassword"
|
||||
"github.com/fossyy/filekeeper/session"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
@ -83,7 +82,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = db.DB.UpdateUserPassword(data.User.Email, hashedPassword)
|
||||
err = app.Server.Database.UpdateUserPassword(data.User.Email, hashedPassword)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
"github.com/fossyy/filekeeper/types/models"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
@ -102,7 +101,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
||||
Password: hashedPassword,
|
||||
}
|
||||
|
||||
if registered := db.DB.IsUserRegistered(userEmail, username); registered {
|
||||
if registered := app.Server.Database.IsUserRegistered(userEmail, username); registered {
|
||||
component := signupView.Main("Filekeeper - Sign up Page", types.Message{
|
||||
Code: 0,
|
||||
Message: "Email or Username has been registered",
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
signupView "github.com/fossyy/filekeeper/view/client/signup"
|
||||
"net/http"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
signupHandler "github.com/fossyy/filekeeper/handler/signup"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
)
|
||||
@ -19,7 +18,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := db.DB.CreateUser(data.User)
|
||||
err := app.Server.Database.CreateUser(data.User)
|
||||
if err != nil {
|
||||
component := signupView.Main("Filekeeper - Sign up Page", types.Message{
|
||||
Code: 0,
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
"github.com/fossyy/filekeeper/types/models"
|
||||
"github.com/google/uuid"
|
||||
@ -93,7 +92,7 @@ func handleNewUpload(user types.User, file types.FileInfo) (models.File, error)
|
||||
Done: false,
|
||||
}
|
||||
|
||||
err = db.DB.CreateFile(&newFile)
|
||||
err = app.Server.Database.CreateFile(&newFile)
|
||||
if err != nil {
|
||||
app.Server.Logger.Error(err.Error())
|
||||
return models.File{}, err
|
||||
|
@ -1,8 +1,8 @@
|
||||
package userHandlerResetPassword
|
||||
|
||||
import (
|
||||
"github.com/fossyy/filekeeper/app"
|
||||
"github.com/fossyy/filekeeper/cache"
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/session"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
@ -31,7 +31,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = db.DB.UpdateUserPassword(user.Email, hashPassword)
|
||||
err = app.Server.Database.UpdateUserPassword(user.Email, hashPassword)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -4,13 +4,13 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/fossyy/filekeeper/app"
|
||||
"github.com/fossyy/filekeeper/cache"
|
||||
"github.com/fossyy/filekeeper/view/client/user/totp"
|
||||
"image/png"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
"github.com/skip2/go-qrcode"
|
||||
"github.com/xlzd/gotp"
|
||||
@ -71,7 +71,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if totp.Verify(code, time.Now().Unix()) {
|
||||
if err := db.DB.InitializeTotp(userSession.Email, secret); err != nil {
|
||||
if err := app.Server.Database.InitializeTotp(userSession.Email, secret); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user