up
This commit is contained in:
@@ -1,4 +1,13 @@
|
||||
<div class="w-full max-w-sm">
|
||||
<!-- Error alert -->
|
||||
{{if .error}}
|
||||
<div class="mb-5 flex items-start gap-3 rounded-xl px-4 py-3" style="background:rgba(239,68,68,0.08); border:1px solid rgba(239,68,68,0.3)">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 flex-shrink-0 mt-0.5" style="color:#ef4444" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z"/>
|
||||
</svg>
|
||||
<span class="text-sm" style="color:#ef4444">{{.error}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
<!-- Logo -->
|
||||
<div class="mb-8 text-center">
|
||||
<div class="inline-flex items-center justify-center w-14 h-14 rounded-2xl mb-4" style="background-color:#1e293b">
|
||||
|
||||
@@ -6,25 +6,21 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>U-site</title>
|
||||
<!-- Alpine.js -->
|
||||
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
|
||||
<!-- TailwindCSS -->
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.13.5/dist/cdn.min.js"></script>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<!-- Select2 CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
||||
<!-- Select2 JS -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
||||
<style>
|
||||
[x-cloak] {
|
||||
display: none !important;
|
||||
}
|
||||
*, *::before, *::after { box-sizing: border-box; }
|
||||
body { font-family: 'Inter', system-ui, sans-serif; }
|
||||
[x-cloak] { display: none !important; }
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main class="flex space-x-1 justify-between">
|
||||
<div class="w-full">
|
||||
{{embed}}
|
||||
</div>
|
||||
<body style="background:#f1f5f9; min-height:100vh; display:flex; align-items:center; justify-content:center; font-family:'Inter',system-ui,sans-serif">
|
||||
<main>
|
||||
{{embed}}
|
||||
</main>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@ import (
|
||||
func LoginGet(c *fiber.Ctx) error {
|
||||
data := getFlashData(c)
|
||||
data["title"] = "Login | "
|
||||
if errMsg := c.Query("error"); errMsg != "" {
|
||||
data["error"] = errMsg
|
||||
}
|
||||
return c.Render("auth/login", data, "layouts/landing")
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/gookit/validate"
|
||||
"github.com/sujit-baniya/fiber-boilerplate/pkg/auth"
|
||||
"github.com/sujit-baniya/fiber-boilerplate/pkg/models"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func RedirectToHomePageOnLogin(c *fiber.Ctx) error {
|
||||
@@ -17,26 +18,16 @@ func RedirectToHomePageOnLogin(c *fiber.Ctx) error {
|
||||
func ValidateLoginPost(c *fiber.Ctx) error {
|
||||
var login models.Login
|
||||
if err := c.BodyParser(&login); err != nil {
|
||||
return c.JSON(fiber.Map{
|
||||
"status": "error",
|
||||
"message": err.Error(),
|
||||
})
|
||||
return c.Redirect("/login?error=" + url.QueryEscape(err.Error()))
|
||||
}
|
||||
v := validate.Struct(login)
|
||||
if !v.Validate() {
|
||||
return c.JSON(fiber.Map{
|
||||
"status": "error",
|
||||
"message": v.Errors.One(),
|
||||
})
|
||||
return c.Redirect("/login?error=" + url.QueryEscape(v.Errors.One()))
|
||||
}
|
||||
|
||||
user, err := login.CheckLogin()
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(fiber.Map{
|
||||
"status": "error",
|
||||
"message": err.Error(),
|
||||
})
|
||||
return c.Redirect("/login?error=" + url.QueryEscape(err.Error()))
|
||||
}
|
||||
|
||||
c.Locals("user", user)
|
||||
|
||||
Reference in New Issue
Block a user