aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--config.go20
-rw-r--r--main.go37
-rw-r--r--misc.go20
-rw-r--r--oidc.go20
-rw-r--r--static/style.css20
-rw-r--r--tmpl/index.tmpl17
-rw-r--r--tmpl/index_login.tmpl35
7 files changed, 168 insertions, 1 deletions
diff --git a/config.go b/config.go
index 255b44e..421b324 100644
--- a/config.go
+++ b/config.go
@@ -1,3 +1,23 @@
+/*
+ * Handle fbfp's configuration.
+ *
+ * Copyright (C) 2024 Runxi Yu <https://runxiyu.org>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
package main
import (
diff --git a/main.go b/main.go
index 1435826..480f2ea 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,27 @@
+/*
+ * The main logic for fbfp.
+ *
+ * Copyright (C) 2024 Runxi Yu <https://runxiyu.org>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
package main
import (
+ "errors"
"fmt"
"html/template"
"log"
@@ -16,7 +37,21 @@ var db *gorm.DB
var tmpl *template.Template
func handle_index(w http.ResponseWriter, req *http.Request) {
- tmpl.ExecuteTemplate(w, "index", nil)
+ session_cookie, err := req.Cookie("session")
+ if errors.Is(err, http.ErrNoCookie) {
+ err = tmpl.ExecuteTemplate(w, "index_login", nil)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+ return
+ }
+ _ = session_cookie
+ err = tmpl.ExecuteTemplate(w, "index", nil)
+ if err != nil {
+ log.Println(err)
+ return
+ }
}
func handle_login(w http.ResponseWriter, req *http.Request) {
diff --git a/misc.go b/misc.go
index 172ed90..73e3b07 100644
--- a/misc.go
+++ b/misc.go
@@ -1,3 +1,23 @@
+/*
+ * Misc function definitions for fbfp.
+ *
+ * Copyright (C) 2024 Runxi Yu <https://runxiyu.org>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
package main
import (
diff --git a/oidc.go b/oidc.go
index f23381f..0f8c54d 100644
--- a/oidc.go
+++ b/oidc.go
@@ -1,3 +1,23 @@
+/*
+ * OpenID Connect for fbfp.
+ *
+ * Copyright (C) 2024 Runxi Yu <https://runxiyu.org>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
package main
import (
diff --git a/static/style.css b/static/style.css
index b37098e..0655fa0 100644
--- a/static/style.css
+++ b/static/style.css
@@ -1,4 +1,24 @@
/*
+ * General styling for fbfp.
+ *
+ * Copyright (C) 2024 Runxi Yu <https://runxiyu.org>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+/*
* TODO: Remove all uses of !important. These are obviously bad practice, but
* it's not always trivial to get the precedence right.
*/
diff --git a/tmpl/index.tmpl b/tmpl/index.tmpl
index 92ce9a7..af8aaa9 100644
--- a/tmpl/index.tmpl
+++ b/tmpl/index.tmpl
@@ -1,3 +1,20 @@
+{{- /*
+ * Copyright (c) 2024 Runxi Yu
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+ */ -}}
{{ define "index" }}
<!DOCTYPE html>
<html>
diff --git a/tmpl/index_login.tmpl b/tmpl/index_login.tmpl
new file mode 100644
index 0000000..da3396c
--- /dev/null
+++ b/tmpl/index_login.tmpl
@@ -0,0 +1,35 @@
+{{- /*
+ * Copyright (c) 2024 Runxi Yu
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+ */ -}}
+{{ define "index_login" }}
+<!DOCTYPE html>
+<html>
+<head>
+<title>
+Login required &ndash; FBFP
+</title>
+</head>
+<body>
+<p>
+You have not authenticated.
+</p>
+<p>
+You must <a href="login">login</a> to use this service.
+</p>
+</body>
+</html>
+{{ end }}