all repos — auth-boilerplate @ 32f35ef61aea6ea30b3919f4298a7c4ea5893969

A simple Go web-app boilerplate.

graphic overhaul
Marco Andronaco andronacomarco@gmail.com
Thu, 10 Oct 2024 18:31:45 +0200
commit

32f35ef61aea6ea30b3919f4298a7c4ea5893969

parent

11306ab298ac8d3dcc76c08302590f317dbc7b55

A .vscode/launch.json

@@ -0,0 +1,15 @@

+{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Package", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "." + } + ] +}
A README.md

@@ -0,0 +1,28 @@

+# auth-boilerplate + +This web-app features: +* a working folder-based file structure, +* a basic authentication service, +* a basic SMTP implementation, +* a Dockerfile for convenience, +* a GitHub workflow to create packages. + + +## Environment + +All environment variables are optional, but some features might be disabled depending on what you have set. + +* `APP_PORT`: defaults to `3000`. +* `APP_BASE_URL`: defaults to `http://localhost:<port>`. +* `APP_PEPPER`: random string, used for password hashing. +* `APP_SMTP_EMAIL`: email address you want to send mails from. +* `APP_SMTP_PASSWORD`: password for said email address. +* `APP_SMTP_HOST`: host for the SMTP server. +* `APP_SMTP_PORT`: port for the SMTP server. + +This application also looks for a `.env` file in the current directory. + + +## License + +auth-boilerplate is licensed under MIT.
M src/app/init.gosrc/app/init.go

@@ -89,6 +89,8 @@ http.HandleFunc("POST /register", postRegisterHandler)

http.HandleFunc("POST /reset-password", postResetPasswordHandler) http.HandleFunc("POST /reset-password-confirm", postResetPasswordConfirmHandler) + http.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) + // Start serving log.Println("Port: " + port) log.Println("Server started: " + baseUrl)
A static/style.css

@@ -0,0 +1,19 @@

+form { + width: 400px; +} + +label { + display: flex; + flex-direction: row; + justify-content: flex-end; +} + +label > input { + flex: 0 0 200px; + margin-left: 20px; +} + +input[type=checkbox] { + flex: unset; +} +
M templates/example.htmltemplates/example.html

@@ -1,11 +1,18 @@

<!DOCTYPE html> -<html> +<html lang="en"> + <head> - <title>Pagina Protetta</title> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Protected page</title> + <link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"> + <link rel="stylesheet" href="/static/style.css"> </head> + <body> - <h1>Benvenuto, {{.User.Username}}!</h1> - <p>Questa รจ una pagina protetta visibile solo agli utenti loggati.</p> + <h1>Welcome, {{.User.Username}}!</h1> + <p>This page is only accessible by users who have logged in.</p> <a href="/logout">Logout</a> </body> + </html>
M templates/login.htmltemplates/login.html

@@ -1,17 +1,33 @@

<!DOCTYPE html> -<html> +<html lang="en"> + <head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Login</title> + <link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"> + <link rel="stylesheet" href="/static/style.css"> </head> + <body> <h1>Login</h1> <form method="post" action="/login"> - <label>Username: <input type="text" name="username" autocomplete="off"></label><br> - <label>Password: <input type="password" name="password"></label><br> - <label>Remember me: <input type="checkbox" name="remember"></label><br> + <label> + <span>Username:</span> + <input type="text" name="username" autocomplete="off"> + </label> + <label> + <span>Password:</span> + <input type="password" name="password"> + </label> + <label> + <span>Remember me:</span> + <input type="checkbox" name="remember"> + </label> <input type="submit" value="Login"> </form> <a href="/register">Sign up</a> <a href="/reset-password">Reset password</a> </body> + </html>
M templates/new_password.htmltemplates/new_password.html

@@ -1,8 +1,14 @@

<!DOCTYPE html> -<html> +<html lang="en"> + <head> - <title>Nuova Password</title> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Pagina Protetta</title> + <link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"> + <link rel="stylesheet" href="/static/style.css"> </head> + <body> <h1>Reimposta la tua password</h1> <form method="post">

@@ -10,4 +16,5 @@ <label>Nuova Password: <input type="password" name="password"></label><br>

<input type="submit" value="Reimposta Password"> </form> </body> + </html>
M templates/register.htmltemplates/register.html

@@ -1,10 +1,16 @@

<!DOCTYPE html> -<html> +<html lang="en"> + <head> - <title>Registrazione</title> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Sign up</title> + <link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"> + <link rel="stylesheet" href="/static/style.css"> </head> + <body> - <h1>Registrazione</h1> + <h1>Sign up</h1> <form method="post" action="/register"> <label>Username: <input type="text" name="username"></label><br> <label>Email: <input type="email" name="email"></label><br>

@@ -14,4 +20,5 @@ </form>

<a href="/login">Login</a> <a href="/reset-password">Reset password</a> </body> + </html>
M templates/reset_password.htmltemplates/reset_password.html

@@ -1,8 +1,14 @@

<!DOCTYPE html> -<html> +<html lang="en"> + <head> - <title>Reset Password</title> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Reset password</title> + <link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"> + <link rel="stylesheet" href="/static/style.css"> </head> + <body> <h1>Reset Password</h1> <form method="post" action="/reset-password">

@@ -12,4 +18,5 @@ </form>

<a href="/register">Sign up</a> <a href="/login">Login</a> </body> + </html>