diff --git a/controller/admin_controller.go b/controller/admin_controller.go index 78ceed0..f5874d8 100644 --- a/controller/admin_controller.go +++ b/controller/admin_controller.go @@ -1,7 +1,10 @@ package controller import ( + "net/http" + "github.com/gin-gonic/gin" + ginsession "github.com/go-session/gin-session" ) type TableData struct { @@ -9,13 +12,13 @@ type TableData struct { } func HandleAdmin(ctx *gin.Context) { - // store := ginsession.FromContext(ctx) - // _, ok := store.Get("user") - // if !ok { - // // User is not logged in, redirect them to the login page - // ctx.Redirect(http.StatusTemporaryRedirect, "/login") - // return - // } + store := ginsession.FromContext(ctx) + _, ok := store.Get("user") + if !ok { + // User is not logged in, redirect them to the login page + ctx.Redirect(http.StatusTemporaryRedirect, "/login") + return + } ctx.HTML(200, "admin.html", nil) } diff --git a/controller/login_controller.go b/controller/login_controller.go index 214b318..27f1d9d 100644 --- a/controller/login_controller.go +++ b/controller/login_controller.go @@ -10,13 +10,13 @@ import ( ) func HandleLogin(ctx *gin.Context) { - // store := ginsession.FromContext(ctx) - // _, ok := store.Get("user") - // if ok { - // // User is not logged in, redirect them to the login page - // ctx.Redirect(http.StatusTemporaryRedirect, "/") - // return - // } + store := ginsession.FromContext(ctx) + _, ok := store.Get("user") + if ok { + // User is not logged in, redirect them to the login page + ctx.Redirect(http.StatusTemporaryRedirect, "/") + return + } ctx.HTML(200, "login.html", nil) } diff --git a/controller/search_controller.go b/controller/search_controller.go index bc5eda2..72ed194 100644 --- a/controller/search_controller.go +++ b/controller/search_controller.go @@ -8,13 +8,25 @@ import ( func HandleSearch(ctx *gin.Context) { searchQuery := ctx.PostForm("search-input") + exact := ctx.Query("exact") + var data internal.PageData - if searchQuery == "" { - HandleQueue(ctx) - return - } + if exact == "true" { + + sourceCreds := internal.Credentials{ + Server: ctx.Query("source_server"), + Account: ctx.Query("source_account"), + } + destCreds := internal.Credentials{ + Server: ctx.Query("destination_server"), + Account: ctx.Query("destination_account"), + } - data := internal.GetSearchData(searchQuery) + data = internal.GetSearchData("", true, sourceCreds, destCreds) + } else { + + data = internal.GetSearchData(searchQuery, false, internal.Credentials{}, internal.Credentials{}) + } ctx.HTML(200, "tbody.html", data) } diff --git a/internal/search.go b/internal/search.go index 4946be0..b6282c7 100644 --- a/internal/search.go +++ b/internal/search.go @@ -7,8 +7,13 @@ import ( "github.com/lithammer/fuzzysearch/fuzzy" ) -func GetSearchData(searchQuery string) PageData { - results := searchInQueue(searchQuery) +func GetSearchData(searchQuery string, isExact bool, sourceDetails, destinationDetails Credentials) PageData { + var results []*Task + if isExact { + results = searchExactCredentials(sourceDetails, destinationDetails) + } else { + results = searchInQueue(searchQuery) + } data := PageData{ Index: 1, @@ -69,10 +74,8 @@ func searchExactCredentials(sourceDetails, destinationDetails Credentials) []*Ta task := e.Value.(*Task) if task.SourceAccount == sourceDetails.Account && task.SourceServer == sourceDetails.Server && - task.SourcePassword == sourceDetails.Password && task.DestinationAccount == destinationDetails.Account && - task.DestinationServer == destinationDetails.Server && - task.DestinationPassword == destinationDetails.Password { + task.DestinationServer == destinationDetails.Server { results = append(results, task) } } diff --git a/internal/sync_loop.go b/internal/sync_loop.go index 2e6e4b4..c59c7c3 100644 --- a/internal/sync_loop.go +++ b/internal/sync_loop.go @@ -16,8 +16,8 @@ func processPendingTasks() { continue } - //syncIMAP(task) - simulateTask(task) + syncIMAP(task) + // simulateTask(task) time.Sleep(100 * time.Millisecond) } } diff --git a/templates/admin_navbar.html b/templates/admin_navbar.html index c1affd5..a8eb95e 100644 --- a/templates/admin_navbar.html +++ b/templates/admin_navbar.html @@ -6,7 +6,7 @@
diff --git a/templates/index.html b/templates/index.html index 17c360e..9825843 100644 --- a/templates/index.html +++ b/templates/index.html @@ -64,12 +64,12 @@Index | -Source Server | -Source Account | -Destination Server | -Destination Account | -Status | -Actions | -
---|