~huyngo/yue

87bb2f237adab4f626d139b5742f7c77007f4cec — Ngô Ngọc Đức Huy 11 months ago abda7c1
Implement timeline and login page with localization
4 files changed, 61 insertions(+), 3 deletions(-)

A auth.go
M main.go
M static.go
R home.go => timeline.go
A auth.go => auth.go +49 -0
@@ 0,0 1,49 @@
// Authentication handlers
// Copyright (C) 2021 Ngô Ngọc Đức Huy
//
// This file is part of Yue.
//
// Yue is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Yue is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Yue.  If not, see <https://www.gnu.org/licenses/>.

package main

import (
	"html/template"
	"log"
	"net/http"
)

// GET Handler for login page
func LoginPage(w http.ResponseWriter, r *http.Request) {
	files := []string{
		"./templates/dynamic/login.tmpl",
		"./templates/base.tmpl",
		"./templates/partials/head.tmpl",
	}

	tmpl, err := template.ParseFiles(files...)
	if err != nil {
		log.Println(err.Error())
		http.Error(w, "Internal Server Error", 500)
		return
	}

	title := "Log In"
	description := "Login page"
	err = tmpl.Execute(w, CreateRequestContext("", title, description, "system"))
	if err != nil {
		log.Println(err.Error())
		http.Error(w, "Internal Server Error", 500)
	}
}

M main.go => main.go +8 -1
@@ 34,8 34,15 @@ func main() {
	fs := http.FileServer(http.Dir("assets/"))

	r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs))
	r.HandleFunc("/", HomePage)

	// Static pages
	r.HandleFunc("/about/", AboutPage)

	// Authentication
	r.HandleFunc("/login/", LoginPage)

	// Timelines
	r.HandleFunc("/", HomeTimeline)

	http.ListenAndServe(":8080", r)
}

M static.go => static.go +1 -0
@@ 46,6 46,7 @@ func genericStaticPage(w http.ResponseWriter, r *http.Request, page string) {
	}
}

// Handler for About page
func AboutPage(w http.ResponseWriter, r *http.Request) {
	genericStaticPage(w, r, "about")
}

R home.go => timeline.go +3 -2
@@ 1,4 1,4 @@
// Home timeline handler
// Timeline handlers
// Copyright (C) 2021 Ngô Ngọc Đức Huy
//
// This file is part of Yue.


@@ 24,7 24,8 @@ import (
	"net/http"
)

func HomePage(w http.ResponseWriter, r *http.Request) {
// Handler for home timeline
func HomeTimeline(w http.ResponseWriter, r *http.Request) {
	files := []string{
		"./templates/dynamic/home.tmpl",
		"./templates/base.tmpl",