Skip to content

Commit

Permalink
Mail syncing working, TODO fix bugs on frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
xeome committed Sep 28, 2023
1 parent 1bab65a commit fe6cdad
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tmp

imap-sync
LOG_imapsync
1 change: 0 additions & 1 deletion internal/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func InitServer() {
router.GET("/api/pagination", handlePagination)
router.POST("/api/validate", handleValidate)
router.POST("/api/search", handleSearch)
router.POST("/api/sync", handleSync)

log.Info("Server starting on http://localhost:" + *port)

Expand Down
12 changes: 6 additions & 6 deletions internal/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
)

func handleSync(ctx *gin.Context) {
sourceServer := ctx.PostForm("sourceServer")
sourceAccount := ctx.PostForm("sourceAccount")
sourcePassword := ctx.PostForm("sourcePassword")
destinationServer := ctx.PostForm("destinationServer")
destinationAccount := ctx.PostForm("destinationAccount")
destinationPassword := ctx.PostForm("destinationPassword")
sourceServer := ctx.PostForm("source_server")
sourceAccount := ctx.PostForm("source_account")
sourcePassword := ctx.PostForm("source_password")
destinationServer := ctx.PostForm("destination_server")
destinationAccount := ctx.PostForm("destination_account")
destinationPassword := ctx.PostForm("destination_password")

sourceDetails := Credentials{
Server: sourceServer,
Expand Down
28 changes: 23 additions & 5 deletions internal/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,29 @@ import (
)

func handleValidate(ctx *gin.Context) {
Server := ctx.PostForm("server")
Account := ctx.PostForm("account")
Password := ctx.PostForm("password")

sourceCreds := ctx.PostForm("source_creds")
destCreds := ctx.PostForm("destination_creds")
submitsync := ctx.PostForm("submit_sync")

var Server, Account, Password string

if sourceCreds != "" {
Server = ctx.PostForm("source_server")
Account = ctx.PostForm("source_account")
Password = ctx.PostForm("source_password")
}

if destCreds != "" {
Server = ctx.PostForm("destination_server")
Account = ctx.PostForm("destination_account")
Password = ctx.PostForm("destination_password")
}

if destCreds == "" && sourceCreds == "" && submitsync != "" {
handleSync(ctx)
return
}

creds := Credentials{
Server: Server,
Expand Down Expand Up @@ -45,10 +65,8 @@ func validateCredentials(creds Credentials) error {
}
log.Infof("IMAP Connected")

// Don't forget to logout
defer c.Logout()

// Login
if err := c.Login(creds.Account, creds.Password); err != nil {
log.Error(err)
return err
Expand Down
97 changes: 47 additions & 50 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,73 +54,70 @@
</div>

<!-- imap sync form -->
<div class="container p-4 mx-auto flex gap-4 mt-4">


<!-- TODO: Single form only, use input instead of button, value for text -->
<form hx-post="/api/validate" hx-target="#error-notification" hx-swap="outerHTML"
class="container p-4 mx-auto flex gap-4 mt-4" id="credentials_form">

<!-- Source details -->
<div class="w-1/2 rounded-xl border border-border bg-backgroundSecondary rounded-lg p-4 shadow-md">
<h2 class="text-2xl font-semibold mb-4">Source Details</h2>
<form hx-post="/api/validate" hx-target="#error-notification" hx-swap="outerHTML">
<div class="grid gap-4 form-group">
<div class="form-field">
<label for="source_server" class="block font-semibold">Server</label>
<input type="text" id="source_server" name="server" placeholder="Source Server"
class="input max-w-full" required value="{{.SourceDetails.Server}}">
</div>
<div>
<label for="source_account" class="block font-semibold">Account</label>
<input type="text" id="source_account" name="account" placeholder="Source Account"
class="input max-w-full" required value="{{.SourceDetails.Account}}">
</div>
<div>
<label for="source_password" class="block font-semibold">Password</label>
<input type="password" id="source_password" name="password" placeholder="Source Password"
class="input max-w-full" required value="{{.SourceDetails.Password}}">
</div>
<button type="submit"
class="w-full bg-blue-500 hover:bg-blue-700 font-semibold text-white p-2 rounded-lg mt-4">
Validate Credentials
</button>
<div class="grid gap-4 form-group">
<div class="form-field">
<label for="source_server" class="block font-semibold">Server</label>
<input type="text" id="source_server" name="source_server" placeholder="Source Server"
class="input max-w-full" value="{{.SourceDetails.Server}}">
</div>
<div>
<label for="source_account" class="block font-semibold">Account</label>
<input type="text" id="source_account" name="source_account" placeholder="Source Account"
class="input max-w-full" value="{{.SourceDetails.Account}}">
</div>
</form>
<div>
<label for="source_password" class="block font-semibold">Password</label>
<input type="password" id="source_password" name="source_password" placeholder="Source Password"
class="input max-w-full" value="{{.SourceDetails.Password}}">
</div>
<input value="Validate Credentials" name="source_creds" type="submit"
class="w-full bg-blue-500 hover:bg-blue-700 font-semibold text-white p-2 rounded-lg mt-4">
</input>
</div>
</div>
<!-- Destination details -->
<div class="w-1/2 rounded-xl border border-border bg-backgroundSecondary rounded-lg p-4 shadow-md">
<h2 class="text-2xl font-semibold mb-4">Destination Details</h2>
<form hx-post="/api/validate" hx-target="#error-notification" hx-swap="outerHTML">
<div class="grid gap-4 form-group">
<div class="form-field">
<label for="destination_server" class="block font-semibold">Server</label>
<input type="text" id="source_server" name="server" placeholder="Destination Server"
class="input max-w-full" required value="{{.DestinationDetails.Server}}">
</div>
<div>
<label for="destination_account" class="block font-semibold">Account</label>
<input type="text" id="source_account" name="account" placeholder="Destination Account"
class="input max-w-full" required value="{{.DestinationDetails.Account}}">
</div>
<div>
<label for="destination_password" class="block font-semibold">Password</label>
<input type="password" id="source_password" name="password" placeholder="Destination Password"
class="input max-w-full" required value="{{.DestinationDetails.Password}}">
</div>
<button type="submit"
class="w-full bg-blue-500 hover:bg-blue-700 font-semibold text-white p-2 rounded-lg mt-4">
Validate Credentials
</button>
<div class="grid gap-4 form-group">
<div class="form-field">
<label for="destination_server" class="block font-semibold">Server</label>
<input type="text" id="destination_server" name="destination_server"
placeholder="Destination Server" class="input max-w-full"
value="{{.DestinationDetails.Server}}">
</div>
</form>
<div>
<label for="destination_account" class="block font-semibold">Account</label>
<input type="text" id="destination_account" name="destination_account"
placeholder="Destination Account" class="input max-w-full"
value="{{.DestinationDetails.Account}}">
</div>
<div>
<label for="destination_password" class="block font-semibold">Password</label>
<input type="password" id="destination_password" name="destination_password"
placeholder="Destination Password" class="input max-w-full"
value="{{.DestinationDetails.Password}}">
</div>
<input value="Validate Credentials" name="destination_creds" type="submit"
class="w-full bg-blue-500 hover:bg-blue-700 font-semibold text-white p-2 rounded-lg mt-4">
</input>
</div>
</div>
</div>
</form>

<!-- Log output -->
<div class="container mx-auto flex px-4">
<div class="w-full bg-backgroundSecondary p-4 shadow-md border border-border rounded-lg">
<div class="flex justify-between items-center mb-4">
<h2 class="text-2xl font-semibold">Log Output</h2>
<button class="btn btn-primary" id="start-sync-btn" form="">Start synchronization</button>
<input type="submit" class="bg-blue-500 hover:bg-blue-700 font-semibold text-white p-2 rounded-lg"
id="start-sync-btn" name="submit_sync" value="Start synchronization"
form="credentials_form"></input>
</div>
<div class="grid gap-4">
<textarea class="textarea-block textarea" rows="12" readonly></textarea>
Expand Down

0 comments on commit fe6cdad

Please sign in to comment.