Add login page

This commit is contained in:
Khanh Ngo 2020-04-24 11:22:50 +07:00
parent d017ea17c8
commit a78c9f3dd4
No known key found for this signature in database
GPG key ID: D5FAA6A16150E49E
4 changed files with 92 additions and 0 deletions

View file

@ -14,6 +14,13 @@ import (
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
// LoginPage handler
func LoginPage() echo.HandlerFunc {
return func(c echo.Context) error {
return c.Render(http.StatusOK, "login.html", map[string]interface{}{})
}
}
// WireGuardClients handler
func WireGuardClients() echo.HandlerFunc {
return func(c echo.Context) error {

View file

@ -19,6 +19,7 @@ func main() {
app := router.New()
app.GET("/", handler.WireGuardClients())
app.GET("/login", handler.LoginPage())
app.POST("/new-client", handler.NewClient())
app.POST("/client/set-status", handler.SetClientStatus())
app.POST("/remove-client", handler.RemoveClient())

View file

@ -22,6 +22,10 @@ func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c
err := errors.New("Template not found -> " + name)
return err
}
// login page does not need the base layout
if name == "login.html" {
return tmpl.Execute(w, data)
}
return tmpl.ExecuteTemplate(w, "base.html", data)
}
@ -29,6 +33,7 @@ func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c
func New() *echo.Echo {
e := echo.New()
templates := make(map[string]*template.Template)
templates["login.html"] = template.Must(template.ParseFiles("templates/login.html"))
templates["clients.html"] = template.Must(template.ParseFiles("templates/clients.html", "templates/base.html"))
templates["server.html"] = template.Must(template.ParseFiles("templates/server.html", "templates/base.html"))
templates["global_settings.html"] = template.Must(template.ParseFiles("templates/global_settings.html", "templates/base.html"))

79
templates/login.html Normal file
View file

@ -0,0 +1,79 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>WireGuard UI</title>
<!-- Tell the browser to be responsive to screen width -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Font Awesome -->
<link rel="stylesheet" href="static/plugins/fontawesome-free/css/all.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<!-- icheck bootstrap -->
<link rel="stylesheet" href="static/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="static/dist/css/adminlte.min.css">
<!-- Google Font: Source Sans Pro -->
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<a href="https://github.com/ngoduykhanh/wireguard-ui">WireGuard UI</a>
</div>
<!-- /.login-logo -->
<div class="card">
<div class="card-body login-card-body">
<p class="login-box-msg">Sign in to start your session</p>
<form action="" method="post">
<div class="input-group mb-3">
<input type="username" class="form-control" placeholder="Username">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-envelope"></span>
</div>
</div>
</div>
<div class="input-group mb-3">
<input type="password" class="form-control" placeholder="Password">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<div class="row">
<div class="col-8">
<div class="icheck-primary">
<input type="checkbox" id="remember">
<label for="remember">
Remember Me
</label>
</div>
</div>
<!-- /.col -->
<div class="col-4">
<button type="submit" class="btn btn-primary btn-block">Sign In</button>
</div>
<!-- /.col -->
</div>
</form>
</div>
<!-- /.login-card-body -->
</div>
</div>
<!-- /.login-box -->
<!-- jQuery -->
<script src="static/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="static/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="static/dist/js/adminlte.min.js"></script>
</body>
</html>