Compare commits
271 Commits
publish_is
...
main
Author | SHA1 | Date | |
---|---|---|---|
acae07b8f3 | |||
52b5dbf2c7 | |||
1b100483de | |||
7b9438233e | |||
ff36d65cc3 | |||
3d3cda319d | |||
0e825a55e5 | |||
88776337e4 | |||
f8691eb180 | |||
60e09175da | |||
13a6039490 | |||
d953b4135c | |||
4da9792b0f | |||
e03fd78ea9 | |||
36e9a16a6e | |||
d239a86444 | |||
8b1b99d0f7 | |||
c0e446d6d9 | |||
370ef205a9 | |||
544dddc893 | |||
523bdb24cd | |||
376a1264f5 | |||
82faacb9ec | |||
7f85b60916 | |||
ca43ec1a81 | |||
0a14545a19 | |||
8d41caf40a | |||
8fb0733908 | |||
81f0e46ba6 | |||
19da2ae60c | |||
2078be920e | |||
eb8e14ff6d | |||
485eaaca70 | |||
b2a8578c72 | |||
dbddff6e55 | |||
f663592019 | |||
c59029cf3d | |||
d328ddb749 | |||
ac740cf4b8 | |||
b7d82f15e9 | |||
b4003c8216 | |||
5dc5590da9 | |||
81c046c1b0 | |||
364112a0a4 | |||
1e9fdd2ab9 | |||
a38523e933 | |||
1fbc0ddcf6 | |||
0dd2101a08 | |||
e95871ee70 | |||
083718711d | |||
20a12c6299 | |||
200672dae2 | |||
be829e662b | |||
3d3aad88c8 | |||
0036b42d82 | |||
e4e43d1a83 | |||
59deb69e2f | |||
3aef27585a | |||
3aa8796537 | |||
737a9ec314 | |||
4b75fc61cd | |||
1ebe0380ee | |||
c439e048c1 | |||
f86f2ba146 | |||
d62d71b5d1 | |||
07e1983fcc | |||
878f57af08 | |||
d86b9027bf | |||
31484dd44a | |||
3b4e1e01d2 | |||
03425fc2c6 | |||
0b9bae3bf8 | |||
8ed0676e51 | |||
d7cbb34814 | |||
23f0c6f4a4 | |||
cb322c57f9 | |||
123071ab1b | |||
343022273c | |||
19b390cbbb | |||
2751a8c972 | |||
750184b8ef | |||
f28c204c52 | |||
70d403d7d7 | |||
b36e0ea503 | |||
863581f590 | |||
aec829ad85 | |||
298ea458ca | |||
533053aef0 | |||
c00645432b | |||
91d53a0f2a | |||
b3f31f398d | |||
cf4d4f151a | |||
202d04f323 | |||
b2a701c87a | |||
bc4d8fa37e | |||
1368593c75 | |||
e4bef7006c | |||
afa1b65563 | |||
a9bef63174 | |||
4d944ef65a | |||
d2b21e7405 | |||
4bd255a7c4 | |||
2743899b65 | |||
065ffcdc30 | |||
38ef7b80d5 | |||
e3c192359f | |||
c777a77824 | |||
46532e4c85 | |||
c183043dac | |||
c722135a56 | |||
391b3bf157 | |||
0aa479763d | |||
ff0e229f03 | |||
8ef6ff729e | |||
e4624b8705 | |||
887fa863bc | |||
4592bdf970 | |||
dadd610b2d | |||
74d71cfb6a | |||
4004bcb8f0 | |||
9e0182ed03 | |||
e554174c28 | |||
8597f1b849 | |||
b04e0e5e81 | |||
ca7e7cddd3 | |||
62921c8e2a | |||
94431a2aa9 | |||
c7761e2dc8 | |||
5b1f20c5bc | |||
013cddc157 | |||
523ff9d2db | |||
84960fdd44 | |||
d0c566f8df | |||
0a387c1087 | |||
38caf02b2c | |||
435157a42f | |||
4163afb0b7 | |||
5e586aa49a | |||
6cc0fb40d7 | |||
66b2743d3d | |||
18617f1dbc | |||
3723b2b5e6 | |||
79ee20a50e | |||
e05521591b | |||
0c9a79e24a | |||
ce788bfd50 | |||
8147d9bef6 | |||
230a6278cc | |||
da0d65d40b | |||
42d6e0c198 | |||
a2d219b2c0 | |||
e1af2979af | |||
b02a882ed7 | |||
f6dedc6f10 | |||
edb448413b | |||
cdf0a49550 | |||
222b791e90 | |||
c3c0650210 | |||
bc58b1be44 | |||
ab6b9b9a4f | |||
91ef195a56 | |||
d077f700d8 | |||
e4589f3b84 | |||
cd67fe6df3 | |||
ec752b1c66 | |||
4663cedec5 | |||
3f1b18c29f | |||
4a11e1a497 | |||
a33e7f9896 | |||
2b2ab0d428 | |||
c52e35bf0b | |||
cddd88d2f6 | |||
be467521d9 | |||
10d8fceb77 | |||
46aef4f12f | |||
714cdd9aaf | |||
1b29e328cf | |||
5474b17ce5 | |||
a318a265d4 | |||
e50cb819f3 | |||
365d5a68a1 | |||
b451da7e8e | |||
6a4a592714 | |||
806cfb01bd | |||
c32e38ca10 | |||
c2cadd1542 | |||
4cb2831e9a | |||
ee31a9f8e2 | |||
beec20cdda | |||
7ef957c2d7 | |||
d7c8c7a43a | |||
d56cdc78eb | |||
151d89d9f0 | |||
8d2944d00c | |||
9ddd8198ee | |||
ff6c7a66d7 | |||
129c85929c | |||
b1a6359473 | |||
b5d979dbf8 | |||
1cd3edc90c | |||
77e8edbe16 | |||
8115c50974 | |||
61bfa85b13 | |||
cd27349d04 | |||
5b41892dff | |||
c7add76a12 | |||
f4ae2f9c04 | |||
64f85a34cb | |||
0c87d91df1 | |||
472f00a107 | |||
bebfe994ae | |||
46bfd23b2a | |||
0afbdde077 | |||
0e768c9f61 | |||
ce43e45a6c | |||
1fcd775cc5 | |||
203a1ed147 | |||
ef1914ee5c | |||
084b101e31 | |||
b2db128aa9 | |||
081e880fb6 | |||
32f11f57b5 | |||
46a0cec6df | |||
4e0bce37a2 | |||
85e2f8b4ad | |||
d0c1e525d2 | |||
21fd3403b2 | |||
0f0471b84c | |||
4b90ec9652 | |||
783d59805b | |||
b5f0fe8985 | |||
d9bf79d5f8 | |||
f98ab149a2 | |||
822ca2b8ab | |||
af65180893 | |||
5615210be5 | |||
b88fb1643c | |||
92189a4a51 | |||
8dc8f02504 | |||
e3ce1d7b55 | |||
532bc6490a | |||
84fa828b38 | |||
a3c53b1b20 | |||
ca70fa6d4d | |||
972b8cac19 | |||
d0605660f7 | |||
5d2d841aba | |||
d62c5a4078 | |||
803c5bbdbd | |||
c74bdeba72 | |||
717f1c813b | |||
52797760bb | |||
8711ba0629 | |||
ed51d28c65 | |||
7e7de28b14 | |||
0139f7ab9a | |||
7fc115bcc3 | |||
ae90f693f6 | |||
a730e11b4a | |||
959e1e96b3 | |||
68b052625f | |||
a0fe0024f2 | |||
6e3c4bf647 | |||
26988ecf6a | |||
9408ce99e3 | |||
af036b4909 | |||
e60e6114bd | |||
600044c621 | |||
77a90cb4f1 | |||
34e9e9edd5 | |||
4d1faf3d4a |
61
.air.toml
Normal file
61
.air.toml
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
root = "."
|
||||||
|
testdata_dir = "testdata"
|
||||||
|
tmp_dir = "tmp"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
args_bin = [
|
||||||
|
"-aes tmp/cpolis.aes",
|
||||||
|
"-articles tmp/articles",
|
||||||
|
"-banner-width 512",
|
||||||
|
"-config tmp/config.toml",
|
||||||
|
"-desc 'Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität'",
|
||||||
|
"-domain localhost",
|
||||||
|
"-feed tmp/cpolis.atom",
|
||||||
|
"-firebase tmp/firebase.json",
|
||||||
|
"-img-width 256",
|
||||||
|
"-link https://distrikt-ni-st.de",
|
||||||
|
"-log tmp/cpolis.log",
|
||||||
|
"-pdfs tmp/pdfs",
|
||||||
|
"-pics tmp/pics",
|
||||||
|
"-port 8080",
|
||||||
|
"-title 'Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt'",
|
||||||
|
"-web web",
|
||||||
|
]
|
||||||
|
bin = "./tmp/main"
|
||||||
|
cmd = "go build -o ./tmp/main ./cmd/main.go"
|
||||||
|
delay = 0
|
||||||
|
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
|
||||||
|
exclude_file = []
|
||||||
|
exclude_regex = ["_test.go"]
|
||||||
|
exclude_unchanged = false
|
||||||
|
follow_symlink = false
|
||||||
|
full_bin = ""
|
||||||
|
include_dir = []
|
||||||
|
include_ext = ["go", "tpl", "tmpl", "html", "css"]
|
||||||
|
include_file = []
|
||||||
|
kill_delay = "0s"
|
||||||
|
log = "build-errors.log"
|
||||||
|
poll = false
|
||||||
|
poll_interval = 0
|
||||||
|
rerun = false
|
||||||
|
rerun_delay = 500
|
||||||
|
send_interrupt = false
|
||||||
|
stop_on_error = false
|
||||||
|
|
||||||
|
[color]
|
||||||
|
app = ""
|
||||||
|
build = "yellow"
|
||||||
|
main = "magenta"
|
||||||
|
runner = "green"
|
||||||
|
watcher = "cyan"
|
||||||
|
|
||||||
|
[log]
|
||||||
|
main_only = false
|
||||||
|
time = false
|
||||||
|
|
||||||
|
[misc]
|
||||||
|
clean_on_exit = false
|
||||||
|
|
||||||
|
[screen]
|
||||||
|
clear_on_rebuild = false
|
||||||
|
keep_scroll = true
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -23,3 +23,4 @@ go.work
|
|||||||
|
|
||||||
# Custom stuff
|
# Custom stuff
|
||||||
tmp/
|
tmp/
|
||||||
|
style.css
|
||||||
|
179
LICENSE
179
LICENSE
@ -1,71 +1,68 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
Version 3, 29 June 2007
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
Preamble
|
Preamble
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for software and other kinds of works.
|
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
|
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
|
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
|
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
|
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and modification follow.
|
The precise terms and conditions for copying, distribution and modification follow.
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
0. Definitions.
|
0. Definitions.
|
||||||
|
|
||||||
“This License” refers to version 3 of the GNU General Public License.
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||||
|
|
||||||
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
|
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
|
||||||
|
|
||||||
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
|
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
A “covered work” means either the unmodified Program or a work based on the Program.
|
A "covered work" means either the unmodified Program or a work based on the Program.
|
||||||
|
|
||||||
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||||
|
|
||||||
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
1. Source Code.
|
1. Source Code.
|
||||||
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
|
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
|
||||||
|
|
||||||
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||||
|
|
||||||
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
|
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that same work.
|
The Corresponding Source for a work in source code form is that same work.
|
||||||
|
|
||||||
2. Basic Permissions.
|
2. Basic Permissions.
|
||||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||||
@ -80,153 +77,159 @@ You may charge any price or no price for each copy that you convey, and you may
|
|||||||
5. Conveying Modified Source Versions.
|
5. Conveying Modified Source Versions.
|
||||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
|
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
6. Conveying Non-Source Forms.
|
||||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||||
|
|
||||||
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||||
|
|
||||||
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||||
|
|
||||||
7. Additional Terms.
|
7. Additional Terms.
|
||||||
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||||
|
|
||||||
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||||
|
|
||||||
8. Termination.
|
8. Termination.
|
||||||
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
|
||||||
|
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
9. Acceptance Not Required for Having Copies.
|
||||||
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
11. Patents.
|
11. Patents.
|
||||||
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
|
|
||||||
|
|
||||||
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||||
|
|
||||||
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||||
|
|
||||||
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
12. No Surrender of Others' Freedom.
|
||||||
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may
|
||||||
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
|
not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License.
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
14. Revised Versions of this License.
|
||||||
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
|
The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||||
|
|
||||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
15. Disclaimer of Warranty.
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
16. Limitation of Liability.
|
16. Limitation of Liability.
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
cpolis
|
cpolis
|
||||||
Copyright (C) 2024 Jason Streifling
|
Copyright (C) 2024 Jason Streifling
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 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 General Public License for more details.
|
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 General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
|
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
|
||||||
|
|
||||||
cpolis Copyright (C) 2024 Jason Streifling
|
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <http://www.gnu.org/licenses/>.
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <https://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
||||||
|
17
README.md
17
README.md
@ -1,3 +1,18 @@
|
|||||||
# cpolis
|
# cpolis
|
||||||
|
|
||||||
cpolis is an application written in Go to serve as the backend of the Orient Express magazine.
|
cpolis is an application written in Go to serve as the backend of the Orient
|
||||||
|
Express magazine.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
You should have the following packages installed:
|
||||||
|
|
||||||
|
- Go >= 1.22
|
||||||
|
- MariaDB
|
||||||
|
|
||||||
|
Enable and start the MariaDB service.
|
||||||
|
|
||||||
|
sudo systemctl enable --now mariadb.service
|
||||||
|
|
||||||
|
Set up a dedicated MariaDB user for cpolis.
|
||||||
|
|
||||||
|
@ -1,23 +1,31 @@
|
|||||||
package model
|
package backend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Article struct {
|
type Article struct {
|
||||||
Title string
|
Created time.Time
|
||||||
Created time.Time
|
Title string
|
||||||
Description string
|
BannerLink string
|
||||||
Content string
|
Summary string
|
||||||
Published bool
|
UUID uuid.UUID
|
||||||
Rejected bool
|
ID int64
|
||||||
ID int64
|
CreatorID int64
|
||||||
AuthorID int64
|
IssueID int64
|
||||||
IssueID int64
|
EditedID int64
|
||||||
|
Clicks int
|
||||||
|
Published bool
|
||||||
|
Rejected bool
|
||||||
|
IsInIssue bool
|
||||||
|
AutoGenerated bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) AddArticle(a *Article) (int64, error) {
|
func (db *DB) AddArticle(a *Article) (int64, error) {
|
||||||
@ -26,8 +34,8 @@ func (db *DB) AddArticle(a *Article) (int64, error) {
|
|||||||
selectQuery := "SELECT id FROM issues WHERE published = false"
|
selectQuery := "SELECT id FROM issues WHERE published = false"
|
||||||
insertQuery := `
|
insertQuery := `
|
||||||
INSERT INTO articles
|
INSERT INTO articles
|
||||||
(title, description, content, published, rejected, author_id, issue_id)
|
(title, banner_link, summary, published, rejected, creator_id, issue_id, edited_id, clicks, is_in_issue, auto_generated, uuid)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
`
|
`
|
||||||
|
|
||||||
for i := 0; i < TxMaxRetries; i++ {
|
for i := 0; i < TxMaxRetries; i++ {
|
||||||
@ -44,8 +52,7 @@ func (db *DB) AddArticle(a *Article) (int64, error) {
|
|||||||
return 0, fmt.Errorf("error getting issue ID when adding article to DB: %v", err)
|
return 0, fmt.Errorf("error getting issue ID when adding article to DB: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := tx.Exec(insertQuery, a.Title, a.Description,
|
result, err := tx.Exec(insertQuery, a.Title, a.BannerLink, a.Summary, a.Published, a.Rejected, a.CreatorID, id, a.EditedID, 0, a.IsInIssue, a.AutoGenerated, a.UUID.String())
|
||||||
a.Content, a.Published, a.Rejected, a.AuthorID, id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
@ -79,7 +86,7 @@ func (db *DB) AddArticle(a *Article) (int64, error) {
|
|||||||
|
|
||||||
func (db *DB) GetArticle(id int64) (*Article, error) {
|
func (db *DB) GetArticle(id int64) (*Article, error) {
|
||||||
query := `
|
query := `
|
||||||
SELECT title, created, description, content, published, author_id
|
SELECT title, created, banner_link, summary, published, creator_id, issue_id, edited_id, clicks, is_in_issue, auto_generated, uuid
|
||||||
FROM articles
|
FROM articles
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
`
|
`
|
||||||
@ -87,10 +94,10 @@ func (db *DB) GetArticle(id int64) (*Article, error) {
|
|||||||
|
|
||||||
article := new(Article)
|
article := new(Article)
|
||||||
var created []byte
|
var created []byte
|
||||||
|
var uuidString string
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if err := row.Scan(&article.Title, &created, &article.Description,
|
if err := row.Scan(&article.Title, &created, &article.BannerLink, &article.Summary, &article.Published, &article.CreatorID, &article.IssueID, &article.EditedID, &article.Clicks, &article.IsInIssue, &article.AutoGenerated, &uuidString); err != nil {
|
||||||
&article.Content, &article.Published, &article.AuthorID); err != nil {
|
|
||||||
return nil, fmt.Errorf("error scanning article row: %v", err)
|
return nil, fmt.Errorf("error scanning article row: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,17 +107,21 @@ func (db *DB) GetArticle(id int64) (*Article, error) {
|
|||||||
return nil, fmt.Errorf("error parsing created: %v", err)
|
return nil, fmt.Errorf("error parsing created: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
article.UUID, err = uuid.Parse(uuidString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error parsing uuid: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
return article, nil
|
return article, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) GetCertainArticles(published, rejected bool) ([]*Article, error) {
|
func (db *DB) GetCertainArticles(attribute string, value bool) ([]*Article, error) {
|
||||||
query := `
|
query := fmt.Sprintf(`
|
||||||
SELECT id, title, created, description, content, author_id
|
SELECT id, title, created, banner_link, summary, creator_id, issue_id, clicks, published, rejected, is_in_issue, auto_generated, uuid
|
||||||
FROM articles
|
FROM articles
|
||||||
WHERE published = ?
|
WHERE %s = ?
|
||||||
AND rejected = ?
|
`, attribute)
|
||||||
`
|
rows, err := db.Query(query, value)
|
||||||
rows, err := db.Query(query, published, rejected)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error querying articles: %v", err)
|
return nil, fmt.Errorf("error querying articles: %v", err)
|
||||||
}
|
}
|
||||||
@ -119,18 +130,22 @@ func (db *DB) GetCertainArticles(published, rejected bool) ([]*Article, error) {
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
article := new(Article)
|
article := new(Article)
|
||||||
var created []byte
|
var created []byte
|
||||||
|
var uuidString string
|
||||||
|
|
||||||
if err = rows.Scan(&article.ID, &article.Title, &created,
|
if err = rows.Scan(&article.ID, &article.Title, &created, &article.BannerLink, &article.Summary, &article.CreatorID, &article.IssueID, &article.Clicks, &article.Published, &article.Rejected, &article.IsInIssue, &article.AutoGenerated, &uuidString); err != nil {
|
||||||
&article.Description, &article.Content, &article.AuthorID); err != nil {
|
|
||||||
return nil, fmt.Errorf("error scanning article row: %v", err)
|
return nil, fmt.Errorf("error scanning article row: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
article.Published = false
|
|
||||||
article.Created, err = time.Parse("2006-01-02 15:04:05", string(created))
|
article.Created, err = time.Parse("2006-01-02 15:04:05", string(created))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error parsing created: %v", err)
|
return nil, fmt.Errorf("error parsing created: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
article.UUID, err = uuid.Parse(uuidString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error parsing uuid: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
articleList = append(articleList, article)
|
articleList = append(articleList, article)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,9 +157,9 @@ func (db *DB) GetCurrentIssueArticles() ([]*Article, error) {
|
|||||||
txOptions := &sql.TxOptions{Isolation: sql.LevelSerializable}
|
txOptions := &sql.TxOptions{Isolation: sql.LevelSerializable}
|
||||||
issueQuery := "SELECT id FROM issues WHERE published = false"
|
issueQuery := "SELECT id FROM issues WHERE published = false"
|
||||||
articlesQuery := `
|
articlesQuery := `
|
||||||
SELECT id, title, created, description, content, author_id
|
SELECT id, title, created, banner_link, summary, clicks, auto_generated, uuid
|
||||||
FROM articles
|
FROM articles
|
||||||
WHERE issue_id = ? AND published = true
|
WHERE issue_id = ? AND published = true AND is_in_issue = true
|
||||||
`
|
`
|
||||||
|
|
||||||
for i := 0; i < TxMaxRetries; i++ {
|
for i := 0; i < TxMaxRetries; i++ {
|
||||||
@ -174,9 +189,9 @@ func (db *DB) GetCurrentIssueArticles() ([]*Article, error) {
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
article := new(Article)
|
article := new(Article)
|
||||||
var created []byte
|
var created []byte
|
||||||
|
var uuidString string
|
||||||
|
|
||||||
if err = rows.Scan(&article.ID, &article.Title, &created,
|
if err = rows.Scan(&article.ID, &article.Title, &created, &article.BannerLink, &article.Summary, &article.Clicks, &article.AutoGenerated, &uuidString); err != nil {
|
||||||
&article.Description, &article.Content, &article.AuthorID); err != nil {
|
|
||||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
}
|
}
|
||||||
@ -191,6 +206,14 @@ func (db *DB) GetCurrentIssueArticles() ([]*Article, error) {
|
|||||||
return nil, fmt.Errorf("error parsing created: %v", err)
|
return nil, fmt.Errorf("error parsing created: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
article.UUID, err = uuid.Parse(uuidString)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("error parsing uuid: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
articleList = append(articleList, article)
|
articleList = append(articleList, article)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,3 +278,42 @@ func (db *DB) AddArticleToCurrentIssue(id int64) error {
|
|||||||
|
|
||||||
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *DB) DeleteArticle(id int64) error {
|
||||||
|
articlesTagsQuery := "DELETE FROM articles_tags WHERE article_id = ?"
|
||||||
|
articlesContributorsQuery := "DELETE FROM articles_contributors WHERE article_id = ?"
|
||||||
|
articlesAuthorsQuery := "DELETE FROM articles_authors WHERE article_id = ?"
|
||||||
|
articlesQuery := "DELETE FROM articles WHERE id = ?"
|
||||||
|
|
||||||
|
_, err := db.Exec(articlesTagsQuery, id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting articles_tags %v from DB: %v", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = db.Exec(articlesContributorsQuery, id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting articles_contributors %v from DB: %v", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = db.Exec(articlesAuthorsQuery, id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting articles_authors %v from DB: %v", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = db.Exec(articlesQuery, id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting article %v from DB: %v", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func WriteArticleToFile(c *Config, articleUUID uuid.UUID, content []byte) error {
|
||||||
|
articleAbsName := fmt.Sprint(c.ArticleDir, "/", articleUUID, ".md")
|
||||||
|
|
||||||
|
if err := os.WriteFile(articleAbsName, content, 0644); err != nil {
|
||||||
|
return fmt.Errorf("error writing article %v to file: %v", articleUUID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
114
cmd/backend/articles_authors.go
Normal file
114
cmd/backend/articles_authors.go
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (db *DB) WriteArticleAuthors(articleID int64, authorIDs []int64) error {
|
||||||
|
query := "INSERT INTO articles_authors (article_id, author_id) VALUES (?, ?)"
|
||||||
|
|
||||||
|
for i := 0; i < TxMaxRetries; i++ {
|
||||||
|
err := func() error {
|
||||||
|
tx, err := db.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error starting transaction: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, authorID := range authorIDs {
|
||||||
|
if _, err := tx.Exec(query, articleID, authorID); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error inserting into articles_authors: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = tx.Commit(); err != nil {
|
||||||
|
return fmt.Errorf("error committing transaction: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}()
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(err)
|
||||||
|
wait(i)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) GetArticleAuthors(c *Config, articleID int64) ([]*User, error) {
|
||||||
|
query := `
|
||||||
|
SELECT u.id
|
||||||
|
FROM articles a
|
||||||
|
INNER JOIN articles_authors aa ON a.id = aa.article_id
|
||||||
|
INNER JOIN users u ON aa.author_id = u.id
|
||||||
|
WHERE a.id = ?
|
||||||
|
`
|
||||||
|
rows, err := db.Query(query, articleID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error querying articles_authors: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
authors := make([]*User, 0)
|
||||||
|
for rows.Next() {
|
||||||
|
var authorID int64
|
||||||
|
|
||||||
|
if err = rows.Scan(&authorID); err != nil {
|
||||||
|
return nil, fmt.Errorf("error scanning rows: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
author, err := db.GetUser(c, authorID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting user info for article author: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
authors = append(authors, author)
|
||||||
|
}
|
||||||
|
|
||||||
|
return authors, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) UpdateArticleAuthors(articleID int64, authorIDs []int64) error {
|
||||||
|
deleteQuery := "DELETE FROM articles_authors WHERE article_id = ?"
|
||||||
|
insertQuery := "INSERT INTO articles_authors (article_id, author_id) VALUES (?, ?)"
|
||||||
|
|
||||||
|
for i := 0; i < TxMaxRetries; i++ {
|
||||||
|
err := func() error {
|
||||||
|
tx, err := db.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error starting transaction: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := tx.Exec(deleteQuery, articleID); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error deleting entries from articles_authors before inserting new ones: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, authorID := range authorIDs {
|
||||||
|
if _, err := tx.Exec(insertQuery, articleID, authorID); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error inserting new entries into articles_authors: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = tx.Commit(); err != nil {
|
||||||
|
return fmt.Errorf("error committing transaction: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}()
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(err)
|
||||||
|
wait(i)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
||||||
|
}
|
114
cmd/backend/articles_contributors.go
Normal file
114
cmd/backend/articles_contributors.go
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (db *DB) WriteArticleContributors(articleID int64, contributorIDs []int64) error {
|
||||||
|
query := "INSERT INTO articles_contributors (article_id, contributor_id) VALUES (?, ?)"
|
||||||
|
|
||||||
|
for i := 0; i < TxMaxRetries; i++ {
|
||||||
|
err := func() error {
|
||||||
|
tx, err := db.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error starting transaction: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, contributorID := range contributorIDs {
|
||||||
|
if _, err := tx.Exec(query, articleID, contributorID); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error inserting into articles_contributors: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = tx.Commit(); err != nil {
|
||||||
|
return fmt.Errorf("error committing transaction: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}()
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(err)
|
||||||
|
wait(i)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) GetArticleContributors(c *Config, articleID int64) ([]*User, error) {
|
||||||
|
query := `
|
||||||
|
SELECT u.id
|
||||||
|
FROM articles a
|
||||||
|
INNER JOIN articles_contributors ac ON a.id = ac.article_id
|
||||||
|
INNER JOIN users u ON ac.contributor_id = u.id
|
||||||
|
WHERE a.id = ?
|
||||||
|
`
|
||||||
|
rows, err := db.Query(query, articleID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error querying articles_contributors: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
contributors := make([]*User, 0)
|
||||||
|
for rows.Next() {
|
||||||
|
var contributorID int64
|
||||||
|
|
||||||
|
if err = rows.Scan(&contributorID); err != nil {
|
||||||
|
return nil, fmt.Errorf("error scanning rows: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
contributor, err := db.GetUser(c, contributorID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting user info for article contributor: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
contributors = append(contributors, contributor)
|
||||||
|
}
|
||||||
|
|
||||||
|
return contributors, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) UpdateArticleContributors(articleID int64, contributorIDs []int64) error {
|
||||||
|
deleteQuery := "DELETE FROM articles_contributors WHERE article_id = ?"
|
||||||
|
insertQuery := "INSERT INTO articles_contributors (article_id, contributor_id) VALUES (?, ?)"
|
||||||
|
|
||||||
|
for i := 0; i < TxMaxRetries; i++ {
|
||||||
|
err := func() error {
|
||||||
|
tx, err := db.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error starting transaction: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := tx.Exec(deleteQuery, articleID); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error deleting entries from articles_contributors before inserting new ones: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, contributorID := range contributorIDs {
|
||||||
|
if _, err := tx.Exec(insertQuery, articleID, contributorID); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error inserting new entries into articles_contributors: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = tx.Commit(); err != nil {
|
||||||
|
return fmt.Errorf("error committing transaction: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}()
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(err)
|
||||||
|
wait(i)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package model
|
package backend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -6,10 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (db *DB) WriteArticleTags(articleID int64, tagIDs []int64) error {
|
func (db *DB) WriteArticleTags(articleID int64, tagIDs []int64) error {
|
||||||
query := `
|
query := "INSERT INTO articles_tags (article_id, tag_id) VALUES (?, ?)"
|
||||||
INSERT INTO articles_tags (article_id, tag_id)
|
|
||||||
VALUES (?, ?)
|
|
||||||
`
|
|
||||||
|
|
||||||
for i := 0; i < TxMaxRetries; i++ {
|
for i := 0; i < TxMaxRetries; i++ {
|
||||||
err := func() error {
|
err := func() error {
|
||||||
@ -46,8 +43,8 @@ func (db *DB) GetArticleTags(articleID int64) ([]*Tag, error) {
|
|||||||
query := `
|
query := `
|
||||||
SELECT t.id, t.name
|
SELECT t.id, t.name
|
||||||
FROM articles a
|
FROM articles a
|
||||||
INNER JOIN articles_tags at ON a.id = at.article_id
|
INNER JOIN articles_tags at ON a.id = at.article_id
|
||||||
INNER JOIN tags t ON at.tag_id = t.id
|
INNER JOIN tags t ON at.tag_id = t.id
|
||||||
WHERE a.id = ?
|
WHERE a.id = ?
|
||||||
`
|
`
|
||||||
rows, err := db.Query(query, articleID)
|
rows, err := db.Query(query, articleID)
|
||||||
@ -68,8 +65,8 @@ func (db *DB) GetArticleTags(articleID int64) ([]*Tag, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) UpdateArticleTags(articleID int64, tagIDs []int64) error {
|
func (db *DB) UpdateArticleTags(articleID int64, tagIDs []int64) error {
|
||||||
query := `
|
deleteQuery := "DELETE FROM articles_tags WHERE article_id = ?"
|
||||||
`
|
insertQuery := "INSERT INTO articles_tags (article_id, tag_id) VALUES (?, ?)"
|
||||||
|
|
||||||
for i := 0; i < TxMaxRetries; i++ {
|
for i := 0; i < TxMaxRetries; i++ {
|
||||||
err := func() error {
|
err := func() error {
|
||||||
@ -78,6 +75,22 @@ func (db *DB) UpdateArticleTags(articleID int64, tagIDs []int64) error {
|
|||||||
return fmt.Errorf("error starting transaction: %v", err)
|
return fmt.Errorf("error starting transaction: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := tx.Exec(deleteQuery, articleID); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error deleting entries from articles_tags before inserting new ones: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tagID := range tagIDs {
|
||||||
|
if _, err := tx.Exec(insertQuery, articleID, tagID); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error inserting new entries into articles_tags: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err = tx.Commit(); err != nil {
|
if err = tx.Commit(); err != nil {
|
||||||
return fmt.Errorf("error committing transaction: %v", err)
|
return fmt.Errorf("error committing transaction: %v", err)
|
||||||
}
|
}
|
128
cmd/backend/atom.go
Normal file
128
cmd/backend/atom.go
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"git.streifling.com/jason/atom"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GenerateAtomFeed(c *Config, db *DB) (*string, error) {
|
||||||
|
feed := atom.NewFeed(c.Title)
|
||||||
|
feed.ID = atom.NewID("urn:feed:1")
|
||||||
|
feed.Subtitle = atom.NewText("text", c.Description)
|
||||||
|
|
||||||
|
linkID := feed.AddLink(atom.NewLink(c.Link))
|
||||||
|
feed.Links[linkID].Rel = "self"
|
||||||
|
|
||||||
|
feed.Generator = atom.NewGenerator("cpolis")
|
||||||
|
feed.Generator.URI = "https://git.streifling.com/jason/cpolis"
|
||||||
|
feed.Generator.Version = c.Version
|
||||||
|
|
||||||
|
articles, err := db.GetCertainArticles("published", true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting published articles for Atom feed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, article := range articles {
|
||||||
|
articleTitle, err := ConvertToPlain(article.Title)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error converting title to plain text for Atom feed: %v", err)
|
||||||
|
}
|
||||||
|
entry := atom.NewEntry(articleTitle)
|
||||||
|
entry.ID = atom.NewID(fmt.Sprint("urn:entry:", article.ID))
|
||||||
|
entry.Published = atom.NewDate(article.Created)
|
||||||
|
entry.Content = atom.NewContent(atom.OutOfLine, "text/html", fmt.Sprint(c.Domain, "/article/serve/", article.UUID))
|
||||||
|
|
||||||
|
if article.AutoGenerated {
|
||||||
|
entry.Summary = atom.NewText("text", "automatically generated")
|
||||||
|
} else {
|
||||||
|
articleSummary, err := ConvertToPlain(article.Summary)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error converting description to plain text for Atom feed: %v", err)
|
||||||
|
}
|
||||||
|
entry.Summary = atom.NewText("text", articleSummary)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(article.BannerLink) > 0 {
|
||||||
|
linkID := entry.AddLink(atom.NewLink(c.Domain + "/image/serve/" + article.BannerLink))
|
||||||
|
entry.Links[linkID].Rel = "enclosure"
|
||||||
|
entry.Links[linkID].Type = "image/webp"
|
||||||
|
}
|
||||||
|
|
||||||
|
authors, err := db.GetArticleAuthors(c, article.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting article's authors for Atom feed: %v", err)
|
||||||
|
}
|
||||||
|
for _, author := range authors {
|
||||||
|
user, err := db.GetUser(c, author.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting user info for Atom feed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
authorID := entry.AddAuthor(atom.NewPerson(user.FirstName + " " + user.LastName))
|
||||||
|
entry.Authors[authorID].URI = c.Domain + "/image/serve/" + user.ProfilePicLink
|
||||||
|
}
|
||||||
|
|
||||||
|
contributors, err := db.GetArticleContributors(c, article.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting article's contributors for Atom feed: %v", err)
|
||||||
|
}
|
||||||
|
for _, contributor := range contributors {
|
||||||
|
user, err := db.GetUser(c, contributor.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting user info for Atom feed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
contributorID := entry.AddContributor(atom.NewPerson(user.FirstName + " " + user.LastName))
|
||||||
|
entry.Contributors[contributorID].URI = c.Domain + "/image/serve/" + user.ProfilePicLink
|
||||||
|
}
|
||||||
|
|
||||||
|
tags, err := db.GetArticleTags(article.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting tags for articles for Atom feed: %v", err)
|
||||||
|
}
|
||||||
|
for _, tag := range tags {
|
||||||
|
entry.AddCategory(atom.NewCategory(tag.Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
if article.IsInIssue || article.AutoGenerated {
|
||||||
|
entry.AddCategory(atom.NewCategory(fmt.Sprint("Orient Express ", article.IssueID)))
|
||||||
|
}
|
||||||
|
if article.AutoGenerated {
|
||||||
|
entry.AddCategory(atom.NewCategory("autogenerated"))
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.Updated = atom.NewDate(article.Created)
|
||||||
|
feed.AddEntry(entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = feed.Check(); err != nil {
|
||||||
|
return nil, fmt.Errorf("error checking Atom feed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
atom, err := feed.ToXML("UTF-8")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error converting Atom feed to XML: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &atom, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func SaveAtomFeed(filename string, feed *string) error {
|
||||||
|
file, err := os.Create(filename)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error creating file for Atom feed: %v", err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
if err = file.Chmod(0644); err != nil {
|
||||||
|
return fmt.Errorf("error setting permissions for Atom file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = io.WriteString(file, *feed); err != nil {
|
||||||
|
return fmt.Errorf("error writing to Atom file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
291
cmd/backend/config.go
Normal file
291
cmd/backend/config.go
Normal file
@ -0,0 +1,291 @@
|
|||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
AESKeyFile string
|
||||||
|
ArticleDir string
|
||||||
|
AtomFile string
|
||||||
|
ConfigFile string
|
||||||
|
DBName string
|
||||||
|
Description string
|
||||||
|
Domain string
|
||||||
|
FirebaseKey string
|
||||||
|
Link string
|
||||||
|
LogFile string
|
||||||
|
PDFDir string
|
||||||
|
PicsDir string
|
||||||
|
Port string
|
||||||
|
Title string
|
||||||
|
Version string
|
||||||
|
WebDir string
|
||||||
|
CookieExpiryHours int
|
||||||
|
MaxBannerHeight int
|
||||||
|
MaxBannerWidth int
|
||||||
|
MaxImgHeight int
|
||||||
|
MaxImgWidth int
|
||||||
|
}
|
||||||
|
|
||||||
|
func newConfig() *Config {
|
||||||
|
return &Config{
|
||||||
|
AESKeyFile: "/var/www/cpolis/aes.key",
|
||||||
|
ArticleDir: "/var/www/cpolis/articles",
|
||||||
|
AtomFile: "/var/www/cpolis/cpolis.atom",
|
||||||
|
ConfigFile: "/etc/cpolis/config.toml",
|
||||||
|
CookieExpiryHours: 24 * 30,
|
||||||
|
DBName: "cpolis",
|
||||||
|
FirebaseKey: "/var/www/cpolis/serviceAccountKey.json",
|
||||||
|
LogFile: "/var/log/cpolis.log",
|
||||||
|
MaxBannerHeight: 1080,
|
||||||
|
MaxBannerWidth: 1920,
|
||||||
|
MaxImgHeight: 1080,
|
||||||
|
MaxImgWidth: 1920,
|
||||||
|
PDFDir: "/var/www/cpolis/pdfs",
|
||||||
|
PicsDir: "/var/www/cpolis/pics",
|
||||||
|
Port: ":8080",
|
||||||
|
Version: "v0.15.0",
|
||||||
|
WebDir: "/var/www/cpolis/web",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mkDir(path string, perm fs.FileMode) (string, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
stringSlice := strings.Split(path, "/")
|
||||||
|
name := stringSlice[len(stringSlice)-1]
|
||||||
|
|
||||||
|
path, err = filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error finding absolute path for %v directory: %v", name, err)
|
||||||
|
}
|
||||||
|
if err = os.MkdirAll(path, perm); err != nil {
|
||||||
|
return "", fmt.Errorf("error creating %v directory: %v", name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mkFile(path string, filePerm, dirPerm fs.FileMode) (string, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
path, err = filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error finding absolute path for %v: %v", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
stringSlice := strings.Split(path, "/")
|
||||||
|
_, err = os.Stat(path)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
dir := strings.Join(stringSlice[:len(stringSlice)-1], "/")
|
||||||
|
if err = os.MkdirAll(dir, dirPerm); err != nil {
|
||||||
|
return "", fmt.Errorf("error creating %v: %v", dir, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fileName := stringSlice[len(stringSlice)-1]
|
||||||
|
file, err := os.Create(dir + "/" + fileName)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error creating %v: %v", fileName, err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
if err = file.Chmod(filePerm); err != nil {
|
||||||
|
return "", fmt.Errorf("error setting permissions for %v: %v", fileName, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) handleCliArgs() error {
|
||||||
|
var port int
|
||||||
|
var err error
|
||||||
|
|
||||||
|
flag.StringVar(&c.AESKeyFile, "aes", c.AESKeyFile, "aes key file")
|
||||||
|
flag.StringVar(&c.ArticleDir, "articles", c.ArticleDir, "articles directory")
|
||||||
|
flag.StringVar(&c.AtomFile, "feed", c.AtomFile, "atom feed file")
|
||||||
|
flag.StringVar(&c.ConfigFile, "config", c.ConfigFile, "config file")
|
||||||
|
flag.StringVar(&c.DBName, "db", c.DBName, "DB name")
|
||||||
|
flag.StringVar(&c.Description, "desc", c.Description, "channel description")
|
||||||
|
flag.StringVar(&c.Domain, "domain", c.Domain, "domain name")
|
||||||
|
flag.StringVar(&c.FirebaseKey, "firebase", c.FirebaseKey, "Firebase service account key file")
|
||||||
|
flag.StringVar(&c.Link, "link", c.Link, "channel Link")
|
||||||
|
flag.StringVar(&c.LogFile, "log", c.LogFile, "log file")
|
||||||
|
flag.StringVar(&c.PDFDir, "pdfs", c.PDFDir, "pdf directory")
|
||||||
|
flag.StringVar(&c.PicsDir, "pics", c.PicsDir, "pictures directory")
|
||||||
|
flag.StringVar(&c.Title, "title", c.Title, "channel title")
|
||||||
|
flag.StringVar(&c.WebDir, "web", c.WebDir, "web directory")
|
||||||
|
flag.IntVar(&c.CookieExpiryHours, "cookie-expiry-hours", c.CookieExpiryHours, "cookies expire after this amount of hours")
|
||||||
|
flag.IntVar(&c.MaxBannerHeight, "banner-height", c.MaxBannerHeight, "maximum banner height")
|
||||||
|
flag.IntVar(&c.MaxBannerWidth, "banner-width", c.MaxBannerWidth, "maximum banner width")
|
||||||
|
flag.IntVar(&c.MaxImgHeight, "img-height", c.MaxImgHeight, "maximum image height")
|
||||||
|
flag.IntVar(&c.MaxImgWidth, "img-width", c.MaxImgWidth, "maximum image width")
|
||||||
|
flag.IntVar(&port, "port", port, "port")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if port != 0 {
|
||||||
|
c.Port = fmt.Sprint(":", port)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.ConfigFile, err = mkFile(c.ConfigFile, 0600, 0700)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error setting up file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) handleFile(configFile string) error {
|
||||||
|
_, err := toml.DecodeFile(configFile, c)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error reading config file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) setupConfig(cliConfig *Config) error {
|
||||||
|
var err error
|
||||||
|
defaultConfig := newConfig()
|
||||||
|
|
||||||
|
if cliConfig.AESKeyFile != defaultConfig.AESKeyFile {
|
||||||
|
c.AESKeyFile = cliConfig.AESKeyFile
|
||||||
|
}
|
||||||
|
c.AESKeyFile, err = mkFile(c.AESKeyFile, 0600, 0700)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error setting up file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.ArticleDir != defaultConfig.ArticleDir {
|
||||||
|
c.ArticleDir = cliConfig.ArticleDir
|
||||||
|
}
|
||||||
|
c.ArticleDir, err = mkDir(c.ArticleDir, 0700)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error setting up directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.AtomFile != defaultConfig.AtomFile {
|
||||||
|
c.AtomFile = cliConfig.AtomFile
|
||||||
|
}
|
||||||
|
c.AtomFile, err = mkFile(c.AtomFile, 0644, 0744)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error setting up file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.CookieExpiryHours != defaultConfig.CookieExpiryHours {
|
||||||
|
c.CookieExpiryHours = cliConfig.CookieExpiryHours
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.DBName != defaultConfig.DBName {
|
||||||
|
c.DBName = cliConfig.DBName
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.Description != defaultConfig.Description {
|
||||||
|
c.Description = cliConfig.Description
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.Domain != defaultConfig.Domain {
|
||||||
|
c.Domain = cliConfig.Domain
|
||||||
|
}
|
||||||
|
domainStrings := strings.Split(c.Domain, ":")
|
||||||
|
if domainStrings[0] != "http" && domainStrings[0] != "https" {
|
||||||
|
c.Domain = "https://" + c.Domain
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.FirebaseKey != defaultConfig.FirebaseKey {
|
||||||
|
c.FirebaseKey = cliConfig.FirebaseKey
|
||||||
|
}
|
||||||
|
c.FirebaseKey, err = mkFile(c.FirebaseKey, 0600, 0700)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error setting up file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.Link != defaultConfig.Link {
|
||||||
|
c.Link = cliConfig.Link
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.LogFile != defaultConfig.LogFile {
|
||||||
|
c.LogFile = cliConfig.LogFile
|
||||||
|
}
|
||||||
|
c.LogFile, err = mkFile(c.LogFile, 0600, 0700)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error setting up file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.MaxBannerHeight != defaultConfig.MaxBannerHeight {
|
||||||
|
c.MaxBannerHeight = cliConfig.MaxBannerHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.MaxBannerWidth != defaultConfig.MaxBannerWidth {
|
||||||
|
c.MaxBannerWidth = cliConfig.MaxBannerWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.MaxImgHeight != defaultConfig.MaxImgHeight {
|
||||||
|
c.MaxImgHeight = cliConfig.MaxImgHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.MaxImgWidth != defaultConfig.MaxImgWidth {
|
||||||
|
c.MaxImgWidth = cliConfig.MaxImgWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.PDFDir != defaultConfig.PDFDir {
|
||||||
|
c.PDFDir = cliConfig.PDFDir
|
||||||
|
}
|
||||||
|
c.PDFDir, err = mkDir(c.PDFDir, 0700)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error setting up directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.PicsDir != defaultConfig.PicsDir {
|
||||||
|
c.PicsDir = cliConfig.PicsDir
|
||||||
|
}
|
||||||
|
c.PicsDir, err = mkDir(c.PicsDir, 0700)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error setting up directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.Port != defaultConfig.Port {
|
||||||
|
c.Port = cliConfig.Port
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.Title != defaultConfig.Title {
|
||||||
|
c.Title = cliConfig.Title
|
||||||
|
}
|
||||||
|
|
||||||
|
if cliConfig.WebDir != defaultConfig.WebDir {
|
||||||
|
c.WebDir = cliConfig.WebDir
|
||||||
|
}
|
||||||
|
c.WebDir, err = mkDir(c.WebDir, 0700)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error setting up directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleConfig() (*Config, error) {
|
||||||
|
config := newConfig()
|
||||||
|
cliConfig := newConfig()
|
||||||
|
|
||||||
|
if err := cliConfig.handleCliArgs(); err != nil {
|
||||||
|
return nil, fmt.Errorf("error handling cli arguments: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := config.handleFile(cliConfig.ConfigFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error reading configuration file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = config.setupConfig(cliConfig); err != nil {
|
||||||
|
return nil, fmt.Errorf("error setting up files: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config, nil
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package model
|
package backend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
59
cmd/backend/docx.go
Normal file
59
cmd/backend/docx.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ConvertToMarkdown(c *Config, filename string) ([]byte, error) {
|
||||||
|
var stderr bytes.Buffer
|
||||||
|
|
||||||
|
articleID := uuid.New()
|
||||||
|
articleFileName := fmt.Sprint("/tmp/", articleID, ".md")
|
||||||
|
|
||||||
|
tmpDir, err := os.MkdirTemp("/tmp", "cpolis_images")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error creating temporary directory: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
cmd := exec.Command("pandoc", "-s", "-f", "docx", "-t", "commonmark_x", "-o", articleFileName, "--extract-media", tmpDir, filename) // TODO: Is writing to a file necessary?
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
if err = cmd.Run(); err != nil {
|
||||||
|
return nil, fmt.Errorf("error converting docx to markdown: %v: %v", err, stderr.String())
|
||||||
|
}
|
||||||
|
defer os.Remove(articleFileName)
|
||||||
|
|
||||||
|
articleContent, err := os.ReadFile(articleFileName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error reading markdown file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
imageNames, err := filepath.Glob(filepath.Join(tmpDir, "/media/*"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting docx images from temporary directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, name := range imageNames {
|
||||||
|
image, err := os.Open(name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error opening image file %v: %v", name, err)
|
||||||
|
}
|
||||||
|
defer image.Close()
|
||||||
|
|
||||||
|
newImageName, err := SaveImage(image, c.MaxImgHeight, c.MaxImgWidth, c.PicsDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error saving image %v: %v", name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
articleContent = regexp.MustCompile(name).ReplaceAll(articleContent, []byte(c.PicsDir+"/"+newImageName))
|
||||||
|
}
|
||||||
|
|
||||||
|
return articleContent, nil
|
||||||
|
}
|
49
cmd/backend/files.go
Normal file
49
cmd/backend/files.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CopyFile(src, dst string) error {
|
||||||
|
srcFile, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error opening source file: %v", err)
|
||||||
|
}
|
||||||
|
defer srcFile.Close()
|
||||||
|
|
||||||
|
dstFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error opening destination file: %v", err)
|
||||||
|
}
|
||||||
|
defer dstFile.Close()
|
||||||
|
|
||||||
|
if _, err = io.Copy(dstFile, srcFile); err != nil {
|
||||||
|
return fmt.Errorf("error copying file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dstFile.Sync()
|
||||||
|
}
|
||||||
|
|
||||||
|
func WriteFile(path string, src io.Reader) error {
|
||||||
|
file, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return fmt.Errorf("error creating file: %v", err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
if _, err = io.Copy(file, src); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return fmt.Errorf("error copying file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = file.Sync(); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return fmt.Errorf("error syncing file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
42
cmd/backend/firebase.go
Normal file
42
cmd/backend/firebase.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
firebase "firebase.google.com/go/v4"
|
||||||
|
"firebase.google.com/go/v4/auth"
|
||||||
|
"google.golang.org/api/option"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Client struct{ *auth.Client }
|
||||||
|
|
||||||
|
func NewClient(c *Config) (*Client, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
client := new(Client)
|
||||||
|
ctx := context.Background()
|
||||||
|
opt := option.WithCredentialsFile(c.FirebaseKey)
|
||||||
|
|
||||||
|
app, err := firebase.NewApp(ctx, nil, opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
client.Client, err = app.Auth(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Verify(idToken string) (*auth.Token, error) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
token, err := c.VerifyIDTokenAndCheckRevoked(ctx, idToken)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return token, nil
|
||||||
|
}
|
106
cmd/backend/images.go
Normal file
106
cmd/backend/images.go
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"image"
|
||||||
|
"io"
|
||||||
|
"io/fs"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/chai2010/webp"
|
||||||
|
"github.com/disintegration/imaging"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrUnsupportedFormat error = image.ErrFormat // used internally by imaging
|
||||||
|
|
||||||
|
func SaveImage(src io.Reader, maxHeight, maxWidth int, path string) (string, error) {
|
||||||
|
img, err := imaging.Decode(src, imaging.AutoOrientation(true))
|
||||||
|
if err != nil {
|
||||||
|
if err == ErrUnsupportedFormat {
|
||||||
|
return "", ErrUnsupportedFormat
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("error decoding image: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if img.Bounds().Dy() > maxHeight {
|
||||||
|
img = imaging.Resize(img, 0, maxHeight, imaging.Lanczos)
|
||||||
|
}
|
||||||
|
if img.Bounds().Dx() > maxWidth {
|
||||||
|
img = imaging.Resize(img, maxWidth, 0, imaging.Lanczos)
|
||||||
|
}
|
||||||
|
|
||||||
|
filename := fmt.Sprint(uuid.New(), ".webp")
|
||||||
|
file, err := os.Create(filepath.Join(path, filename))
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error creating new image file: %v", err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
if err = webp.Encode(file, img, &webp.Options{Quality: 80}); err != nil {
|
||||||
|
return "", fmt.Errorf("error encoding image as webp: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return filename, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CleanUpImages(c *Config) {
|
||||||
|
for {
|
||||||
|
if err := filepath.Walk(c.PicsDir, func(path string, info fs.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() {
|
||||||
|
imageName := info.Name()
|
||||||
|
absImageName := path
|
||||||
|
|
||||||
|
if err = filepath.Walk(c.ArticleDir, func(path string, info fs.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() {
|
||||||
|
mdFile, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer mdFile.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(mdFile)
|
||||||
|
imageWasFound := false
|
||||||
|
|
||||||
|
for scanner.Scan() {
|
||||||
|
if strings.Contains(scanner.Text(), imageName) {
|
||||||
|
imageWasFound = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !imageWasFound {
|
||||||
|
if err = os.Remove(absImageName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return scanner.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Hour)
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package model
|
package backend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -23,7 +23,6 @@ func (db *DB) AddIssue() (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) PublishLatestIssue() error {
|
func (db *DB) PublishLatestIssue() error {
|
||||||
var id int64
|
|
||||||
txOptions := &sql.TxOptions{Isolation: sql.LevelSerializable}
|
txOptions := &sql.TxOptions{Isolation: sql.LevelSerializable}
|
||||||
updateQuery := "UPDATE issues SET published = true WHERE published = false"
|
updateQuery := "UPDATE issues SET published = true WHERE published = false"
|
||||||
insertQuery := "INSERT INTO issues (published) VALUES (?)"
|
insertQuery := "INSERT INTO issues (published) VALUES (?)"
|
||||||
@ -35,7 +34,7 @@ func (db *DB) PublishLatestIssue() error {
|
|||||||
return fmt.Errorf("error starting transaction: %v", err)
|
return fmt.Errorf("error starting transaction: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := tx.Exec(updateQuery, id); err != nil {
|
if _, err := tx.Exec(updateQuery); err != nil {
|
||||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package control
|
package backend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -1,4 +1,4 @@
|
|||||||
package model
|
package backend
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
634
cmd/backend/users.go
Normal file
634
cmd/backend/users.go
Normal file
@ -0,0 +1,634 @@
|
|||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/aes"
|
||||||
|
"crypto/cipher"
|
||||||
|
"crypto/rand"
|
||||||
|
"database/sql"
|
||||||
|
"encoding/base64"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
Admin = iota
|
||||||
|
Publisher
|
||||||
|
Editor
|
||||||
|
Author
|
||||||
|
NonExistent
|
||||||
|
)
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
UserName string
|
||||||
|
FirstName string
|
||||||
|
LastName string
|
||||||
|
Email string
|
||||||
|
ProfilePicLink string
|
||||||
|
ID int64
|
||||||
|
Role int
|
||||||
|
}
|
||||||
|
|
||||||
|
func readKey(filename string) ([]byte, error) {
|
||||||
|
key, err := os.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error reading from aes key file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(key) != 44 {
|
||||||
|
return nil, errors.New("key is not 32 bytes long")
|
||||||
|
}
|
||||||
|
|
||||||
|
key, err = base64.StdEncoding.DecodeString(string(key))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error base64 decoding key: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return key, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func key(c *Config) ([]byte, error) {
|
||||||
|
key, err := readKey(c.AESKeyFile)
|
||||||
|
if err != nil {
|
||||||
|
key = make([]byte, 32)
|
||||||
|
if _, err := rand.Read(key); err != nil {
|
||||||
|
return nil, fmt.Errorf("error generating random key: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fileKey := make([]byte, 44)
|
||||||
|
base64.StdEncoding.Encode(fileKey, key)
|
||||||
|
if err = os.WriteFile(c.AESKeyFile, fileKey, 0600); err != nil {
|
||||||
|
return nil, fmt.Errorf("error writing key to file: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return key, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func aesEncrypt(c *Config, plaintext string) (string, error) {
|
||||||
|
key, err := key(c)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error retrieving key: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
block, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error creating cipher block: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
gcm, err := cipher.NewGCM(block)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error creating new gcm: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
nonce := make([]byte, gcm.NonceSize())
|
||||||
|
if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
|
||||||
|
return "", fmt.Errorf("error creating nonce: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cipherText := gcm.Seal(nonce, nonce, []byte(plaintext), nil)
|
||||||
|
return base64.StdEncoding.EncodeToString(cipherText), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func aesDecrypt(c *Config, ciphertext string) (string, error) {
|
||||||
|
key, err := key(c)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error retrieving key: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
block, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error creating cipher block: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
gcm, err := cipher.NewGCM(block)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error creating new gcm: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := base64.StdEncoding.DecodeString(ciphertext)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error base64 decoding ciphertext: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
nonceSize := gcm.NonceSize()
|
||||||
|
nonce, cipherText := data[:nonceSize], data[nonceSize:]
|
||||||
|
|
||||||
|
plaintext, err := gcm.Open(nil, nonce, cipherText, nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error aes decoding ciphertext: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(plaintext), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) AddUser(c *Config, u *User, pass string) (int64, error) {
|
||||||
|
hashedPass, err := bcrypt.GenerateFromPassword([]byte(pass), bcrypt.DefaultCost)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("error creating password hash: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
aesFirstName, err := aesEncrypt(c, u.FirstName)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("error encrypting first name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
aesLastName, err := aesEncrypt(c, u.LastName)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("error encrypting last name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
aesEmail, err := aesEncrypt(c, u.Email)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("error encrypting email: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
INSERT INTO users (username, password, first_name, last_name, email, profile_pic_link, role)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
|
result, err := db.Exec(query, u.UserName, string(hashedPass), aesFirstName, aesLastName, aesEmail, u.ProfilePicLink, u.Role)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("error inserting new user %v into DB: %v", u.UserName, err)
|
||||||
|
}
|
||||||
|
id, err := result.LastInsertId()
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("error inserting user into DB: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return id, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) GetID(userName string) int64 {
|
||||||
|
var id int64
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id
|
||||||
|
FROM users
|
||||||
|
WHERE username = ?
|
||||||
|
`
|
||||||
|
row := db.QueryRow(query, userName)
|
||||||
|
if err := row.Scan(&id); err != nil { // seems like the only possible error is ErrNoRows
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) CheckPassword(id int64, pass string) error {
|
||||||
|
var queriedPass string
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT password
|
||||||
|
FROM users
|
||||||
|
WHERE id = ?
|
||||||
|
`
|
||||||
|
row := db.QueryRow(query, id)
|
||||||
|
if err := row.Scan(&queriedPass); err != nil {
|
||||||
|
return fmt.Errorf("error reading password from DB: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := bcrypt.CompareHashAndPassword([]byte(queriedPass), []byte(pass)); err != nil {
|
||||||
|
return fmt.Errorf("incorrect password: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tx *Tx) ChangePassword(id int64, oldPass, newPass string) error {
|
||||||
|
var queriedPass string
|
||||||
|
getQuery := `
|
||||||
|
SELECT password
|
||||||
|
FROM users
|
||||||
|
WHERE id = ?
|
||||||
|
`
|
||||||
|
row := tx.QueryRow(getQuery, id)
|
||||||
|
if err := row.Scan(&queriedPass); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error reading password from DB: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := bcrypt.CompareHashAndPassword([]byte(queriedPass), []byte(oldPass)); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("incorrect password: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
newHashedPass, err := bcrypt.GenerateFromPassword([]byte(newPass), bcrypt.DefaultCost)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error creating password hash: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
setQuery := `
|
||||||
|
UPDATE users
|
||||||
|
SET password = ?
|
||||||
|
WHERE id = ?
|
||||||
|
`
|
||||||
|
if _, err = tx.Exec(setQuery, string(newHashedPass), id); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error updating password in DB: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: No need for ID field in general
|
||||||
|
func (db *DB) GetUser(c *Config, id int64) (*User, error) {
|
||||||
|
var aesFirstName, aesLastName, aesEmail string
|
||||||
|
var err error
|
||||||
|
|
||||||
|
user := new(User)
|
||||||
|
query := `
|
||||||
|
SELECT id, username, first_name, last_name, email, profile_pic_link, role
|
||||||
|
FROM users
|
||||||
|
WHERE id = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
row := db.QueryRow(query, id)
|
||||||
|
if err := row.Scan(&user.ID, &user.UserName, &aesFirstName, &aesLastName, &aesEmail, &user.ProfilePicLink, &user.Role); err != nil {
|
||||||
|
return nil, fmt.Errorf("error reading user information: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
user.FirstName, err = aesDecrypt(c, aesFirstName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decrypting first name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
user.LastName, err = aesDecrypt(c, aesLastName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decrypting last name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Email, err = aesDecrypt(c, aesEmail)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decrypting email: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return user, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) UpdateOwnUserAttributes(c *Config, id int64, userName, firstName, lastName, email, profilePicLink, oldPass, newPass string) error {
|
||||||
|
var err error
|
||||||
|
tx := new(Tx)
|
||||||
|
passwordEmpty := len(newPass) == 0
|
||||||
|
|
||||||
|
for i := 0; i < TxMaxRetries; i++ {
|
||||||
|
err := func() error {
|
||||||
|
tx.Tx, err = db.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error starting transaction: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !passwordEmpty {
|
||||||
|
if err = tx.ChangePassword(id, oldPass, newPass); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error changing password: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
aesFirstName, err := aesEncrypt(c, firstName)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error encrypting first name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
aesLastName, err := aesEncrypt(c, lastName)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error encrypting last name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
aesEmail, err := aesEncrypt(c, email)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error encrypting email: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = tx.UpdateAttributes(
|
||||||
|
&Attribute{Table: "users", ID: id, AttName: "username", Value: userName},
|
||||||
|
&Attribute{Table: "users", ID: id, AttName: "first_name", Value: aesFirstName},
|
||||||
|
&Attribute{Table: "users", ID: id, AttName: "last_name", Value: aesLastName},
|
||||||
|
&Attribute{Table: "users", ID: id, AttName: "email", Value: aesEmail},
|
||||||
|
&Attribute{Table: "users", ID: id, AttName: "profile_pic_link", Value: profilePicLink},
|
||||||
|
); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error updating attributes in DB: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = tx.Commit(); err != nil {
|
||||||
|
return fmt.Errorf("error committing transaction: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}()
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(err)
|
||||||
|
wait(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) AddFirstUser(c *Config, u *User, pass string) (int64, error) {
|
||||||
|
var numUsers int64
|
||||||
|
txOptions := &sql.TxOptions{Isolation: sql.LevelSerializable}
|
||||||
|
selectQuery := "SELECT COUNT(*) FROM users"
|
||||||
|
insertQuery := `
|
||||||
|
INSERT INTO users (username, password, first_name, last_name, email, profile_pic_link, role)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
|
for i := 0; i < TxMaxRetries; i++ {
|
||||||
|
id, err := func() (int64, error) {
|
||||||
|
tx, err := db.BeginTx(context.Background(), txOptions)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("error starting transaction: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := tx.QueryRow(selectQuery).Scan(&numUsers); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("error getting ID of %v: %v", u.UserName, err)
|
||||||
|
}
|
||||||
|
if numUsers != 0 {
|
||||||
|
if err = tx.Commit(); err != nil {
|
||||||
|
return 0, fmt.Errorf("error committing transaction: %v", err)
|
||||||
|
}
|
||||||
|
return -1, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
hashedPass, err := bcrypt.GenerateFromPassword([]byte(pass), bcrypt.DefaultCost)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("error creating password hash: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
aesFirstName, err := aesEncrypt(c, u.FirstName)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("error encrypting first name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
aesLastName, err := aesEncrypt(c, u.LastName)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("error encrypting last name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
aesEmail, err := aesEncrypt(c, u.Email)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("error encrypting email: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := tx.Exec(insertQuery, u.UserName, string(hashedPass), aesFirstName, aesLastName, aesEmail, u.ProfilePicLink, u.Role)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("error inserting new user %v into DB: %v", u.UserName, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := result.LastInsertId()
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("error inserting user into DB: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = tx.Commit(); err != nil {
|
||||||
|
return 0, fmt.Errorf("error committing transaction: %v", err)
|
||||||
|
}
|
||||||
|
return id, nil
|
||||||
|
}()
|
||||||
|
if err == nil {
|
||||||
|
return id, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(err)
|
||||||
|
wait(i)
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) GetAllUsers(c *Config) ([]*User, error) {
|
||||||
|
var aesFirstName, aesLastName, aesEmail string
|
||||||
|
var err error
|
||||||
|
|
||||||
|
query := "SELECT id, username, first_name, last_name, email, profile_pic_link, role FROM users"
|
||||||
|
|
||||||
|
rows, err := db.Query(query)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting all users from DB: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
users := make([]*User, 0)
|
||||||
|
for rows.Next() {
|
||||||
|
user := new(User)
|
||||||
|
if err = rows.Scan(&user.ID, &user.UserName, &aesFirstName, &aesLastName, &aesEmail, &user.ProfilePicLink, &user.Role); err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting user info: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
user.FirstName, err = aesDecrypt(c, aesFirstName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decrypting first name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
user.LastName, err = aesDecrypt(c, aesLastName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decrypting last name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Email, err = aesDecrypt(c, aesEmail)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decrypting email: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
users = append(users, user)
|
||||||
|
}
|
||||||
|
|
||||||
|
return users, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) GetAllUsersMap(c *Config) (map[int64]*User, error) {
|
||||||
|
var aesFirstName, aesLastName, aesEmail string
|
||||||
|
var err error
|
||||||
|
|
||||||
|
query := "SELECT id, username, first_name, last_name, email, profile_pic_link, role FROM users"
|
||||||
|
|
||||||
|
rows, err := db.Query(query)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting all users from DB: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
users := make(map[int64]*User, 0)
|
||||||
|
for rows.Next() {
|
||||||
|
user := new(User)
|
||||||
|
if err = rows.Scan(&user.ID, &user.UserName, &aesFirstName, &aesLastName, &aesEmail, &user.ProfilePicLink, &user.Role); err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting user info: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
user.FirstName, err = aesDecrypt(c, aesFirstName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decrypting first name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
user.LastName, err = aesDecrypt(c, aesLastName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decrypting last name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Email, err = aesDecrypt(c, aesEmail)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decrypting email: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
users[user.ID] = user
|
||||||
|
}
|
||||||
|
|
||||||
|
return users, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tx *Tx) SetPassword(id int64, newPass string) error {
|
||||||
|
hashedPass, err := bcrypt.GenerateFromPassword([]byte(newPass), bcrypt.DefaultCost)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error creating password hash: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
setQuery := "UPDATE users SET password = ? WHERE id = ?"
|
||||||
|
if _, err = tx.Exec(setQuery, string(hashedPass), id); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error updating password in DB: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) UpdateUserAttributes(c *Config, id int64, userName, firstName, lastName, email, profilePicLink, newPass string, role int) error {
|
||||||
|
var err error
|
||||||
|
tx := new(Tx)
|
||||||
|
passwordEmpty := len(newPass) == 0
|
||||||
|
|
||||||
|
for i := 0; i < TxMaxRetries; i++ {
|
||||||
|
err := func() error {
|
||||||
|
tx.Tx, err = db.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error starting transaction: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !passwordEmpty {
|
||||||
|
if err = tx.SetPassword(id, newPass); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error changing password: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
aesFirstName, err := aesEncrypt(c, firstName)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error encrypting first name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
aesLastName, err := aesEncrypt(c, lastName)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error encrypting last name: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
aesEmail, err := aesEncrypt(c, email)
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error encrypting email: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = tx.UpdateAttributes(
|
||||||
|
&Attribute{Table: "users", ID: id, AttName: "username", Value: userName},
|
||||||
|
&Attribute{Table: "users", ID: id, AttName: "first_name", Value: aesFirstName},
|
||||||
|
&Attribute{Table: "users", ID: id, AttName: "last_name", Value: aesLastName},
|
||||||
|
&Attribute{Table: "users", ID: id, AttName: "email", Value: aesEmail},
|
||||||
|
&Attribute{Table: "users", ID: id, AttName: "profile_pic_link", Value: profilePicLink},
|
||||||
|
&Attribute{Table: "users", ID: id, AttName: "role", Value: role},
|
||||||
|
); err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error updating attributes in DB: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = tx.Commit(); err != nil {
|
||||||
|
return fmt.Errorf("error committing transaction: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}()
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(err)
|
||||||
|
wait(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) DeleteUser(id int64) error {
|
||||||
|
query := "DELETE FROM users WHERE id = ?"
|
||||||
|
|
||||||
|
_, err := db.Exec(query, id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting user %v from DB: %v", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
111
cmd/calls/articles.go
Normal file
111
cmd/calls/articles.go
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
package calls
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func incrementClicks(db *b.DB, a *b.Article) error {
|
||||||
|
a.Clicks++
|
||||||
|
if err := db.UpdateAttributes(&b.Attribute{Table: "articles", ID: a.ID, AttName: "clicks", Value: a.Clicks}); err != nil {
|
||||||
|
return fmt.Errorf("error updating click attribute of article %v: %v", a.ID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.IsInIssue {
|
||||||
|
issue, err := db.GetArticle(a.IssueID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error getting issue %v: %v", a.IssueID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
issue.Clicks++
|
||||||
|
if err := db.UpdateAttributes(&b.Attribute{Table: "articles", ID: issue.ID, AttName: "clicks", Value: issue.Clicks}); err != nil {
|
||||||
|
return fmt.Errorf("error updating click attribute of issue %v: %v", issue.ID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ServeArticle(c *b.Config, db *b.DB) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !tokenIsVerified(w, r, c) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
idString := r.PathValue("id")
|
||||||
|
id, err := strconv.ParseInt(idString, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
article, err := db.GetArticle(id)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !article.Published {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
articleAbsName := fmt.Sprint(c.ArticleDir, "/", article.ID, ".md")
|
||||||
|
contentBytes, err := os.ReadFile(articleAbsName)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := b.ConvertToHTML(string(contentBytes))
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = incrementClicks(db, article); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = fmt.Fprint(w, content); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ServeClicks(db *b.DB) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
idString := r.PathValue("id")
|
||||||
|
id, err := strconv.ParseInt(idString, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
article, err := db.GetArticle(id)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = fmt.Fprint(w, article.Clicks); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
cmd/calls/atom.go
Normal file
26
cmd/calls/atom.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package calls
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ServeAtomFeed(c *b.Config) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !tokenIsVerified(w, r, c) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
absFilepath, err := filepath.Abs(c.AtomFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.ServeFile(w, r, absFilepath)
|
||||||
|
}
|
||||||
|
}
|
29
cmd/calls/images.go
Normal file
29
cmd/calls/images.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package calls
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
f "streifling.com/jason/cpolis/cmd/frontend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ServeImage(c *b.Config, s map[string]*f.Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if _, err := f.ManageSession(w, r, c, s); err != nil {
|
||||||
|
if !tokenIsVerified(w, r, c) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
absFilepath, err := filepath.Abs(c.PicsDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.ServeFile(w, r, absFilepath+"/"+r.PathValue("pic"))
|
||||||
|
}
|
||||||
|
}
|
47
cmd/calls/pdf.go
Normal file
47
cmd/calls/pdf.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package calls
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ServePDFList(c *b.Config) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !tokenIsVerified(w, r, c) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
files, err := os.ReadDir(c.PDFDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fileNames := make([]string, 0)
|
||||||
|
for _, file := range files {
|
||||||
|
fileNames = append(fileNames, file.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
if err = json.NewEncoder(w).Encode(fileNames); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ServePDF(c *b.Config) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !tokenIsVerified(w, r, c) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.ServeFile(w, r, c.PDFDir+"/"+r.PathValue("id"))
|
||||||
|
}
|
||||||
|
}
|
34
cmd/calls/verification.go
Normal file
34
cmd/calls/verification.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package calls
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
// tokenIsVerified verifies that a request is authorized. It returns a bool.
|
||||||
|
func tokenIsVerified(w http.ResponseWriter, r *http.Request, c *b.Config) bool {
|
||||||
|
idToken := r.Header.Get("Authorization")
|
||||||
|
if idToken == "" {
|
||||||
|
log.Println("Authorization header missing")
|
||||||
|
http.Error(w, "Authorization header missing", http.StatusUnauthorized)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := b.NewClient(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = client.Verify(idToken)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusUnauthorized)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
@ -1,50 +0,0 @@
|
|||||||
package control
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.streifling.com/jason/rss"
|
|
||||||
"streifling.com/jason/cpolis/cmd/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetChannel(db *model.DB, title, link, description string) (*rss.Channel, error) {
|
|
||||||
channel := &rss.Channel{
|
|
||||||
Title: title,
|
|
||||||
Link: link,
|
|
||||||
Description: description,
|
|
||||||
Items: make([]*rss.Item, 0),
|
|
||||||
}
|
|
||||||
|
|
||||||
articles, err := db.GetCertainArticles(true, false)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error fetching published articles: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, article := range articles {
|
|
||||||
tags, err := db.GetArticleTags(article.ID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error fetching tags for article %v: %v", article.Title, err)
|
|
||||||
}
|
|
||||||
tagNames := make([]string, 0)
|
|
||||||
for _, tag := range tags {
|
|
||||||
tagNames = append(tagNames, tag.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
user, err := db.GetUser(article.AuthorID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error finding user %v: %v", article.AuthorID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
channel.Items = append(channel.Items, &rss.Item{
|
|
||||||
Title: article.Title,
|
|
||||||
Author: user.FirstName + user.LastName,
|
|
||||||
PubDate: article.Created.Format(time.RFC1123Z),
|
|
||||||
Description: article.Description,
|
|
||||||
Content: &rss.Content{Value: article.Content},
|
|
||||||
Categories: tagNames,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return channel, nil
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
package control
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/rand"
|
|
||||||
"encoding/gob"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/gorilla/sessions"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CookieStore struct {
|
|
||||||
sessions.CookieStore
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewKey() ([]byte, error) {
|
|
||||||
key := make([]byte, 32)
|
|
||||||
|
|
||||||
if _, err := io.ReadFull(rand.Reader, key); err != nil {
|
|
||||||
return nil, fmt.Errorf("error generating key: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return key, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func SaveKey(key []byte, filename string) error {
|
|
||||||
file, err := os.Create(filename)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error creating key file: %v", err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
file.Chmod(0600)
|
|
||||||
|
|
||||||
if err = gob.NewEncoder(file).Encode(key); err != nil {
|
|
||||||
return fmt.Errorf("error ecoding key: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func LoadKey(filename string) ([]byte, error) {
|
|
||||||
file, err := os.Open(filename)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error opening key file: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
key := make([]byte, 32)
|
|
||||||
if err = gob.NewDecoder(file).Decode(&key); err != nil {
|
|
||||||
return nil, fmt.Errorf("error decoding key: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return key, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCookieStore(key []byte) *CookieStore {
|
|
||||||
store := sessions.NewCookieStore(key)
|
|
||||||
store.Options.Secure = true
|
|
||||||
store.Options.HttpOnly = true
|
|
||||||
return &CookieStore{*store}
|
|
||||||
}
|
|
1025
cmd/frontend/articles.go
Normal file
1025
cmd/frontend/articles.go
Normal file
File diff suppressed because it is too large
Load Diff
107
cmd/frontend/docx.go
Normal file
107
cmd/frontend/docx.go
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
package frontend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gabriel-vasile/mimetype"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UploadDocx(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := ManageSession(w, r, c, s)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
file, fileHeader, err := r.FormFile("docx-upload")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
var buf bytes.Buffer
|
||||||
|
if _, err = io.Copy(&buf, file); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mime := mimetype.Detect(buf.Bytes())
|
||||||
|
if !mime.Is("application/vnd.openxmlformats-officedocument.wordprocessingml.document") {
|
||||||
|
http.Error(w, "Die Datei ist kein DOCX Worddokument.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
docxFilename := fmt.Sprint(uuid.New(), ".docx")
|
||||||
|
absDocxFilepath, err := filepath.Abs("/tmp/" + docxFilename)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = os.WriteFile(absDocxFilepath, buf.Bytes(), 0644); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer os.Remove(absDocxFilepath)
|
||||||
|
|
||||||
|
mdString, err := b.ConvertToMarkdown(c, absDocxFilepath)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uuidName := uuid.New()
|
||||||
|
mdFilename := fmt.Sprint(uuidName, ".md")
|
||||||
|
absMdFilepath, err := filepath.Abs(c.ArticleDir + "/" + mdFilename)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = os.WriteFile(absMdFilepath, mdString, 0644); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
article := &b.Article{
|
||||||
|
Created: time.Now(),
|
||||||
|
UUID: uuidName,
|
||||||
|
CreatorID: session.User.ID,
|
||||||
|
Rejected: true,
|
||||||
|
}
|
||||||
|
article.Title = fmt.Sprint(fileHeader.Filename, "-", article.UUID)
|
||||||
|
|
||||||
|
id, err := db.AddArticle(article)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = db.WriteArticleAuthors(id, []int64{session.User.ID}); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
99
cmd/frontend/homepage.go
Normal file
99
cmd/frontend/homepage.go
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package frontend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HomePage(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
numRows, err := db.CountEntries("users")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data := new(struct {
|
||||||
|
*UserHTMLData
|
||||||
|
Version string
|
||||||
|
})
|
||||||
|
data.UserHTMLData = &UserHTMLData{User: new(b.User)}
|
||||||
|
data.Version = c.Version
|
||||||
|
|
||||||
|
files := make([]string, 2)
|
||||||
|
files[0] = c.WebDir + "/templates/index.html"
|
||||||
|
if numRows == 0 {
|
||||||
|
data.Role = b.NonExistent
|
||||||
|
data.Title = "Erster Benutzer (Administrator)"
|
||||||
|
data.ButtonText = "Anlegen"
|
||||||
|
data.URL = "/user/add-first"
|
||||||
|
|
||||||
|
files[1] = c.WebDir + "/templates/edit-user.html"
|
||||||
|
tmpl, err := template.ParseFiles(files...)
|
||||||
|
if err = template.Must(tmpl, err).Execute(w, data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cookie, err := r.Cookie("cpolis_session")
|
||||||
|
if err != nil {
|
||||||
|
files[1] = c.WebDir + "/templates/login.html"
|
||||||
|
tmpl, err := template.ParseFiles(files...)
|
||||||
|
if err = template.Must(tmpl, err).Execute(w, data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session, ok := s[cookie.Value]
|
||||||
|
if !ok {
|
||||||
|
cookie.Expires = time.Now()
|
||||||
|
http.SetCookie(w, cookie)
|
||||||
|
|
||||||
|
files[1] = c.WebDir + "/templates/login.html"
|
||||||
|
tmpl, err := template.ParseFiles(files...)
|
||||||
|
if err = template.Must(tmpl, err).Execute(w, data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data.Role = session.User.Role
|
||||||
|
files[1] = c.WebDir + "/templates/hub.html"
|
||||||
|
tmpl, err := template.ParseFiles(files...)
|
||||||
|
if err = template.Must(tmpl, err).Execute(w, data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ShowHub(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := ManageSession(w, r, c, s)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := new(struct{ Role int })
|
||||||
|
data.Role = session.User.Role
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||||
|
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
80
cmd/frontend/images.go
Normal file
80
cmd/frontend/images.go
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
package frontend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UploadEasyMDEImage(c *b.Config, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if _, err := ManageSession(w, r, c, s); err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
file, _, err := r.FormFile("article-image")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
filename, err := b.SaveImage(file, c.MaxImgHeight, c.MaxImgWidth, c.PicsDir+"/")
|
||||||
|
if err != nil {
|
||||||
|
if err == b.ErrUnsupportedFormat {
|
||||||
|
http.Error(w, "Das Dateiformat wird nicht unterstützt.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
url := c.Domain + "/image/serve/" + filename
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func UploadImage(c *b.Config, s map[string]*Session, fileKey, htmlFile, htmlTemplate string) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if _, err := ManageSession(w, r, c, s); err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
file, _, err := r.FormFile(fileKey)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
filename, err := b.SaveImage(file, c.MaxBannerHeight, c.MaxBannerWidth, c.PicsDir+"/")
|
||||||
|
if err != nil {
|
||||||
|
if err == b.ErrUnsupportedFormat {
|
||||||
|
http.Error(w, "Das Dateiformat wird nicht unterstützt.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := new(struct{ Image string })
|
||||||
|
data.Image = filename
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/" + htmlFile)
|
||||||
|
if err = template.Must(tmpl, err).ExecuteTemplate(w, htmlTemplate, data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
102
cmd/frontend/issues.go
Normal file
102
cmd/frontend/issues.go
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
package frontend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PublishLatestIssue(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := ManageSession(w, r, c, s)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
article := &b.Article{
|
||||||
|
Title: r.PostFormValue("issue-title"),
|
||||||
|
BannerLink: r.PostFormValue("issue-banner-url"),
|
||||||
|
Published: true,
|
||||||
|
Rejected: false,
|
||||||
|
Created: time.Now(),
|
||||||
|
AutoGenerated: true,
|
||||||
|
UUID: uuid.New(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(article.Title) == 0 {
|
||||||
|
http.Error(w, "Bitte den Titel eingeben.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
article.ID, err = db.AddArticle(article)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
authorIDs := make([]int64, 1)
|
||||||
|
authorIDs[0] = session.User.ID
|
||||||
|
|
||||||
|
if err = db.WriteArticleAuthors(article.ID, authorIDs); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
content := []byte(r.PostFormValue("issue-content"))
|
||||||
|
if len(content) == 0 {
|
||||||
|
http.Error(w, "Bitte eine Beschreibung eingeben.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
articleAbsName := fmt.Sprint(c.ArticleDir, "/", article.UUID, ".md")
|
||||||
|
if err = os.WriteFile(articleAbsName, content, 0644); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = db.AddArticleToCurrentIssue(article.ID); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.PublishLatestIssue(); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
feed, err := b.GenerateAtomFeed(c, db)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = b.SaveAtomFeed(c.AtomFile, feed); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := new(struct{ Role int })
|
||||||
|
data.Role = session.User.Role
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
65
cmd/frontend/pdf.go
Normal file
65
cmd/frontend/pdf.go
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package frontend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UploadPDF(c *b.Config, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if _, err := ManageSession(w, r, c, s); err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
file, header, err := r.FormFile("pdf-upload")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
buffer := make([]byte, 512) // Should be enough for mime type
|
||||||
|
if _, err := file.Read(buffer); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := file.Seek(0, 0); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if http.DetectContentType(buffer) != "application/pdf" {
|
||||||
|
http.Error(w, "Die Datei ist kein PDF.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
oldFilename := header.Filename
|
||||||
|
oldFilename = strings.Join(strings.Split(oldFilename, ".")[:len(oldFilename)-1], ".")
|
||||||
|
filename := fmt.Sprint(oldFilename, ".", uuid.New(), ".pdf")
|
||||||
|
absFilepath, err := filepath.Abs(c.PDFDir + "/" + filename)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = b.WriteFile(absFilepath, file); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
167
cmd/frontend/sessions.go
Normal file
167
cmd/frontend/sessions.go
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
package frontend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Session struct {
|
||||||
|
ctx context.Context
|
||||||
|
cancel context.CancelFunc
|
||||||
|
cookie *http.Cookie
|
||||||
|
User *b.User
|
||||||
|
}
|
||||||
|
|
||||||
|
func newSession(w http.ResponseWriter, c *b.Config, sessionExpiryChan chan<- string, user *b.User) *Session {
|
||||||
|
sessionID := uuid.New().String()
|
||||||
|
expires := time.Now().Add(time.Hour * time.Duration(c.CookieExpiryHours))
|
||||||
|
ctx, cancel := context.WithDeadline(context.Background(), expires)
|
||||||
|
|
||||||
|
session := &Session{
|
||||||
|
ctx: ctx,
|
||||||
|
cancel: cancel,
|
||||||
|
cookie: &http.Cookie{
|
||||||
|
Name: "cpolis_session",
|
||||||
|
Value: sessionID,
|
||||||
|
Expires: expires,
|
||||||
|
Path: "/",
|
||||||
|
HttpOnly: true,
|
||||||
|
Secure: true,
|
||||||
|
SameSite: http.SameSiteStrictMode,
|
||||||
|
},
|
||||||
|
User: user,
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
<-session.ctx.Done()
|
||||||
|
sessionExpiryChan <- session.cookie.Value
|
||||||
|
session.cookie.Expires = time.Now()
|
||||||
|
http.SetCookie(w, session.cookie)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return session
|
||||||
|
}
|
||||||
|
|
||||||
|
func StartSessions() (map[string]*Session, chan string) {
|
||||||
|
sessions := make(map[string]*Session)
|
||||||
|
sessionExpiryChan := make(chan string)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for sessionID := range sessionExpiryChan {
|
||||||
|
delete(sessions, sessionID)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return sessions, sessionExpiryChan
|
||||||
|
}
|
||||||
|
|
||||||
|
// ManageSession is used for verifying that the user is logged in and returns
|
||||||
|
// their session and an error. It also handles cases where the user is not
|
||||||
|
// logged in.
|
||||||
|
func ManageSession(w http.ResponseWriter, r *http.Request, c *b.Config, s map[string]*Session) (*Session, error) {
|
||||||
|
tmpl, tmplErr := template.ParseFiles(c.WebDir+"/templates/index.html", c.WebDir+"/templates/login.html")
|
||||||
|
|
||||||
|
cookie, err := r.Cookie("cpolis_session")
|
||||||
|
if err != nil {
|
||||||
|
if err = template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", nil); err != nil {
|
||||||
|
return nil, fmt.Errorf("error executing template: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("no cookie set")
|
||||||
|
}
|
||||||
|
|
||||||
|
session, ok := s[cookie.Value]
|
||||||
|
if !ok {
|
||||||
|
cookie.Expires = time.Now()
|
||||||
|
http.SetCookie(w, cookie)
|
||||||
|
|
||||||
|
if err = template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", nil); err != nil {
|
||||||
|
return nil, fmt.Errorf("error executing template: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("session does not exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
session.cookie.Expires = time.Now().Add(time.Hour * time.Duration(c.CookieExpiryHours))
|
||||||
|
http.SetCookie(w, session.cookie)
|
||||||
|
|
||||||
|
return session, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Login(c *b.Config, db *b.DB, s map[string]*Session, sessionExpiryChan chan string) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
userName := r.PostFormValue("username")
|
||||||
|
password := r.PostFormValue("password")
|
||||||
|
|
||||||
|
id := db.GetID(userName)
|
||||||
|
if id == 0 {
|
||||||
|
http.Error(w, fmt.Sprintf("no such user: %v", userName), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.CheckPassword(id, password); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := db.GetUser(c, id)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session := newSession(w, c, sessionExpiryChan, user)
|
||||||
|
s[session.cookie.Value] = session
|
||||||
|
http.SetCookie(w, session.cookie)
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||||
|
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Logout(c *b.Config, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
tmpl, tmplErr := template.ParseFiles(c.WebDir + "/templates/login.html")
|
||||||
|
|
||||||
|
cookie, err := r.Cookie("cpolis_session")
|
||||||
|
if err != nil {
|
||||||
|
if err = template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", nil); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cookie.Expires = time.Now()
|
||||||
|
http.SetCookie(w, cookie)
|
||||||
|
|
||||||
|
session, ok := s[cookie.Value]
|
||||||
|
if !ok {
|
||||||
|
if err = template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", nil); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.cancel()
|
||||||
|
|
||||||
|
if err = template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", nil); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
cmd/frontend/tags.go
Normal file
53
cmd/frontend/tags.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package frontend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateTag(c *b.Config, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if _, err := ManageSession(w, r, c, s); err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-tag.html")
|
||||||
|
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddTag(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := ManageSession(w, r, c, s)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tag := r.PostFormValue("tag")
|
||||||
|
if len(tag) == 0 {
|
||||||
|
http.Error(w, "Bitte einen Tag eingeben.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
db.AddTag(tag)
|
||||||
|
|
||||||
|
data := new(struct{ Role int })
|
||||||
|
data.Role = session.User.Role
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
510
cmd/frontend/users.go
Normal file
510
cmd/frontend/users.go
Normal file
@ -0,0 +1,510 @@
|
|||||||
|
package frontend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserHTMLData struct {
|
||||||
|
*b.User
|
||||||
|
Title string
|
||||||
|
ButtonText string
|
||||||
|
URL string
|
||||||
|
Image string
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkUserStrings(user *b.User) (string, int, bool) {
|
||||||
|
userLen := 63 // max value for utf-8 at 255 bytes
|
||||||
|
nameLen := 56 // max value when aes encrypting utf-8 at up to 255 bytes
|
||||||
|
|
||||||
|
if len(user.UserName) > userLen {
|
||||||
|
return "Benutzername", userLen, false
|
||||||
|
} else if len(user.FirstName) > nameLen {
|
||||||
|
return "Vorname", nameLen, false
|
||||||
|
} else if len(user.LastName) > nameLen {
|
||||||
|
return "Nachname", nameLen, false
|
||||||
|
} else {
|
||||||
|
return "", 0, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sortUsersByName(users []*b.User) {
|
||||||
|
sort.SliceStable(users, func(i, j int) bool {
|
||||||
|
if users[i].LastName == users[j].LastName {
|
||||||
|
return users[i].FirstName < users[j].FirstName
|
||||||
|
}
|
||||||
|
return users[i].LastName < users[j].LastName
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateUser(c *b.Config, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if _, err := ManageSession(w, r, c, s); err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := &UserHTMLData{
|
||||||
|
User: &b.User{Role: b.Author},
|
||||||
|
Title: "Neuer Benutzer",
|
||||||
|
ButtonText: "Anlegen",
|
||||||
|
URL: "/user/add",
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-user.html")
|
||||||
|
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddUser(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := ManageSession(w, r, c, s)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user := &b.User{
|
||||||
|
UserName: r.PostFormValue("username"),
|
||||||
|
FirstName: r.PostFormValue("first-name"),
|
||||||
|
LastName: r.PostFormValue("last-name"),
|
||||||
|
Email: r.PostFormValue("email"),
|
||||||
|
ProfilePicLink: r.PostFormValue("profile-pic-url"),
|
||||||
|
}
|
||||||
|
pass := r.PostFormValue("password")
|
||||||
|
pass2 := r.PostFormValue("password2")
|
||||||
|
email2 := r.PostFormValue("email2")
|
||||||
|
|
||||||
|
if len(user.UserName) == 0 || len(user.FirstName) == 0 || len(user.LastName) == 0 || len(user.Email) == 0 || len(email2) == 0 || len(pass) == 0 || len(pass2) == 0 {
|
||||||
|
http.Error(w, "Bitte alle Felder ausfüllen.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userString, stringLen, ok := checkUserStrings(user)
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, fmt.Sprint(userString, " ist zu lang. Maximal ", stringLen, " Zeichen erlaubt."), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if id := db.GetID(user.UserName); id != 0 {
|
||||||
|
http.Error(w, user.UserName+" ist bereits vergeben. Bitte anderen Benutzernamen wählen.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.Email != email2 {
|
||||||
|
http.Error(w, "Die Emailadressen stimmen nicht überein.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if pass != pass2 {
|
||||||
|
http.Error(w, "Die Passwörter stimmen nicht überein.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
roleString := r.PostFormValue("role")
|
||||||
|
if len(roleString) == 0 {
|
||||||
|
http.Error(w, "Bitte eine Aufgabe vergeben.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Role, err = strconv.Atoi(roleString)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = db.AddUser(c, user, pass)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := new(struct{ Role int })
|
||||||
|
data.Role = session.User.Role
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func EditSelf(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := ManageSession(w, r, c, s)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := db.GetUser(c, session.User.ID)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := &UserHTMLData{
|
||||||
|
User: user,
|
||||||
|
Title: "Mein Profil bearbeiten",
|
||||||
|
ButtonText: "Übernehmen",
|
||||||
|
URL: "/user/update/self",
|
||||||
|
Image: user.ProfilePicLink,
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-user.html")
|
||||||
|
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateSelf(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := ManageSession(w, r, c, s)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user := &b.User{
|
||||||
|
ID: session.User.ID,
|
||||||
|
UserName: r.PostFormValue("username"),
|
||||||
|
FirstName: r.PostFormValue("first-name"),
|
||||||
|
LastName: r.PostFormValue("last-name"),
|
||||||
|
Email: r.PostFormValue("email"),
|
||||||
|
ProfilePicLink: r.PostFormValue("profile-pic-url"),
|
||||||
|
}
|
||||||
|
|
||||||
|
oldPass := r.PostFormValue("old-password")
|
||||||
|
newPass := r.PostFormValue("password")
|
||||||
|
newPass2 := r.PostFormValue("password2")
|
||||||
|
email2 := r.PostFormValue("email2")
|
||||||
|
|
||||||
|
if len(user.UserName) == 0 {
|
||||||
|
http.Error(w, "Bitte den Benutzernamen ausfüllen.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(user.FirstName) == 0 || len(user.LastName) == 0 {
|
||||||
|
http.Error(w, "Bitte den vollständigen Namen ausfüllen.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(user.Email) == 0 || len(email2) == 0 {
|
||||||
|
http.Error(w, "Bitte die Emailadresse ausfüllen.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if user.Email != email2 {
|
||||||
|
http.Error(w, "Die Emailadressen stimmen nicht überein", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if newPass != newPass2 {
|
||||||
|
http.Error(w, "Die Passwörter stimmen nicht überein", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userString, stringLen, ok := checkUserStrings(user)
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, fmt.Sprint(userString, " ist zu lang. Maximal ", stringLen, " Zeichen erlaubt."), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if id := db.GetID(user.UserName); id != 0 && id != user.ID {
|
||||||
|
http.Error(w, user.UserName+" ist bereits vergeben. Bitte anderen Benutzernamen wählen.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = db.UpdateOwnUserAttributes(c, user.ID, user.UserName, user.FirstName, user.LastName, user.Email, user.ProfilePicLink, oldPass, newPass); err != nil {
|
||||||
|
log.Println("error: user:", user.ID, err)
|
||||||
|
http.Error(w, "Benutzerdaten konnten nicht aktualisiert werden.", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := new(struct{ Role int })
|
||||||
|
data.Role = session.User.Role
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddFirstUser(c *b.Config, db *b.DB, s map[string]*Session, sessionExpiryChan chan string) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var err error
|
||||||
|
user := &b.User{
|
||||||
|
UserName: r.PostFormValue("username"),
|
||||||
|
FirstName: r.PostFormValue("first-name"),
|
||||||
|
LastName: r.PostFormValue("last-name"),
|
||||||
|
Email: r.PostFormValue("email"),
|
||||||
|
ProfilePicLink: r.PostFormValue("profile-pic-url"),
|
||||||
|
Role: b.Admin,
|
||||||
|
}
|
||||||
|
pass := r.PostFormValue("password")
|
||||||
|
pass2 := r.PostFormValue("password2")
|
||||||
|
email2 := r.PostFormValue("email2")
|
||||||
|
|
||||||
|
if len(user.UserName) == 0 || len(user.FirstName) == 0 || len(user.LastName) == 0 || len(user.Email) == 0 || len(email2) == 0 || len(pass) == 0 || len(pass2) == 0 {
|
||||||
|
http.Error(w, "Bitte alle Felder ausfüllen.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userString, stringLen, ok := checkUserStrings(user)
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, fmt.Sprint(userString, " ist zu lang. Maximal ", stringLen, " Zeichen erlaubt."), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.Email != email2 {
|
||||||
|
http.Error(w, "Die Emailadressen stimmen nicht überein.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if pass != pass2 {
|
||||||
|
http.Error(w, "Die Passwörter stimmen nicht überein.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user.ID, err = db.AddFirstUser(c, user, pass)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if user.ID == -1 {
|
||||||
|
http.Error(w, "Bitte ein Benutzerkonto von einem Administrator anlegen lassen.", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := db.AddIssue(); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session := newSession(w, c, sessionExpiryChan, user)
|
||||||
|
s[session.cookie.Value] = session
|
||||||
|
http.SetCookie(w, session.cookie)
|
||||||
|
|
||||||
|
data := new(struct{ Role int })
|
||||||
|
data.Role = user.Role
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||||
|
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ShowAllUsers(c *b.Config, db *b.DB, s map[string]*Session, action string) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := ManageSession(w, r, c, s)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := new(struct {
|
||||||
|
Users map[int64]*b.User
|
||||||
|
Action string
|
||||||
|
})
|
||||||
|
|
||||||
|
data.Action = action
|
||||||
|
data.Users, err = db.GetAllUsersMap(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
delete(data.Users, session.User.ID)
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/show-all-users.html")
|
||||||
|
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func EditUser(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if _, err := ManageSession(w, r, c, s); err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := db.GetUser(c, id)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := &UserHTMLData{
|
||||||
|
User: user,
|
||||||
|
Title: "Profil von " + user.FirstName + " " + user.LastName + " bearbeiten",
|
||||||
|
ButtonText: "Übernehmen",
|
||||||
|
URL: fmt.Sprint("/user/update/", user.ID),
|
||||||
|
Image: user.ProfilePicLink,
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/edit-user.html")
|
||||||
|
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateUser(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := ManageSession(w, r, c, s)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user := new(b.User)
|
||||||
|
user.ID, err = strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Role, err = strconv.Atoi(r.PostFormValue("role"))
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user.UserName = r.PostFormValue("username")
|
||||||
|
if len(user.UserName) == 0 {
|
||||||
|
http.Error(w, "Bitte den Benutzernamen ausfüllen.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user.FirstName = r.PostFormValue("first-name")
|
||||||
|
user.LastName = r.PostFormValue("last-name")
|
||||||
|
if len(user.FirstName) == 0 || len(user.LastName) == 0 {
|
||||||
|
http.Error(w, "Bitte den vollständigen Namen ausfüllen.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Email = r.PostFormValue("email")
|
||||||
|
email2 := r.PostFormValue("email2")
|
||||||
|
if len(user.Email) == 0 || len(email2) == 0 {
|
||||||
|
http.Error(w, "Bitte die Emailadresse ausfüllen.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if user.Email != email2 {
|
||||||
|
http.Error(w, "Die Emailadressen stimmen nicht überein.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user.ProfilePicLink = r.PostFormValue("profile-pic-url")
|
||||||
|
|
||||||
|
newPass := r.PostFormValue("password")
|
||||||
|
newPass2 := r.PostFormValue("password2")
|
||||||
|
if newPass != newPass2 {
|
||||||
|
http.Error(w, "Die Passwörter stimmen nicht überein.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userString, stringLen, ok := checkUserStrings(user)
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, fmt.Sprint(userString, " ist zu lang. Maximal ", stringLen, " Zeichen erlaubt."), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if id := db.GetID(user.UserName); id != 0 && id != user.ID {
|
||||||
|
http.Error(w, user.UserName+" ist bereits vergeben. Bitte anderen Benutzernamen wählen.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = db.UpdateUserAttributes(c, user.ID, user.UserName, user.FirstName, user.LastName, user.Email, user.ProfilePicLink, newPass, user.Role); err != nil {
|
||||||
|
log.Println("error: user:", user.ID, err)
|
||||||
|
http.Error(w, "Benutzerdaten konnten nicht aktualisiert werden.", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := new(struct{ Role int })
|
||||||
|
data.Role = session.User.Role
|
||||||
|
|
||||||
|
tmpl := template.Must(template.ParseFiles(c.WebDir + "/templates/hub.html"))
|
||||||
|
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteUser(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := ManageSession(w, r, c, s)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = db.DeleteUser(id); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := new(struct{ Role int })
|
||||||
|
data.Role = session.User.Role
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
113
cmd/main.go
113
cmd/main.go
@ -1,77 +1,90 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"streifling.com/jason/cpolis/cmd/control"
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
"streifling.com/jason/cpolis/cmd/model"
|
c "streifling.com/jason/cpolis/cmd/calls"
|
||||||
"streifling.com/jason/cpolis/cmd/view"
|
f "streifling.com/jason/cpolis/cmd/frontend"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
gob.Register(model.User{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logFile, err := os.OpenFile("tmp/cpolis.log",
|
config, err := b.HandleConfig()
|
||||||
os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logFile, err := os.OpenFile(config.LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
defer logFile.Close()
|
defer logFile.Close()
|
||||||
// log.SetOutput(logFile)
|
log.SetOutput(logFile)
|
||||||
|
|
||||||
db, err := model.OpenDB("cpolis")
|
db, err := b.OpenDB(config.DBName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
key, err := control.LoadKey("tmp/key.gob")
|
sessions, sessionExpiryChan := f.StartSessions()
|
||||||
if err != nil {
|
defer close(sessionExpiryChan)
|
||||||
key, err = control.NewKey()
|
|
||||||
if err != nil {
|
// go b.CleanUpImages(config)
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
control.SaveKey(key, "tmp/key.gob")
|
|
||||||
}
|
|
||||||
store := control.NewCookieStore(key)
|
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle("/web/static/", http.StripPrefix("/web/static/",
|
mux.Handle("/web/static/", http.StripPrefix("/web/static/",
|
||||||
http.FileServer(http.Dir("web/static/"))))
|
http.FileServer(http.Dir(config.WebDir+"/static/"))))
|
||||||
mux.HandleFunc("/", view.HomePage(db, store))
|
mux.HandleFunc("/", f.HomePage(config, db, sessions))
|
||||||
|
|
||||||
mux.HandleFunc("GET /create-tag/", view.CreateTag)
|
mux.HandleFunc("GET /article/allow-edit/{id}", f.AllowEditArticle(config, db, sessions))
|
||||||
mux.HandleFunc("GET /create-user/", view.CreateUser)
|
mux.HandleFunc("GET /article/all-published/review-edit", f.ShowPublishedArticles(config, db, sessions, "review-edit"))
|
||||||
mux.HandleFunc("GET /edit-user/", view.EditUser(db, store))
|
mux.HandleFunc("GET /article/all-published/delete", f.ShowPublishedArticles(config, db, sessions, "review-delete"))
|
||||||
mux.HandleFunc("GET /hub/", view.ShowHub(db, store))
|
mux.HandleFunc("GET /article/all-rejected", f.ShowRejectedArticles(config, db, sessions))
|
||||||
mux.HandleFunc("GET /logout/", view.Logout(store))
|
mux.HandleFunc("GET /article/all-unpublished-unrejected-and-published-rejected", f.ShowUnpublishedUnrejectedAndPublishedRejectedArticles(config, db, sessions))
|
||||||
mux.HandleFunc("GET /publish-issue/", view.PublishLatestIssue(db))
|
mux.HandleFunc("GET /article/delete/{id}", f.DeleteArticle(config, db, sessions))
|
||||||
mux.HandleFunc("GET /rejected-articles/", view.ShowRejectedArticles(db, store))
|
mux.HandleFunc("GET /article/edit/{id}", f.EditArticle(config, db, sessions))
|
||||||
mux.HandleFunc("GET /rss/", view.ShowRSS(
|
mux.HandleFunc("GET /article/publish/{id}", f.PublishArticle(config, db, sessions))
|
||||||
db,
|
mux.HandleFunc("GET /article/reject/{id}", f.RejectArticle(config, db, sessions))
|
||||||
"Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt",
|
mux.HandleFunc("GET /article/review-delete/{id}", f.ReviewArticle(config, db, sessions, "delete", "Artikel löschen", "Löschen"))
|
||||||
"https://distrikt-ni-st.de",
|
mux.HandleFunc("GET /article/review-edit/{id}", f.ReviewArticle(config, db, sessions, "allow-edit", "Artikel bearbeiten", "Bearbeiten erlauben"))
|
||||||
"Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität",
|
mux.HandleFunc("GET /article/review-rejected/{id}", f.ReviewRejectedArticle(config, db, sessions))
|
||||||
))
|
mux.HandleFunc("GET /article/review-unpublished/{id}", f.ReviewArticle(config, db, sessions, "publish", "Artikel veröffentlichen", "Veröffentlichen"))
|
||||||
mux.HandleFunc("GET /this-issue/", view.ShowCurrentArticles(db))
|
mux.HandleFunc("GET /article/serve/{id}", c.ServeArticle(config, db))
|
||||||
mux.HandleFunc("GET /unpublished-articles/", view.ShowUnpublishedArticles(db))
|
mux.HandleFunc("GET /article/serve/{id}/clicks", c.ServeClicks(db))
|
||||||
mux.HandleFunc("GET /write-article/", view.WriteArticle(db))
|
mux.HandleFunc("GET /article/write", f.WriteArticle(config, db, sessions))
|
||||||
|
mux.HandleFunc("GET /atom/serve", c.ServeAtomFeed(config))
|
||||||
|
mux.HandleFunc("GET /hub", f.ShowHub(config, db, sessions))
|
||||||
|
mux.HandleFunc("GET /image/serve/{pic}", c.ServeImage(config, sessions))
|
||||||
|
mux.HandleFunc("GET /issue/this", f.ShowCurrentIssue(config, db, sessions))
|
||||||
|
mux.HandleFunc("GET /logout", f.Logout(config, sessions))
|
||||||
|
mux.HandleFunc("GET /pdf/get-list", c.ServePDFList(config))
|
||||||
|
mux.HandleFunc("GET /pdf/serve/{id}", c.ServePDF(config))
|
||||||
|
mux.HandleFunc("GET /tag/create", f.CreateTag(config, sessions))
|
||||||
|
mux.HandleFunc("GET /user/create", f.CreateUser(config, sessions))
|
||||||
|
mux.HandleFunc("GET /user/delete/{id}", f.DeleteUser(config, db, sessions))
|
||||||
|
mux.HandleFunc("GET /user/edit/{id}", f.EditUser(config, db, sessions))
|
||||||
|
mux.HandleFunc("GET /user/edit/self", f.EditSelf(config, db, sessions))
|
||||||
|
mux.HandleFunc("GET /user/show-all/delete", f.ShowAllUsers(config, db, sessions, "delete"))
|
||||||
|
mux.HandleFunc("GET /user/show-all/edit", f.ShowAllUsers(config, db, sessions, "edit"))
|
||||||
|
|
||||||
mux.HandleFunc("POST /add-tag/", view.AddTag(db, store))
|
mux.HandleFunc("POST /article/resubmit/{id}", f.ResubmitArticle(config, db, sessions))
|
||||||
mux.HandleFunc("POST /add-user/", view.AddUser(db, store))
|
mux.HandleFunc("POST /article/submit", f.SubmitArticle(config, db, sessions))
|
||||||
mux.HandleFunc("POST /login/", view.Login(db, store))
|
mux.HandleFunc("POST /article/upload-banner", f.UploadImage(config, sessions, "article-banner", "editor.html", "article-banner-template"))
|
||||||
mux.HandleFunc("POST /publish-article/", view.PublishArticle(db, store))
|
mux.HandleFunc("POST /article/upload-image", f.UploadEasyMDEImage(config, sessions))
|
||||||
mux.HandleFunc("POST /reject-article/", view.RejectArticle(db, store))
|
mux.HandleFunc("POST /docx/upload", f.UploadDocx(config, db, sessions))
|
||||||
mux.HandleFunc("POST /resubmit-article/", view.ResubmitArticle(db, store))
|
mux.HandleFunc("POST /issue/publish", f.PublishLatestIssue(config, db, sessions))
|
||||||
mux.HandleFunc("POST /review-rejected-article/", view.ReviewRejectedArticle(db, store))
|
mux.HandleFunc("POST /issue/upload-banner", f.UploadImage(config, sessions, "issue-banner", "current-issue.html", "issue-banner-template"))
|
||||||
mux.HandleFunc("POST /review-unpublished-article/", view.ReviewUnpublishedArticle(db, store))
|
mux.HandleFunc("POST /login", f.Login(config, db, sessions, sessionExpiryChan))
|
||||||
mux.HandleFunc("POST /submit-article/", view.SubmitArticle(db, store))
|
mux.HandleFunc("POST /pdf/upload", f.UploadPDF(config, sessions))
|
||||||
mux.HandleFunc("POST /update-user/", view.UpdateUser(db, store))
|
mux.HandleFunc("POST /tag/add", f.AddTag(config, db, sessions))
|
||||||
|
mux.HandleFunc("POST /user/add", f.AddUser(config, db, sessions))
|
||||||
|
mux.HandleFunc("POST /user/add-first", f.AddFirstUser(config, db, sessions, sessionExpiryChan))
|
||||||
|
mux.HandleFunc("POST /user/update/{id}", f.UpdateUser(config, db, sessions))
|
||||||
|
mux.HandleFunc("POST /user/update/self", f.UpdateSelf(config, db, sessions))
|
||||||
|
mux.HandleFunc("POST /user/upload-profile-pic", f.UploadImage(config, sessions, "upload-profile-pic", "edit-user.html", "profile-pic-template"))
|
||||||
|
|
||||||
log.Fatalln(http.ListenAndServe(":8080", mux))
|
log.Fatalln(http.ListenAndServe(config.Port, mux))
|
||||||
}
|
}
|
||||||
|
@ -1,200 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
Admin = iota
|
|
||||||
Publisher
|
|
||||||
Editor
|
|
||||||
Author
|
|
||||||
)
|
|
||||||
|
|
||||||
type User struct {
|
|
||||||
UserName string
|
|
||||||
FirstName string
|
|
||||||
LastName string
|
|
||||||
ID int64
|
|
||||||
Role int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *DB) AddUser(u *User, pass string) (int64, error) {
|
|
||||||
hashedPass, err := bcrypt.GenerateFromPassword([]byte(pass), bcrypt.DefaultCost)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error creating password hash: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
query := `
|
|
||||||
INSERT INTO users (username, password, first_name, last_name, role)
|
|
||||||
VALUES (?, ?, ?, ?, ?)
|
|
||||||
`
|
|
||||||
result, err := db.Exec(query, u.UserName, string(hashedPass), u.FirstName, u.LastName, u.Role)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error inserting new user %v into DB: %v", u.UserName, err)
|
|
||||||
}
|
|
||||||
id, err := result.LastInsertId()
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error inserting user into DB: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return id, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *DB) GetID(userName string) (int64, bool) {
|
|
||||||
var id int64
|
|
||||||
|
|
||||||
query := `
|
|
||||||
SELECT id
|
|
||||||
FROM users
|
|
||||||
WHERE username = ?
|
|
||||||
`
|
|
||||||
row := db.QueryRow(query, userName)
|
|
||||||
if err := row.Scan(&id); err != nil {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
|
|
||||||
return id, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *DB) CheckPassword(id int64, pass string) error {
|
|
||||||
var queriedPass string
|
|
||||||
|
|
||||||
query := `
|
|
||||||
SELECT password
|
|
||||||
FROM users
|
|
||||||
WHERE id = ?
|
|
||||||
`
|
|
||||||
row := db.QueryRow(query, id)
|
|
||||||
if err := row.Scan(&queriedPass); err != nil {
|
|
||||||
return fmt.Errorf("error reading password from DB: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := bcrypt.CompareHashAndPassword([]byte(queriedPass), []byte(pass)); err != nil {
|
|
||||||
return fmt.Errorf("incorrect password: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tx *Tx) ChangePassword(id int64, oldPass, newPass string) error {
|
|
||||||
var queriedPass string
|
|
||||||
getQuery := `
|
|
||||||
SELECT password
|
|
||||||
FROM users
|
|
||||||
WHERE id = ?
|
|
||||||
`
|
|
||||||
row := tx.QueryRow(getQuery, id)
|
|
||||||
if err := row.Scan(&queriedPass); err != nil {
|
|
||||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
|
||||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("error reading password from DB: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := bcrypt.CompareHashAndPassword([]byte(queriedPass), []byte(oldPass)); err != nil {
|
|
||||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
|
||||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("incorrect password: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
newHashedPass, err := bcrypt.GenerateFromPassword([]byte(newPass), bcrypt.DefaultCost)
|
|
||||||
if err != nil {
|
|
||||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
|
||||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("error creating password hash: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
setQuery := `
|
|
||||||
UPDATE users
|
|
||||||
SET password = ?
|
|
||||||
WHERE id = ?
|
|
||||||
`
|
|
||||||
if _, err = tx.Exec(setQuery, string(newHashedPass), id); err != nil {
|
|
||||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
|
||||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("error updating password in DB: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: No need for ID field in general
|
|
||||||
func (db *DB) GetUser(id int64) (*User, error) {
|
|
||||||
user := new(User)
|
|
||||||
query := `
|
|
||||||
SELECT id, username, first_name, last_name, role
|
|
||||||
FROM users
|
|
||||||
WHERE id = ?
|
|
||||||
`
|
|
||||||
|
|
||||||
row := db.QueryRow(query, id)
|
|
||||||
if err := row.Scan(&user.ID, &user.UserName, &user.FirstName,
|
|
||||||
&user.LastName, &user.Role); err != nil {
|
|
||||||
return nil, fmt.Errorf("error reading user information: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return user, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *DB) UpdateUserAttributes(id int64, user, first, last, oldPass, newPass, newPass2 string) error {
|
|
||||||
passwordEmpty := true
|
|
||||||
if len(newPass) > 0 || len(newPass2) > 0 {
|
|
||||||
if newPass != newPass2 {
|
|
||||||
return fmt.Errorf("error: passwords do not match")
|
|
||||||
}
|
|
||||||
passwordEmpty = false
|
|
||||||
}
|
|
||||||
|
|
||||||
tx := new(Tx)
|
|
||||||
var err error
|
|
||||||
|
|
||||||
for i := 0; i < TxMaxRetries; i++ {
|
|
||||||
err := func() error {
|
|
||||||
tx.Tx, err = db.Begin()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error starting transaction: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !passwordEmpty {
|
|
||||||
if err = tx.ChangePassword(id, oldPass, newPass); err != nil {
|
|
||||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
|
||||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("error changing password: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = tx.UpdateAttributes(
|
|
||||||
&Attribute{Table: "users", ID: id, AttName: "username", Value: user},
|
|
||||||
&Attribute{Table: "users", ID: id, AttName: "first_name", Value: first},
|
|
||||||
&Attribute{Table: "users", ID: id, AttName: "last_name", Value: last},
|
|
||||||
); err != nil {
|
|
||||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
|
||||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("error updating attributes in DB: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = tx.Commit(); err != nil {
|
|
||||||
return fmt.Errorf("error committing transaction: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}()
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println(err)
|
|
||||||
wait(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
|
||||||
}
|
|
@ -1,352 +0,0 @@
|
|||||||
package view
|
|
||||||
|
|
||||||
import (
|
|
||||||
"html/template"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"streifling.com/jason/cpolis/cmd/control"
|
|
||||||
"streifling.com/jason/cpolis/cmd/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ShowHub(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
|
||||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"].(int))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WriteArticle(db *model.DB) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
tags, err := db.GetTagList()
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/editor.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", tags)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func SubmitArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
|
||||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
article := &model.Article{
|
|
||||||
Title: r.PostFormValue("article-title"),
|
|
||||||
Description: r.PostFormValue("article-description"),
|
|
||||||
Content: r.PostFormValue("article-content"),
|
|
||||||
Published: false,
|
|
||||||
Rejected: false,
|
|
||||||
AuthorID: session.Values["id"].(int64),
|
|
||||||
}
|
|
||||||
|
|
||||||
article.ID, err = db.AddArticle(article)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
r.ParseForm()
|
|
||||||
tags := make([]int64, 0)
|
|
||||||
for _, tag := range r.Form["tags"] {
|
|
||||||
tagID, err := strconv.ParseInt(tag, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tags = append(tags, tagID)
|
|
||||||
}
|
|
||||||
if err = db.WriteArticleTags(article.ID, tags); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ResubmitArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
id, err := strconv.ParseInt(r.PostFormValue("article-id"), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
title := r.PostFormValue("article-title")
|
|
||||||
description := r.PostFormValue("article-description")
|
|
||||||
content := r.PostFormValue("article-content")
|
|
||||||
|
|
||||||
if err := db.UpdateAttributes(
|
|
||||||
&model.Attribute{Table: "articles", ID: id, AttName: "title", Value: title},
|
|
||||||
&model.Attribute{Table: "articles", ID: id, AttName: "description", Value: description},
|
|
||||||
&model.Attribute{Table: "articles", ID: id, AttName: "content", Value: content},
|
|
||||||
&model.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: false},
|
|
||||||
); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
|
||||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ShowUnpublishedArticles(db *model.DB) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
unpublishedArticles, err := db.GetCertainArticles(false, false)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/unpublished-articles.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", unpublishedArticles)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ShowRejectedArticles(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
type htmlData struct {
|
|
||||||
MyIDs map[int64]bool
|
|
||||||
RejectedArticles []*model.Article
|
|
||||||
}
|
|
||||||
data := new(htmlData)
|
|
||||||
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data.RejectedArticles, err = db.GetCertainArticles(false, true)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data.MyIDs = make(map[int64]bool)
|
|
||||||
for _, article := range data.RejectedArticles {
|
|
||||||
if article.AuthorID == session.Values["id"].(int64) {
|
|
||||||
data.MyIDs[article.ID] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/rejected-articles.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReviewUnpublishedArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
type htmlData struct {
|
|
||||||
Article *model.Article
|
|
||||||
Tags []*model.Tag
|
|
||||||
}
|
|
||||||
data := new(htmlData)
|
|
||||||
|
|
||||||
id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Article, err = db.GetArticle(id)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Tags, err = db.GetArticleTags(id)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/to-be-published.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReviewRejectedArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
type htmlData struct {
|
|
||||||
Selected map[int64]bool
|
|
||||||
Article *model.Article
|
|
||||||
Tags []*model.Tag
|
|
||||||
}
|
|
||||||
data := new(htmlData)
|
|
||||||
|
|
||||||
id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Article, err = db.GetArticle(id)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Tags, err = db.GetTagList()
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
selectedTags, err := db.GetArticleTags(id)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data.Selected = make(map[int64]bool)
|
|
||||||
for _, tag := range selectedTags {
|
|
||||||
data.Selected[tag.ID] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/rework-article.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func PublishArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
|
||||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = db.AddArticleToCurrentIssue(id); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = db.UpdateAttributes(
|
|
||||||
&model.Attribute{Table: "articles", ID: id, AttName: "published", Value: true},
|
|
||||||
&model.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: false},
|
|
||||||
&model.Attribute{Table: "articles", ID: id, AttName: "created", Value: time.Now().Format("2006-01-02 15:04:05")},
|
|
||||||
); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func RejectArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
|
||||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = db.UpdateAttributes(
|
|
||||||
&model.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: true},
|
|
||||||
); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ShowCurrentArticles(db *model.DB) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
articles, err := db.GetCurrentIssueArticles()
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/current-articles.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", articles)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func PublishLatestIssue(db *model.DB) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if err := db.PublishLatestIssue(); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
package view
|
|
||||||
|
|
||||||
import (
|
|
||||||
"html/template"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"streifling.com/jason/cpolis/cmd/control"
|
|
||||||
"streifling.com/jason/cpolis/cmd/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CreateTag(w http.ResponseWriter, r *http.Request) {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/add-tag.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddTag(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
db.AddTag(r.PostFormValue("tag"))
|
|
||||||
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
|
||||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
package view
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"html/template"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.streifling.com/jason/rss"
|
|
||||||
"streifling.com/jason/cpolis/cmd/control"
|
|
||||||
"streifling.com/jason/cpolis/cmd/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ShowRSS(db *model.DB, title, link, desc string) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
channel := &rss.Channel{
|
|
||||||
Title: title,
|
|
||||||
Link: link,
|
|
||||||
Description: desc,
|
|
||||||
Items: make([]*rss.Item, 0),
|
|
||||||
}
|
|
||||||
|
|
||||||
articles, err := db.GetCertainArticles(true, false)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, article := range articles {
|
|
||||||
tags, err := db.GetArticleTags(article.ID)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tagNames := make([]string, 0)
|
|
||||||
for _, tag := range tags {
|
|
||||||
tagNames = append(tagNames, tag.Name)
|
|
||||||
}
|
|
||||||
tagNames = append(tagNames, fmt.Sprint("Orient Express ", article.IssueID))
|
|
||||||
|
|
||||||
user, err := db.GetUser(article.AuthorID)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
articleTitle, err := control.ConvertToPlain(article.Title)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
articleDescription, err := control.ConvertToPlain(article.Description)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
articleContent, err := control.ConvertToHTML(article.Content)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
channel.Items = append(channel.Items, &rss.Item{
|
|
||||||
Title: articleTitle,
|
|
||||||
Author: user.FirstName + user.LastName,
|
|
||||||
PubDate: article.Created.Format(time.RFC1123Z),
|
|
||||||
Description: articleDescription,
|
|
||||||
Content: &rss.Content{Value: articleContent},
|
|
||||||
Categories: tagNames,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
feed := rss.NewFeed()
|
|
||||||
feed.Channels = append(feed.Channels, channel)
|
|
||||||
rss, err := feed.ToXML()
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
files := []string{"web/templates/index.html", "web/templates/feed.rss"}
|
|
||||||
tmpl, err := template.ParseFiles(files...)
|
|
||||||
template.Must(tmpl, err).Execute(w, rss)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,112 +0,0 @@
|
|||||||
package view
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"html/template"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"streifling.com/jason/cpolis/cmd/control"
|
|
||||||
"streifling.com/jason/cpolis/cmd/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func saveSession(w http.ResponseWriter, r *http.Request, s *control.CookieStore, u *model.User) error {
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error getting session: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
session.Values["authenticated"] = true
|
|
||||||
session.Values["id"] = u.ID
|
|
||||||
session.Values["name"] = u.FirstName + u.LastName
|
|
||||||
session.Values["role"] = u.Role
|
|
||||||
if err := session.Save(r, w); err != nil {
|
|
||||||
return fmt.Errorf("error saving session: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func HomePage(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
numRows, err := db.CountEntries("users")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
files := []string{"web/templates/index.html"}
|
|
||||||
if numRows == 0 {
|
|
||||||
files = append(files, "web/templates/add-user.html")
|
|
||||||
tmpl, err := template.ParseFiles(files...)
|
|
||||||
template.Must(tmpl, err).Execute(w, nil)
|
|
||||||
} else {
|
|
||||||
session, _ := s.Get(r, "cookie")
|
|
||||||
if auth, ok := session.Values["authenticated"].(bool); auth && ok {
|
|
||||||
files = append(files, "web/templates/hub.html")
|
|
||||||
tmpl, err := template.ParseFiles(files...)
|
|
||||||
template.Must(tmpl, err).Execute(w, session.Values["role"])
|
|
||||||
} else {
|
|
||||||
files = append(files, "web/templates/login.html")
|
|
||||||
tmpl, err := template.ParseFiles(files...)
|
|
||||||
template.Must(tmpl, err).Execute(w, nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Login(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
userName := r.PostFormValue("username")
|
|
||||||
password := r.PostFormValue("password")
|
|
||||||
|
|
||||||
id, ok := db.GetID(userName)
|
|
||||||
if !ok {
|
|
||||||
http.Error(w, fmt.Sprintf("no such user: %v", userName), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := db.CheckPassword(id, password); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
user, err := db.GetUser(id)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := saveSession(w, r, s, user); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user.Role)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Logout(s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
|
||||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
session.Options.MaxAge = -1
|
|
||||||
|
|
||||||
if err = session.Save(r, w); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,214 +0,0 @@
|
|||||||
package view
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"html/template"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"streifling.com/jason/cpolis/cmd/control"
|
|
||||||
"streifling.com/jason/cpolis/cmd/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UserData struct {
|
|
||||||
*model.User
|
|
||||||
Msg string
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkUserStrings(user *model.User) (string, int, bool) {
|
|
||||||
userLen := 15
|
|
||||||
nameLen := 50
|
|
||||||
|
|
||||||
if len(user.UserName) > userLen {
|
|
||||||
return "Benutzername", userLen, false
|
|
||||||
} else if len(user.FirstName) > nameLen {
|
|
||||||
return "Vorname", nameLen, false
|
|
||||||
} else if len(user.LastName) > nameLen {
|
|
||||||
return "Nachname", nameLen, false
|
|
||||||
} else {
|
|
||||||
return "", 0, true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateUser(w http.ResponseWriter, r *http.Request) {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddUser(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
role, err := strconv.Atoi(r.PostFormValue("role"))
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
htmlData := UserData{
|
|
||||||
User: &model.User{
|
|
||||||
UserName: r.PostFormValue("username"),
|
|
||||||
FirstName: r.PostFormValue("first-name"),
|
|
||||||
LastName: r.PostFormValue("last-name"),
|
|
||||||
Role: role,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
pass := r.PostFormValue("password")
|
|
||||||
pass2 := r.PostFormValue("password2")
|
|
||||||
|
|
||||||
if len(htmlData.UserName) == 0 || len(htmlData.FirstName) == 0 ||
|
|
||||||
len(htmlData.LastName) == 0 || len(pass) == 0 || len(pass2) == 0 {
|
|
||||||
htmlData.Msg = "Alle Felder müssen ausgefüllt werden."
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
userString, stringLen, ok := checkUserStrings(htmlData.User)
|
|
||||||
if !ok {
|
|
||||||
htmlData.Msg = fmt.Sprint(userString, " ist zu lang. Maximal ",
|
|
||||||
stringLen, " Zeichen erlaubt.")
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
id, _ := db.GetID(htmlData.UserName)
|
|
||||||
if id != 0 {
|
|
||||||
htmlData.Msg = fmt.Sprint(htmlData.UserName,
|
|
||||||
" ist bereits vergeben. Bitte anderen Benutzernamen wählen.")
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if pass != pass2 {
|
|
||||||
htmlData.Msg = "Die Passwörter stimmen nicht überein."
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/add-user.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", htmlData)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
htmlData.ID, err = db.AddUser(htmlData.User, pass)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if htmlData.ID == 1 {
|
|
||||||
htmlData.Role = model.Admin
|
|
||||||
|
|
||||||
if err = db.UpdateAttributes(
|
|
||||||
&model.Attribute{Table: "users", ID: id, AttName: "role", Value: htmlData.Role},
|
|
||||||
); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := saveSession(w, r, s, htmlData.User); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := db.AddIssue(); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func EditUser(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
|
||||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
user, err := db.GetUser(session.Values["id"].(int64))
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/edit-user.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateUser(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
session, err := s.Get(r, "cookie")
|
|
||||||
if err != nil {
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
|
||||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
userData := UserData{
|
|
||||||
User: &model.User{
|
|
||||||
ID: session.Values["id"].(int64),
|
|
||||||
UserName: r.PostFormValue("username"),
|
|
||||||
FirstName: r.PostFormValue("first-name"),
|
|
||||||
LastName: r.PostFormValue("last-name"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
oldPass := r.PostFormValue("old-password")
|
|
||||||
newPass := r.PostFormValue("password")
|
|
||||||
newPass2 := r.PostFormValue("password2")
|
|
||||||
|
|
||||||
if len(userData.UserName) == 0 || len(userData.FirstName) == 0 ||
|
|
||||||
len(userData.LastName) == 0 {
|
|
||||||
userData.Msg = "Alle Felder mit * müssen ausgefüllt sein."
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/edit-user.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", userData.Msg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
userString, stringLen, ok := checkUserStrings(userData.User)
|
|
||||||
if !ok {
|
|
||||||
userData.Msg = fmt.Sprint(userString, " ist zu lang. Maximal ",
|
|
||||||
stringLen, " Zeichen erlaubt.")
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/edit-user.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", userData)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if id, ok := db.GetID(userData.UserName); ok {
|
|
||||||
if id != userData.ID {
|
|
||||||
userData.Msg = "Benutzername bereits vergeben."
|
|
||||||
userData.UserName = ""
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/edit-user.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", userData)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = db.UpdateUserAttributes(
|
|
||||||
userData.ID,
|
|
||||||
userData.UserName,
|
|
||||||
userData.FirstName,
|
|
||||||
userData.LastName,
|
|
||||||
oldPass,
|
|
||||||
newPass,
|
|
||||||
newPass2); err != nil {
|
|
||||||
userData.Msg = "Aktualisierung der Benutzerdaten fehlgeschlagen."
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/edit-user.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", userData)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int))
|
|
||||||
}
|
|
||||||
}
|
|
14
cpolis.service
Normal file
14
cpolis.service
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=cpolis
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/local/bin/cpolis
|
||||||
|
User=cpolis
|
||||||
|
Group=cpolis
|
||||||
|
Restart=always
|
||||||
|
RestartSec=2s
|
||||||
|
Type=simple
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
75
create_db.sql
Normal file
75
create_db.sql
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
DROP TABLE IF EXISTS articles_tags;
|
||||||
|
DROP TABLE IF EXISTS articles_contributors;
|
||||||
|
DROP TABLE IF EXISTS articles_authors;
|
||||||
|
DROP TABLE IF EXISTS tags;
|
||||||
|
DROP TABLE IF EXISTS articles;
|
||||||
|
DROP TABLE IF EXISTS issues;
|
||||||
|
DROP TABLE IF EXISTS users;
|
||||||
|
|
||||||
|
CREATE TABLE users (
|
||||||
|
id INT AUTO_INCREMENT,
|
||||||
|
username VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
password VARCHAR(60) NOT NULL,
|
||||||
|
first_name VARCHAR(255) NOT NULL,
|
||||||
|
last_name VARCHAR(255) NOT NULL,
|
||||||
|
email VARCHAR(255) NOT NULL,
|
||||||
|
profile_pic_link VARCHAR(255),
|
||||||
|
role INT NOT NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE issues (
|
||||||
|
id INT AUTO_INCREMENT,
|
||||||
|
published BOOL NOT NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE articles (
|
||||||
|
id INT AUTO_INCREMENT,
|
||||||
|
title VARCHAR(255) NOT NULL,
|
||||||
|
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
banner_link VARCHAR(255),
|
||||||
|
summary TEXT NOT NULL,
|
||||||
|
published BOOL NOT NULL,
|
||||||
|
rejected BOOL NOT NULL,
|
||||||
|
creator_id INT NOT NULL,
|
||||||
|
issue_id INT NOT NULL,
|
||||||
|
edited_id INT NOT NULL,
|
||||||
|
clicks INT NOT NULL,
|
||||||
|
is_in_issue BOOL NOT NULL,
|
||||||
|
auto_generated BOOL NOT NULL,
|
||||||
|
uuid VARCHAR(36) NOT NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
FOREIGN KEY (creator_id) REFERENCES users (id),
|
||||||
|
FOREIGN KEY (issue_id) REFERENCES issues (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE tags (
|
||||||
|
id INT AUTO_INCREMENT,
|
||||||
|
name VARCHAR(50) NOT NULL UNIQUE,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE articles_authors (
|
||||||
|
article_id INT NOT NULL,
|
||||||
|
author_id INT NOT NULL,
|
||||||
|
PRIMARY KEY (article_id, author_id),
|
||||||
|
FOREIGN KEY (article_id) REFERENCES articles (id),
|
||||||
|
FOREIGN KEY (author_id) REFERENCES users (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE articles_contributors (
|
||||||
|
article_id INT NOT NULL,
|
||||||
|
contributor_id INT NOT NULL,
|
||||||
|
PRIMARY KEY (article_id, contributor_id),
|
||||||
|
FOREIGN KEY (article_id) REFERENCES articles (id),
|
||||||
|
FOREIGN KEY (contributor_id) REFERENCES users (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE articles_tags (
|
||||||
|
article_id INT NOT NULL,
|
||||||
|
tag_id INT NOT NULL,
|
||||||
|
PRIMARY KEY (article_id, tag_id),
|
||||||
|
FOREIGN KEY (article_id) REFERENCES articles (id),
|
||||||
|
FOREIGN KEY (tag_id) REFERENCES tags (id)
|
||||||
|
);
|
78
go.mod
78
go.mod
@ -1,21 +1,75 @@
|
|||||||
module streifling.com/jason/cpolis
|
module streifling.com/jason/cpolis
|
||||||
|
|
||||||
go 1.22.0
|
go 1.23.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.streifling.com/jason/rss v0.0.0-20240305164907-524bf9676188
|
firebase.google.com/go/v4 v4.15.1
|
||||||
github.com/go-sql-driver/mysql v1.7.1
|
git.streifling.com/jason/atom v1.0.0
|
||||||
github.com/gorilla/sessions v1.2.2
|
github.com/BurntSushi/toml v1.4.0
|
||||||
github.com/microcosm-cc/bluemonday v1.0.26
|
github.com/chai2010/webp v1.1.1
|
||||||
github.com/yuin/goldmark v1.7.0
|
github.com/disintegration/imaging v1.6.2
|
||||||
golang.org/x/crypto v0.14.0
|
github.com/gabriel-vasile/mimetype v1.4.8
|
||||||
golang.org/x/term v0.17.0
|
github.com/go-sql-driver/mysql v1.8.1
|
||||||
|
github.com/google/uuid v1.6.0
|
||||||
|
github.com/microcosm-cc/bluemonday v1.0.27
|
||||||
|
github.com/yuin/goldmark v1.7.8
|
||||||
|
golang.org/x/crypto v0.32.0
|
||||||
|
golang.org/x/term v0.28.0
|
||||||
|
google.golang.org/api v0.216.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
cel.dev/expr v0.19.1 // indirect
|
||||||
|
cloud.google.com/go v0.118.0 // indirect
|
||||||
|
cloud.google.com/go/auth v0.14.0 // indirect
|
||||||
|
cloud.google.com/go/auth/oauth2adapt v0.2.7 // indirect
|
||||||
|
cloud.google.com/go/compute/metadata v0.6.0 // indirect
|
||||||
|
cloud.google.com/go/firestore v1.18.0 // indirect
|
||||||
|
cloud.google.com/go/iam v1.3.1 // indirect
|
||||||
|
cloud.google.com/go/longrunning v0.6.4 // indirect
|
||||||
|
cloud.google.com/go/monitoring v1.22.1 // indirect
|
||||||
|
cloud.google.com/go/storage v1.50.0 // indirect
|
||||||
|
filippo.io/edwards25519 v1.1.0 // indirect
|
||||||
|
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0 // indirect
|
||||||
|
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.49.0 // indirect
|
||||||
|
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0 // indirect
|
||||||
|
github.com/MicahParks/keyfunc v1.9.0 // indirect
|
||||||
github.com/aymerick/douceur v0.2.0 // indirect
|
github.com/aymerick/douceur v0.2.0 // indirect
|
||||||
github.com/gorilla/css v1.0.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/gorilla/securecookie v1.1.2 // indirect
|
github.com/cncf/xds/go v0.0.0-20241223141626-cff3c89139a3 // indirect
|
||||||
golang.org/x/net v0.17.0 // indirect
|
github.com/envoyproxy/go-control-plane/envoy v1.32.3 // indirect
|
||||||
golang.org/x/sys v0.17.0 // indirect
|
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
|
||||||
|
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||||
|
github.com/go-logr/logr v1.4.2 // indirect
|
||||||
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
|
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
|
||||||
|
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
|
||||||
|
github.com/golang/protobuf v1.5.4 // indirect
|
||||||
|
github.com/google/s2a-go v0.1.9 // indirect
|
||||||
|
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
|
||||||
|
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
|
||||||
|
github.com/gorilla/css v1.0.1 // indirect
|
||||||
|
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
|
||||||
|
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||||
|
go.opentelemetry.io/contrib/detectors/gcp v1.33.0 // indirect
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.58.0 // indirect
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
|
||||||
|
go.opentelemetry.io/otel v1.33.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/metric v1.33.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/sdk v1.33.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/sdk/metric v1.33.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/trace v1.33.0 // indirect
|
||||||
|
golang.org/x/image v0.23.0 // indirect
|
||||||
|
golang.org/x/net v0.34.0 // indirect
|
||||||
|
golang.org/x/oauth2 v0.25.0 // indirect
|
||||||
|
golang.org/x/sync v0.10.0 // indirect
|
||||||
|
golang.org/x/sys v0.29.0 // indirect
|
||||||
|
golang.org/x/text v0.21.0 // indirect
|
||||||
|
golang.org/x/time v0.9.0 // indirect
|
||||||
|
google.golang.org/appengine/v2 v2.0.6 // indirect
|
||||||
|
google.golang.org/genproto v0.0.0-20250106144421-5f5ef82da422 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 // indirect
|
||||||
|
google.golang.org/grpc v1.69.2 // indirect
|
||||||
|
google.golang.org/protobuf v1.36.2 // indirect
|
||||||
)
|
)
|
||||||
|
212
go.sum
212
go.sum
@ -1,26 +1,190 @@
|
|||||||
git.streifling.com/jason/rss v0.0.0-20240305164907-524bf9676188 h1:C8M/j3f+cl5Y7YfGpU/ynb/SC/4tTYMDsyGFt3rswM8=
|
cel.dev/expr v0.19.1 h1:NciYrtDRIR0lNCnH1LFJegdjspNx9fI59O7TWcua/W4=
|
||||||
git.streifling.com/jason/rss v0.0.0-20240305164907-524bf9676188/go.mod h1:gpZF0nZbQSstMpyHD9DTAvlQEG7v4pjO5c7aIMWM4Jg=
|
cel.dev/expr v0.19.1/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
|
||||||
|
cloud.google.com/go v0.118.0 h1:tvZe1mgqRxpiVa3XlIGMiPcEUbP1gNXELgD4y/IXmeQ=
|
||||||
|
cloud.google.com/go v0.118.0/go.mod h1:zIt2pkedt/mo+DQjcT4/L3NDxzHPR29j5HcclNH+9PM=
|
||||||
|
cloud.google.com/go/auth v0.14.0 h1:A5C4dKV/Spdvxcl0ggWwWEzzP7AZMJSEIgrkngwhGYM=
|
||||||
|
cloud.google.com/go/auth v0.14.0/go.mod h1:CYsoRL1PdiDuqeQpZE0bP2pnPrGqFcOkI0nldEQis+A=
|
||||||
|
cloud.google.com/go/auth/oauth2adapt v0.2.7 h1:/Lc7xODdqcEw8IrZ9SvwnlLX6j9FHQM74z6cBk9Rw6M=
|
||||||
|
cloud.google.com/go/auth/oauth2adapt v0.2.7/go.mod h1:NTbTTzfvPl1Y3V1nPpOgl2w6d/FjO7NNUQaWSox6ZMc=
|
||||||
|
cloud.google.com/go/compute/metadata v0.6.0 h1:A6hENjEsCDtC1k8byVsgwvVcioamEHvZ4j01OwKxG9I=
|
||||||
|
cloud.google.com/go/compute/metadata v0.6.0/go.mod h1:FjyFAW1MW0C203CEOMDTu3Dk1FlqW3Rga40jzHL4hfg=
|
||||||
|
cloud.google.com/go/firestore v1.18.0 h1:cuydCaLS7Vl2SatAeivXyhbhDEIR8BDmtn4egDhIn2s=
|
||||||
|
cloud.google.com/go/firestore v1.18.0/go.mod h1:5ye0v48PhseZBdcl0qbl3uttu7FIEwEYVaWm0UIEOEU=
|
||||||
|
cloud.google.com/go/iam v1.3.1 h1:KFf8SaT71yYq+sQtRISn90Gyhyf4X8RGgeAVC8XGf3E=
|
||||||
|
cloud.google.com/go/iam v1.3.1/go.mod h1:3wMtuyT4NcbnYNPLMBzYRFiEfjKfJlLVLrisE7bwm34=
|
||||||
|
cloud.google.com/go/logging v1.13.0 h1:7j0HgAp0B94o1YRDqiqm26w4q1rDMH7XNRU34lJXHYc=
|
||||||
|
cloud.google.com/go/logging v1.13.0/go.mod h1:36CoKh6KA/M0PbhPKMq6/qety2DCAErbhXT62TuXALA=
|
||||||
|
cloud.google.com/go/longrunning v0.6.4 h1:3tyw9rO3E2XVXzSApn1gyEEnH2K9SynNQjMlBi3uHLg=
|
||||||
|
cloud.google.com/go/longrunning v0.6.4/go.mod h1:ttZpLCe6e7EXvn9OxpBRx7kZEB0efv8yBO6YnVMfhJs=
|
||||||
|
cloud.google.com/go/monitoring v1.22.1 h1:KQbnAC4IAH+5x3iWuPZT5iN9VXqKMzzOgqcYB6fqPDE=
|
||||||
|
cloud.google.com/go/monitoring v1.22.1/go.mod h1:AuZZXAoN0WWWfsSvET1Cpc4/1D8LXq8KRDU87fMS6XY=
|
||||||
|
cloud.google.com/go/storage v1.50.0 h1:3TbVkzTooBvnZsk7WaAQfOsNrdoM8QHusXA1cpk6QJs=
|
||||||
|
cloud.google.com/go/storage v1.50.0/go.mod h1:l7XeiD//vx5lfqE3RavfmU9yvk5Pp0Zhcv482poyafY=
|
||||||
|
cloud.google.com/go/trace v1.11.3 h1:c+I4YFjxRQjvAhRmSsmjpASUKq88chOX854ied0K/pE=
|
||||||
|
cloud.google.com/go/trace v1.11.3/go.mod h1:pt7zCYiDSQjC9Y2oqCsh9jF4GStB/hmjrYLsxRR27q8=
|
||||||
|
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||||
|
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||||
|
firebase.google.com/go/v4 v4.15.1 h1:tR2dzKw1MIfCfG2bhAyxa5KQ57zcE7iFKmeYClET6ZM=
|
||||||
|
firebase.google.com/go/v4 v4.15.1/go.mod h1:eunxbsh4UXI2rA8po3sOiebvWYuW0DVxAdZFO0I6wdY=
|
||||||
|
git.streifling.com/jason/atom v1.0.0 h1:E88z4S7JeT6T+WuAaJWnGwCWTx+vzSJ6giUL51MdptI=
|
||||||
|
git.streifling.com/jason/atom v1.0.0/go.mod h1:FNTYJfatYaIOQn4OKy8y+Mtohqm3MeyEGZUu4bMtZ9E=
|
||||||
|
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
||||||
|
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
|
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0 h1:3c8yed4lgqTt+oTQ+JNMDo+F4xprBf+O/il4ZC0nRLw=
|
||||||
|
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0/go.mod h1:obipzmGjfSjam60XLwGfqUkJsfiheAl+TUjG+4yzyPM=
|
||||||
|
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.49.0 h1:o90wcURuxekmXrtxmYWTyNla0+ZEHhud6DI1ZTxd1vI=
|
||||||
|
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.49.0/go.mod h1:6fTWu4m3jocfUZLYF5KsZC1TUfRvEjs7lM4crme/irw=
|
||||||
|
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.49.0 h1:jJKWl98inONJAr/IZrdFQUWcwUO95DLY1XMD1ZIut+g=
|
||||||
|
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.49.0/go.mod h1:l2fIqmwB+FKSfvn3bAD/0i+AXAxhIZjTK2svT/mgUXs=
|
||||||
|
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0 h1:GYUJLfvd++4DMuMhCFLgLXvFwofIxh/qOwoGuS/LTew=
|
||||||
|
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0/go.mod h1:wRbFgBQUVm1YXrvWKofAEmq9HNJTDphbAaJSSX01KUI=
|
||||||
|
github.com/MicahParks/keyfunc v1.9.0 h1:lhKd5xrFHLNOWrDc4Tyb/Q1AJ4LCzQ48GVJyVIID3+o=
|
||||||
|
github.com/MicahParks/keyfunc v1.9.0/go.mod h1:IdnCilugA0O/99dW+/MkvlyrsX8+L8+x95xuVNtM5jw=
|
||||||
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
||||||
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
||||||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
github.com/chai2010/webp v1.1.1 h1:jTRmEccAJ4MGrhFOrPMpNGIJ/eybIgwKpcACsrTEapk=
|
||||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/chai2010/webp v1.1.1/go.mod h1:0XVwvZWdjjdxpUEIf7b9g9VkHFnInUSYujwqTLEuldU=
|
||||||
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
|
github.com/cncf/xds/go v0.0.0-20241223141626-cff3c89139a3 h1:boJj011Hh+874zpIySeApCX4GeOjPl9qhRF3QuIZq+Q=
|
||||||
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
|
github.com/cncf/xds/go v0.0.0-20241223141626-cff3c89139a3/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
|
||||||
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY=
|
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
|
||||||
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
|
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
|
||||||
github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58=
|
github.com/envoyproxy/go-control-plane v0.13.4 h1:zEqyPVyku6IvWCFwux4x9RxkLOMUL+1vC9xUFv5l2/M=
|
||||||
github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs=
|
github.com/envoyproxy/go-control-plane v0.13.4/go.mod h1:kDfuBlDVsSj2MjrLEtRWtHlsWIFcGyB2RMO44Dc5GZA=
|
||||||
github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA=
|
github.com/envoyproxy/go-control-plane/envoy v1.32.3 h1:hVEaommgvzTjTd4xCaFd+kEQ2iYBtGxP6luyLrx6uOk=
|
||||||
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
github.com/envoyproxy/go-control-plane/envoy v1.32.3/go.mod h1:F6hWupPfh75TBXGKA++MCT/CZHFq5r9/uwt/kQYkZfE=
|
||||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
github.com/envoyproxy/go-control-plane/ratelimit v0.1.0 h1:/G9QYbddjL25KvtKTv3an9lx6VBE2cnb8wp1vEGNYGI=
|
||||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
github.com/envoyproxy/go-control-plane/ratelimit v0.1.0/go.mod h1:Wk+tMFAFbCXaJPzVVHnPgRKdUdwW/KdbRt94AzgRee4=
|
||||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
github.com/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6Uu2PdjCQwWCJ3bM=
|
||||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4=
|
||||||
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
|
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||||
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
|
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
||||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
||||||
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
|
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||||
|
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
|
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||||
|
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||||
|
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||||
|
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
|
||||||
|
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||||
|
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
|
||||||
|
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
|
||||||
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
|
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||||
|
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||||
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/google/martian/v3 v3.3.3 h1:DIhPTQrbPkgs2yJYdXU/eNACCG5DVQjySNRNlflZ9Fc=
|
||||||
|
github.com/google/martian/v3 v3.3.3/go.mod h1:iEPrYcgCF7jA9OtScMFQyAlZZ4YXTKEtJ1E6RWzmBA0=
|
||||||
|
github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0=
|
||||||
|
github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM=
|
||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/googleapis/enterprise-certificate-proxy v0.3.4 h1:XYIDZApgAnrN1c855gTgghdIA6Stxb52D5RnLI1SLyw=
|
||||||
|
github.com/googleapis/enterprise-certificate-proxy v0.3.4/go.mod h1:YKe7cfqYXjKGpGvmSg28/fFvhNzinZQm8DGnaburhGA=
|
||||||
|
github.com/googleapis/gax-go/v2 v2.14.1 h1:hb0FFeiPaQskmvakKu5EbCbpntQn48jyHuvrkurSS/Q=
|
||||||
|
github.com/googleapis/gax-go/v2 v2.14.1/go.mod h1:Hb/NubMaVM88SrNkvl8X/o8XWwDJEPqouaLeN2IUxoA=
|
||||||
|
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
|
||||||
|
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
|
||||||
|
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
|
||||||
|
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
|
||||||
|
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=
|
||||||
|
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
|
||||||
|
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||||
|
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||||
|
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
||||||
|
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||||
|
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||||
|
go.opentelemetry.io/contrib/detectors/gcp v1.33.0 h1:FVPoXEoILwgbZUu4X7YSgsESsAmGRgoYcnXkzgQPhP4=
|
||||||
|
go.opentelemetry.io/contrib/detectors/gcp v1.33.0/go.mod h1:ZHrLmr4ikK2AwRj9QL+c9s2SOlgoSRyMpNVzUj2fZqI=
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.58.0 h1:PS8wXpbyaDJQ2VDHHncMe9Vct0Zn1fEjpsjrLxGJoSc=
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.58.0/go.mod h1:HDBUsEjOuRC0EzKZ1bSaRGZWUBAzo+MhAcUUORSr4D0=
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 h1:yd02MEjBdJkG3uabWP9apV+OuWRIXGDuJEUJbOHmCFU=
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0/go.mod h1:umTcuxiv1n/s/S6/c2AT/g2CQ7u5C59sHDNmfSwgz7Q=
|
||||||
|
go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw=
|
||||||
|
go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I=
|
||||||
|
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.29.0 h1:WDdP9acbMYjbKIyJUhTvtzj601sVJOqgWdUxSdR/Ysc=
|
||||||
|
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.29.0/go.mod h1:BLbf7zbNIONBLPwvFnwNHGj4zge8uTCM/UPIVW1Mq2I=
|
||||||
|
go.opentelemetry.io/otel/metric v1.33.0 h1:r+JOocAyeRVXD8lZpjdQjzMadVZp2M4WmQ+5WtEnklQ=
|
||||||
|
go.opentelemetry.io/otel/metric v1.33.0/go.mod h1:L9+Fyctbp6HFTddIxClbQkjtubW6O9QS3Ann/M82u6M=
|
||||||
|
go.opentelemetry.io/otel/sdk v1.33.0 h1:iax7M131HuAm9QkZotNHEfstof92xM+N8sr3uHXc2IM=
|
||||||
|
go.opentelemetry.io/otel/sdk v1.33.0/go.mod h1:A1Q5oi7/9XaMlIWzPSxLRWOI8nG3FnzHJNbiENQuihM=
|
||||||
|
go.opentelemetry.io/otel/sdk/metric v1.33.0 h1:Gs5VK9/WUJhNXZgn8MR6ITatvAmKeIuCtNbsP3JkNqU=
|
||||||
|
go.opentelemetry.io/otel/sdk/metric v1.33.0/go.mod h1:dL5ykHZmm1B1nVRk9dDjChwDmt81MjVp3gLkQRwKf/Q=
|
||||||
|
go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s=
|
||||||
|
go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
|
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
|
||||||
|
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
|
||||||
|
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
|
golang.org/x/image v0.23.0 h1:HseQ7c2OpPKTPVzNjG5fwJsOTCiiwS4QdsYi5XU6H68=
|
||||||
|
golang.org/x/image v0.23.0/go.mod h1:wJJBTdLfCCf3tiHa1fNxpZmUI4mmoZvwMCPP0ddoNKY=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
|
||||||
|
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
|
||||||
|
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
|
||||||
|
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
||||||
|
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||||
|
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
|
||||||
|
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||||
|
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||||
|
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||||
|
golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY=
|
||||||
|
golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/api v0.216.0 h1:xnEHy+xWFrtYInWPy8OdGFsyIfWJjtVnO39g7pz2BFY=
|
||||||
|
google.golang.org/api v0.216.0/go.mod h1:K9wzQMvWi47Z9IU7OgdOofvZuw75Ge3PPITImZR/UyI=
|
||||||
|
google.golang.org/appengine/v2 v2.0.6 h1:LvPZLGuchSBslPBp+LAhihBeGSiRh1myRoYK4NtuBIw=
|
||||||
|
google.golang.org/appengine/v2 v2.0.6/go.mod h1:WoEXGoXNfa0mLvaH5sV3ZSGXwVmy8yf7Z1JKf3J3wLI=
|
||||||
|
google.golang.org/genproto v0.0.0-20250106144421-5f5ef82da422 h1:6GUHKGv2huWOHKmDXLMNE94q3fBDlEHI+oTRIZSebK0=
|
||||||
|
google.golang.org/genproto v0.0.0-20250106144421-5f5ef82da422/go.mod h1:1NPAxoesyw/SgLPqaUp9u1f9PWCLAk/jVmhx7gJZStg=
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 h1:GVIKPyP/kLIyVOgOnTwFOrvQaQUzOzGMCxgFUOEmm24=
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422/go.mod h1:b6h1vNKhxaSoEI+5jc3PJUCustfli/mRab7295pY7rw=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 h1:3UsHvIr4Wc2aW4brOaSCmcxh9ksica6fHEr8P1XhkYw=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422/go.mod h1:3ENsm/5D1mzDyhpzeRi1NR784I0BcofWBoSc5QqqMK4=
|
||||||
|
google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
|
||||||
|
google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
|
||||||
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
|
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
|
google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
|
||||||
|
google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
11
tailwind.config.js
Normal file
11
tailwind.config.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
module.exports = {
|
||||||
|
content: ["./web/templates/*.html"],
|
||||||
|
theme: {
|
||||||
|
extend: {}
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
require('@tailwindcss/typography')
|
||||||
|
],
|
||||||
|
darkMode: 'selector',
|
||||||
|
}
|
58
update.sh
Executable file
58
update.sh
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
#! /bin/sh -
|
||||||
|
|
||||||
|
CPOLIS_REPO_URL="https://git.streifling.com/api/v1/repos/jason/cpolis/releases"
|
||||||
|
EXTRACTION_DIR=$HOME
|
||||||
|
CPOLIS_DIR=$EXTRACTION_DIR/cpolis
|
||||||
|
TAILWINDCSS_REPO_URL=https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest
|
||||||
|
TMP_DIR=/tmp
|
||||||
|
BIN_DIR=/usr/local/bin
|
||||||
|
SYSTEMD_DIR=/etc/systemd/system
|
||||||
|
|
||||||
|
check_dependency() {
|
||||||
|
if ! which $1 >/dev/null 2>&1; then
|
||||||
|
echo "$1 needs to be installed" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! groups | grep -E 'root|wheel|sudo' >/dev/null; then
|
||||||
|
echo "You need administrative privileges for this script" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
check_dependency curl
|
||||||
|
check_dependency go
|
||||||
|
check_dependency jq
|
||||||
|
check_dependency tar
|
||||||
|
check_dependency xargs
|
||||||
|
|
||||||
|
echo '\nDownloading cpolis...' >&2
|
||||||
|
rm -fr $CPOLIS_DIR/*
|
||||||
|
latest_release=$(curl -s $CPOLIS_REPO_URL | jq -r '.[0].tag_name')
|
||||||
|
curl -Lo $TMP_DIR/cpolis.tar.gz https://git.streifling.com/jason/cpolis/archive/$latest_release.tar.gz
|
||||||
|
tar -xzf $TMP_DIR/cpolis.tar.gz -C $EXTRACTION_DIR
|
||||||
|
rm $TMP_DIR/cpolis.tar.gz
|
||||||
|
|
||||||
|
echo '\nDownloading TailwindCSS...' >&2
|
||||||
|
curl -s $TAILWINDCSS_REPO_URL |
|
||||||
|
grep -F browser_download_url |
|
||||||
|
grep -F linux-x64 |
|
||||||
|
cut -d'"' -f4 |
|
||||||
|
xargs -r curl -Lo $CPOLIS_DIR/tailwindcss
|
||||||
|
chmod +x $CPOLIS_DIR/tailwindcss
|
||||||
|
$CPOLIS_DIR/tailwindcss -i $CPOLIS_DIR/web/static/css/input.css -o $CPOLIS_DIR/web/static/css/style.css
|
||||||
|
|
||||||
|
echo '\nBuilding cpolis...' >&2
|
||||||
|
cd $CPOLIS_DIR
|
||||||
|
go build -o $BIN_DIR/cpolis cmd/main.go
|
||||||
|
cd
|
||||||
|
|
||||||
|
echo '\nSetting up system files...' >&2
|
||||||
|
sudo chown root:root $BIN_DIR/cpolis
|
||||||
|
chmod +x $BIN_DIR/cpolis
|
||||||
|
|
||||||
|
echo '\nSetting up service...' >&2
|
||||||
|
sudo mv $CPOLIS_DIR/cpolis.service $SYSTEMD_DIR
|
||||||
|
sudo chown root:root $SYSTEMD_DIR/cpolis.service
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl is-active --quiet cpolis.service && sudo systemctl restart cpolis.service
|
72
web/static/css/input.css
Normal file
72
web/static/css/input.css
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
@tailwind base;
|
||||||
|
@tailwind components;
|
||||||
|
@tailwind utilities;
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
@apply font-bold mb-2 text-2xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
@apply font-bold mb-2 text-xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="password"],
|
||||||
|
input[type="text"] {
|
||||||
|
@apply bg-slate-50 dark:bg-slate-950 border border-slate-200 dark:border-slate-800 h-8 rounded-md;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
@apply bg-slate-50 dark:bg-slate-950 border border-slate-200 dark:border-slate-800 h-32 rounded-md;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-area-1 {
|
||||||
|
@apply grid grid-cols-1 gap-x-4 gap-y-1 mt-4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-area {
|
||||||
|
@apply grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-area-3 {
|
||||||
|
@apply grid grid-cols-1 md:grid-cols-3 gap-x-4 gap-y-1 mt-4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
@apply bg-slate-200 dark:bg-slate-800 hover:bg-slate-100 dark:hover:bg-slate-900 border border-slate-200 dark:border-slate-800 cursor-pointer my-2 px-3 py-2 rounded-md w-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn {
|
||||||
|
@apply bg-slate-800 dark:bg-slate-200 hover:bg-slate-700 dark:hover:bg-slate-300 cursor-pointer my-2 px-3 py-2 rounded-md text-slate-50 dark:text-slate-950 w-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
.EasyMDEContainer .CodeMirror {
|
||||||
|
@apply bg-slate-50 dark:bg-slate-950 border-slate-200 dark:border-slate-800 text-slate-900 dark:text-slate-100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.EasyMDEContainer .cm-s-easymde .CodeMirror-cursor {
|
||||||
|
@apply border-slate-900 dark:border-slate-100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.EasyMDEContainer .editor-toolbar > * {
|
||||||
|
@apply text-slate-900 dark:text-slate-100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.EasyMDEContainer .editor-toolbar > .active, .editor-toolbar > button:hover, .editor-preview pre, .cm-s-easymde .cm-comment {
|
||||||
|
@apply bg-slate-100 dark:bg-slate-900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.EasyMDEContainer .CodeMirror-fullscreen {
|
||||||
|
@apply bg-slate-50 dark:bg-slate-950;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-toolbar {
|
||||||
|
@apply border border-slate-200 dark:border-slate-800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-toolbar.fullscreen {
|
||||||
|
@apply bg-slate-50 dark:bg-slate-950;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-preview {
|
||||||
|
@apply bg-slate-50 dark:bg-slate-950;
|
||||||
|
}
|
1
web/static/js/htmx.min.js
vendored
1
web/static/js/htmx.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,8 +1,12 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<h2>Neuer Benutzer</h2>
|
<h2>Neuer Tag</h2>
|
||||||
|
|
||||||
<form>
|
<form>
|
||||||
<input required name="tag" placeholder="Tag" type="text" />
|
<input class="w-full" name="tag" placeholder="Tag eingeben" required type="text" />
|
||||||
<input type="submit" value="Anlegen" hx-post="/add-tag/" hx-target="#page-content" />
|
<div class="btn-area">
|
||||||
|
<input class="action-btn" type="submit" value="Anlegen" hx-post="/tag/add" hx-target="#page-content" />
|
||||||
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<button hx-get="/hub/" hx-target="#page-content">Abbrechen</button>
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
{{define "page-content"}}
|
|
||||||
<h2>Neuer Benutzer</h2>
|
|
||||||
<form>
|
|
||||||
<input required name="username" placeholder="Benutzername" type="text" value="{{.UserName}}" />
|
|
||||||
<input required name="password" placeholder="Passwort" type="password" />
|
|
||||||
<input required name="password2" placeholder="Passwort wiederholen" type="password" />
|
|
||||||
|
|
||||||
<input required name="first-name" placeholder="Vorname" type="text" value="{{.FirstName}}" />
|
|
||||||
<input required name="last-name" placeholder="Nachname" type="text" value="{{.LastName}}" />
|
|
||||||
|
|
||||||
<input required id="author" name="role" type="radio" value="3" {{if eq .Role 3 }}checked{{end}} />
|
|
||||||
<label for="author">Autor</label>
|
|
||||||
<input required id="editor" name="role" type="radio" value="2" {{if eq .Role 2 }}checked{{end}} />
|
|
||||||
<label for="editor">Redakteur</label>
|
|
||||||
<input required id="publisher" name="role" type="radio" value="1" {{if eq .Role 1 }}checked{{end}} />
|
|
||||||
<label for="publisher">Herausgeber</label>
|
|
||||||
<input required id="admin" name="role" type="radio" value="0" {{if eq .Role 0 }}checked{{end}} />
|
|
||||||
<label for="admin">Admin</label>
|
|
||||||
|
|
||||||
<input type="submit" value="Anlegen" hx-post="/add-user/" hx-target="#page-content" />
|
|
||||||
</form>
|
|
||||||
<button hx-get="/hub/" hx-target="#page-content">Abbrechen</button>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
var msg = "{{.Msg}}";
|
|
||||||
if (msg != "") {
|
|
||||||
alert(msg);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
{{end}}
|
|
@ -1,10 +0,0 @@
|
|||||||
{{define "page-content"}}
|
|
||||||
{{range .}}
|
|
||||||
<div>
|
|
||||||
<h1>{{.Title}}</h1>
|
|
||||||
<p>{{.Description}}</p>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
<button hx-get="/publish-issue/" hx-target="#page-content">Ausgabe publizieren</button>
|
|
||||||
<button hx-get="/hub/" hx-target="#page-content">Abbrechen</button>
|
|
||||||
{{end}}
|
|
86
web/templates/current-issue.html
Normal file
86
web/templates/current-issue.html
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
{{define "page-content"}}
|
||||||
|
<h2>Diese Ausgabe</h2>
|
||||||
|
|
||||||
|
<form hx-encoding="multipart/form-data">
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<div class="w-full" id="issue-banner-container"></div>
|
||||||
|
|
||||||
|
<h3>Titelseite</h3>
|
||||||
|
<div class="grid grid-cols-2 gap-4 items-center">
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<label for="issue-title">Titel</label>
|
||||||
|
<input name="issue-title" required type="text" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 items-center">
|
||||||
|
<label class="btn text-center" for="issue-banner-upload">Titelbild</label>
|
||||||
|
<input class="hidden" id="issue-banner-upload" name="issue-banner" type="file" required
|
||||||
|
hx-post="/issue/upload-banner" hx-target="#issue-banner-container" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3>Über diese Ausgabe</h3>
|
||||||
|
<div>
|
||||||
|
<textarea id="easyMDE" placeholder="Beschreibung dieser Ausgabe"></textarea>
|
||||||
|
<input id="issue-content" name="issue-content" type="hidden" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3>Aktuelle Artikel</h3>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
{{range .}}
|
||||||
|
<div class="border border-slate-200 dark:border-slate-800 px-2 py-1 rounded-md">
|
||||||
|
<h1 class="font-bold text-2xl">{{.Title}}</h1>
|
||||||
|
<p>{{.Summary}}</p>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="btn-area">
|
||||||
|
<button class="action-btn" hx-post="/issue/publish" hx-target="#page-content">Ausgabe publizieren</button>
|
||||||
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var easyMDE = new EasyMDE({
|
||||||
|
element: document.getElementById('easyMDE'),
|
||||||
|
hideIcons: ['image'],
|
||||||
|
imageTexts: {sbInit: ''},
|
||||||
|
showIcons: ["code", "table", "upload-image"],
|
||||||
|
uploadImage: true,
|
||||||
|
|
||||||
|
imageUploadFunction: function (file, onSuccess, onError) {
|
||||||
|
var formData = new FormData();
|
||||||
|
formData.append('article-image', file);
|
||||||
|
|
||||||
|
fetch('/article/upload-image', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
onSuccess(data);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
onError(error);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
easyMDE.codemirror.on("change", () => {
|
||||||
|
document.getElementById('issue-content').value = easyMDE.value();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
{{define "issue-banner-template"}}
|
||||||
|
<div id="issue-banner-container">
|
||||||
|
<img src="/image/serve/{{.Image}}" alt="" />
|
||||||
|
<input id="issue-banner-url" name="issue-banner-url" type="hidden" value="{{.Image}}" />
|
||||||
|
</div>
|
||||||
|
{{end}}
|
@ -1,13 +1,90 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<form>
|
<h2>{{.Title}}</h2>
|
||||||
<input name="username" type="text" value="{{.UserName}}" />
|
|
||||||
<input name="first-name" type="text" value="{{.FirstName}}" />
|
|
||||||
<input name="last-name" type="text" value="{{.LastName}}" />
|
|
||||||
|
|
||||||
<input name="old-password" placeholder="Altes Passwort" type="password" />
|
<form class="flex flex-col gap-4" hx-encoding="multipart/form-data">
|
||||||
<input name="password" placeholder="Neues Passwort" type="password" />
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
<input name="password2" placeholder="Wiederholen" type="password" />
|
{{template "profile-pic-template" .}}
|
||||||
|
|
||||||
<input type="submit" value="Aktualisieren" hx-post="/update-user/" hx-target="#page-content" />
|
<div>
|
||||||
|
<label for="username">Benutzername</label>
|
||||||
|
<input class="w-full" required name="username" type="text" {{if lt .Role 4}}value="{{.UserName}}" {{end}} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="password">Passwort</label>
|
||||||
|
<input class="w-full" required name="password" placeholder="***" type="password" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="password2">Passwort wiederholen</label>
|
||||||
|
<input class="w-full" required name="password2" placeholder="***" type="password" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="first-name">Vorname</label>
|
||||||
|
<input class="w-full" required name="first-name" type="text" {{if lt .Role 4}}value="{{.FirstName}}"
|
||||||
|
{{end}} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="last-name">Nachname</label>
|
||||||
|
<input class="w-full" required name="last-name" type="text" {{if lt .Role 4}}value="{{.LastName}}"
|
||||||
|
{{end}} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="email">Emailadresse</label>
|
||||||
|
<input class="w-full" required name="email" type="text" {{if lt .Role 4}}value="{{.Email}}" {{end}} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="email2">Emailadresse wiederholen</label>
|
||||||
|
<input class="w-full" required name="email2" type="text" {{if lt .Role 4}}value="{{.Email}}" {{end}} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{if lt .Role 4}}
|
||||||
|
<div class="flex flex-wrap gap-4">
|
||||||
|
<div>
|
||||||
|
<input required id="author" name="role" type="radio" value="3" {{if eq .Role 3}}checked{{end}} />
|
||||||
|
<label for="author">Autor</label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<input required id="editor" name="role" type="radio" value="2" {{if eq .Role 2}}checked{{end}} />
|
||||||
|
<label for="editor">Redakteur</label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<input required id="publisher" name="role" type="radio" value="1" {{if eq .Role 1}}checked{{end}} />
|
||||||
|
<label for="publisher">Herausgeber</label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<input required id="admin" name="role" type="radio" value="0" {{if eq .Role 0}}checked{{end}} />
|
||||||
|
<label for="admin">Administrator</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
<div class="btn-area">
|
||||||
|
<input class="action-btn" type="submit" value="{{.ButtonText}}" hx-post="{{.URL}}" hx-target="#page-content" />
|
||||||
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{define "profile-pic-template"}}
|
||||||
|
<div class="flex items-center justify-center row-span-3 self-center" id="profile-pic-container">
|
||||||
|
<label
|
||||||
|
class="bg-slate-200 dark:bg-slate-800 hover:bg-slate-100 dark:hover:bg-slate-900 border border-slate-200 dark:border-slate-800 cursor-pointer flex flex-col h-48 items-center justify-center overflow-hidden rounded-full w-48"
|
||||||
|
for="upload-profile-pic">
|
||||||
|
{{if gt (len .Image) 0}}
|
||||||
|
<img src="/image/serve/{{.Image}}" alt="" />
|
||||||
|
{{else}}
|
||||||
|
<span class="text-2xl">+</span>
|
||||||
|
<span>Profilbild</span>
|
||||||
|
{{end}}
|
||||||
|
</label>
|
||||||
|
<input class="hidden" id="upload-profile-pic" name="upload-profile-pic" type="file"
|
||||||
|
hx-post="/user/upload-profile-pic" hx-swap="outerHTML" hx-target="#profile-pic-container" />
|
||||||
|
<input id="profile-pic-url" name="profile-pic-url" type="hidden" value="{{.Image}}" />
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
@ -1,13 +1,128 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<h2>Editor</h2>
|
<h2>Editor</h2>
|
||||||
<form>
|
|
||||||
<input name="article-title" placeholder="Titel" type="text" />
|
<form class="flex flex-col gap-4" id="edit-area" hx-encoding="multipart/form-data">
|
||||||
<textarea name="article-description" placeholder="Beschreibung"></textarea>
|
<div class="flex flex-col gap-y-1">
|
||||||
<textarea name="article-content" placeholder="Artikel"></textarea>
|
{{template "article-banner-template" .}}
|
||||||
{{range .}}
|
|
||||||
<input id="{{.Name}}" name="tags" type="checkbox" value="{{.ID}}" />
|
<div class="grid grid-cols-2 gap-4 items-center">
|
||||||
<label for="{{.Name}}">{{.Name}}</label>
|
<div class="flex flex-col">
|
||||||
{{end}}
|
<h3>Titel</h3>
|
||||||
<input type="submit" value="Senden" hx-post="/submit-article/" hx-target="#page-content" />
|
<input name="article-title" type="text" value="{{.Article.Title}}" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex">
|
||||||
|
<label class="btn text-center" for="article-banner">Titelbild</label>
|
||||||
|
<input class="hidden" id="article-banner" name="article-banner" type="file" required
|
||||||
|
hx-post="/article/upload-banner" hx-swap="outerHTML" hx-target="#article-banner-container" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<h3>Beschreibung</h3>
|
||||||
|
<textarea name="article-summary">{{.Article.Summary}}</textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<h3>Artikel</h3>
|
||||||
|
<textarea id="easyMDE">{{.Content}}</textarea>
|
||||||
|
<input id="article-content" name="article-content" type="hidden" value="{{.Content}}" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3>Tags</h3>
|
||||||
|
<div class="flex flex-wrap gap-4">
|
||||||
|
<div>
|
||||||
|
<input id="issue" name="issue" type="checkbox" {{if .Article.IsInIssue}}checked{{end}} />
|
||||||
|
<label for="issue">Orient Express</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{range .Tags}}
|
||||||
|
<div>
|
||||||
|
<input id="tag-{{.Name}}" name="tags" type="checkbox" value="{{.ID}}" {{if index $.Selected
|
||||||
|
.ID}}checked{{end}} />
|
||||||
|
<label for="tag-{{.Name}}">{{.Name}}</label>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3>Beteiligte</h3>
|
||||||
|
{{range .ArticleUsers}}
|
||||||
|
<div class="border border-slate-200 dark:border-slate-800 flex gap-4 px-2 py-1 rounded-md">
|
||||||
|
<span>{{.FirstName}} {{.LastName}}: </span>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<input id="{{.ID}}-author" name="user-{{.ID}}" type="radio" value="author" {{if eq .ArticleRole
|
||||||
|
1}}checked{{end}} />
|
||||||
|
<label for="{{.ID}}-author">Autor</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<input id="{{.ID}}-contributor" name="user-{{.ID}}" type="radio" value="contributor" {{if eq
|
||||||
|
.ArticleRole 2}}checked{{end}} />
|
||||||
|
<label for="{{.ID}}-contributor">Mitwirkender</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<input id="{{.ID}}-none" name="user-{{.ID}}" type="radio" {{if eq .ArticleRole 0}}checked{{end}} />
|
||||||
|
<label for="{{.ID}}-none">Unbeteiligt</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<input id="creator" name="creator" type="checkbox" value="author" {{if eq .Creator.ArticleRole
|
||||||
|
1}}checked{{end}} />
|
||||||
|
<label for="creator">Ich bin Autor.</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="btn-area">
|
||||||
|
<input class="action-btn" type="submit" value="Senden" hx-post="/article/{{.Action}}"
|
||||||
|
hx-target="#page-content" />
|
||||||
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var easyMDE = new EasyMDE({
|
||||||
|
element: document.getElementById('easyMDE'),
|
||||||
|
hideIcons: ['image'],
|
||||||
|
imageTexts: {sbInit: ''},
|
||||||
|
showIcons: ["code", "table", "upload-image"],
|
||||||
|
uploadImage: true,
|
||||||
|
|
||||||
|
imageUploadFunction: function (file, onSuccess, onError) {
|
||||||
|
var formData = new FormData();
|
||||||
|
formData.append('article-image', file);
|
||||||
|
|
||||||
|
fetch('/article/upload-image', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
onSuccess(data);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
htmx.trigger(htmx.find('#notification'), 'htmx:responseError', {xhr: {responseText: error.message}});
|
||||||
|
onError(error);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
easyMDE.codemirror.on("change", () => {
|
||||||
|
document.getElementById('article-content').value = easyMDE.value();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
{{define "article-banner-template"}}
|
||||||
|
<div id="article-banner-container">
|
||||||
|
<img src="/image/serve/{{.Image}}" alt="" />
|
||||||
|
<input id="article-banner-url" name="article-banner-url" type="hidden" value="{{.Image}}" />
|
||||||
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
{{define "page-content"}}
|
|
||||||
{{.}}
|
|
||||||
{{end}}
|
|
@ -1,17 +1,57 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<h2>Hub</h2>
|
<div class="flex flex-col gap-4">
|
||||||
<button hx-get="/write-article/" hx-target="#page-content">Artikel schreiben</button>
|
<button class="btn" hx-get="/logout" hx-target="#page-content">Abmelden</button>
|
||||||
<button hx-get="/rejected-articles/" hx-target="#page-content">Abgelehnte Artikel</button>
|
|
||||||
<button hx-get="/rss/" hx-target="#page-content">RSS Feed</button>
|
{{if lt .Role 4}}
|
||||||
<button hx-get="/edit-user/" hx-target="#page-content">Benutzer bearbeiten</button>
|
<div class="mb-3">
|
||||||
{{if lt . 3}}
|
<h2>Artikel</h2>
|
||||||
<button hx-get="/unpublished-articles/" hx-target="#page-content">Unveröffentlichte Artikel</button>
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2">
|
||||||
<button hx-get="/create-tag/" hx-target="#page-content">Neuer Tag</button>
|
<button class="btn" hx-get="/article/write" hx-target="#page-content">Artikel schreiben</button>
|
||||||
{{end}}
|
<form class="flex" hx-encoding="multipart/form-data">
|
||||||
{{if lt . 2}}
|
<label class="btn text-center" for="docx-upload">Word-Dokument hochladen</label>
|
||||||
<button hx-get="/this-issue/" hx-target="#page-content">Diese Ausgabe</button>
|
<input accept=".docx" class="hidden" id="docx-upload" name="docx-upload" type="file"
|
||||||
{{end}}
|
hx-post="/docx/upload" />
|
||||||
{{if eq . 0}}
|
</form>
|
||||||
<button hx-get="/create-user/" hx-target="#page-content">Benutzer hinzufügen</button>
|
<button class="btn" hx-get="/article/all-rejected" hx-target="#page-content">Artikel bearbeiten</button>
|
||||||
{{end}}
|
{{if lt .Role 3}}<button class="btn" hx-get="/article/all-unpublished-unrejected-and-published-rejected"
|
||||||
|
hx-target="#page-content">Artikel veröffentlichen</button>{{end}}
|
||||||
|
{{if lt .Role 2}}<button class="btn" hx-get="/article/all-published/delete"
|
||||||
|
hx-target="#page-content">Artikel löschen</button>{{end}}
|
||||||
|
{{if lt .Role 2}}<button class="btn" hx-get="/article/all-published/review-edit"
|
||||||
|
hx-target="#page-content">Artikel bearbeiten lassen</button>{{end}}
|
||||||
|
{{if lt .Role 3}}<button class="btn" hx-get="/tag/create" hx-target="#page-content">Neuer
|
||||||
|
Tag</button>{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
{{if lt .Role 2}}
|
||||||
|
<div class="mb-3">
|
||||||
|
<h2>Ausgabe</h2>
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2">
|
||||||
|
<button class="btn" hx-get="/issue/this" hx-target="#page-content">Diese Ausgabe</button>
|
||||||
|
<form class="flex" hx-encoding="multipart/form-data">
|
||||||
|
<label class="btn text-center" for="pdf-upload">PDF hochladen</label>
|
||||||
|
<input accept=".pdf" class="hidden" id="pdf-upload" name="pdf-upload" type="file"
|
||||||
|
hx-post="/pdf/upload" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{if lt .Role 4}}
|
||||||
|
<div class="mb-3">
|
||||||
|
<h2>Benutzer</h2>
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2">
|
||||||
|
<button class="btn" hx-get="/user/edit/self" hx-target="#page-content">Mein Profil bearbeiten</button>
|
||||||
|
{{if eq .Role 0}}<button class="btn" hx-get="/user/create" hx-target="#page-content">Benutzer
|
||||||
|
hinzufügen</button>{{end}}
|
||||||
|
{{if eq .Role 0}}<button class="btn" hx-get="/user/show-all/edit" hx-target="#page-content">Benutzer
|
||||||
|
bearbeiten</button>{{end}}
|
||||||
|
{{if eq .Role 0}}<button class="btn" hx-get="/user/show-all/delete" hx-target="#page-content">Benutzer
|
||||||
|
löschen</button>{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -5,26 +5,81 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>Orient Editor</title>
|
<title>Orient Editor</title>
|
||||||
<link href="web/static/css/style.css" rel="stylesheet">
|
|
||||||
|
<link href="/web/static/css/style.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://unpkg.com/easymde/dist/easymde.min.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body
|
||||||
<header>
|
class="bg-slate-50 dark:bg-slate-950 container flex flex-col justify-between max-w-screen-lg min-h-screen mx-auto text-slate-900 dark:text-slate-100">
|
||||||
<h1>Orient Editor</h1>
|
<header class="my-8">
|
||||||
<button hx-get="logout" hx-target="#page-content">Abmelden</button>
|
<h1 class="font-bold text-4xl text-center">Orient Editor</h1>
|
||||||
|
|
||||||
|
<div class="ml-4">
|
||||||
|
<label class="cursor-pointer flex items-center relative" for="theme-toggle">
|
||||||
|
<div class="bg-slate-200 dark:bg-slate-800 block h-6 w-12 rounded-full"></div>
|
||||||
|
<div
|
||||||
|
class="absolute bg-slate-800 dark:bg-slate-50 dot left-1 top-1 h-4 w-4 rounded-full transform transition">
|
||||||
|
</div>
|
||||||
|
<span class="ml-2">Dunkel</span>
|
||||||
|
</label>
|
||||||
|
<input type="checkbox" id="theme-toggle" class="sr-only">
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main>
|
<main class="mx-4">
|
||||||
|
<div class="hidden bg-slate-950 dark:bg-slate-50 fixed font-bold p-4 right-8 rounded-lg shadow-lg text-slate-100 dark:text-slate-900 top-8 z-50"
|
||||||
|
id="notification">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="page-content">
|
<div id="page-content">
|
||||||
{{template "page-content" .}}
|
{{template "page-content" .}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="web/static/js/htmx.min.js"></script>
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer>
|
<footer class="text-center text-gray-500 my-8">
|
||||||
<p>© 2024 Jason Streifling. Alle Rechte vorbehalten.</p>
|
<p>© 2024 Jason Streifling. Alle Rechte vorbehalten.</p>
|
||||||
|
<p>{{.Version}} - <strong>Alpha: Drastische Änderungen und Fehler vorbehalten.</strong></p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://unpkg.com/htmx.org@2.0.3"></script>
|
||||||
|
<script src="https://unpkg.com/easymde/dist/easymde.min.js"></script>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const toggleSwitch = document.getElementById('theme-toggle');
|
||||||
|
const dot = document.querySelector('.dot');
|
||||||
|
|
||||||
|
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
||||||
|
document.documentElement.classList.add('dark')
|
||||||
|
toggleSwitch.checked = true;
|
||||||
|
dot.classList.add('translate-x-6');
|
||||||
|
} else {
|
||||||
|
document.documentElement.classList.remove('dark')
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleSwitch.addEventListener('change', () => {
|
||||||
|
if (toggleSwitch.checked) {
|
||||||
|
document.documentElement.classList.add('dark');
|
||||||
|
localStorage.theme = 'dark';
|
||||||
|
dot.classList.add('translate-x-6');
|
||||||
|
} else {
|
||||||
|
document.documentElement.classList.remove('dark');
|
||||||
|
localStorage.theme = 'light';
|
||||||
|
dot.classList.remove('translate-x-6');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
htmx.on('htmx:responseError', function (event) {
|
||||||
|
var notification = document.getElementById('notification');
|
||||||
|
notification.innerText = event.detail.xhr.responseText;
|
||||||
|
notification.classList.remove('hidden');
|
||||||
|
setTimeout(function () {
|
||||||
|
notification.classList.add('hidden');
|
||||||
|
}, 5000);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<h2>Anmeldung</h2>
|
<h2>Anmeldung</h2>
|
||||||
|
|
||||||
<form>
|
<form>
|
||||||
<input name="username" placeholder="Benutzername" type="text" />
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 my-1">
|
||||||
<input name="password" placeholder="Passwort" type="password" />
|
<input class="w-full" name="username" placeholder="Benutzername" type="text" />
|
||||||
<input type="submit" value="Anmelden" hx-post="/login/" hx-target="#page-content" />
|
<input class="w-full" name="password" placeholder="Passwort" type="password" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-2">
|
||||||
|
<input class="action-btn" type="submit" value="Anmelden" hx-post="/login" hx-target="#page-content" />
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
14
web/templates/published-articles.html
Normal file
14
web/templates/published-articles.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{{define "page-content"}}
|
||||||
|
<h2>Artikel löschen</h2>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
{{range .Articles}}
|
||||||
|
<button class="btn" hx-get="/article/{{$.Action}}/{{.ID}}" hx-target="#page-content">
|
||||||
|
<h1 class="font-bold text-2xl">{{.Title}}</h1>
|
||||||
|
<p>{{.Summary}}</p>
|
||||||
|
</button>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
<button class="action-btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
@ -1,12 +1,16 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<form>
|
<h2>Artikel bearbeiten</h2>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
{{range .RejectedArticles}}
|
{{range .RejectedArticles}}
|
||||||
{{if index $.MyIDs .ID}}
|
{{if index $.MyIDs .ID}}
|
||||||
<input required id="{{.ID}}" name="id" type="radio" value="{{.ID}}" />
|
<button class="btn" hx-get="/article/review-rejected/{{.ID}}" hx-target="#page-content">
|
||||||
<label for="{{.ID}}">{{.Title}}</label>
|
<h1 class="font-bold text-2xl">{{.Title}}</h1>
|
||||||
|
<p>{{.Summary}}</p>
|
||||||
|
</button>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
<input type="submit" value="Auswählen" hx-post="/review-rejected-article/" hx-target="#page-content" />
|
|
||||||
</form>
|
<button class="action-btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
||||||
<button hx-get="/hub/" hx-target="#page-content">Zurück</button>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
70
web/templates/review-article.html
Normal file
70
web/templates/review-article.html
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
{{define "page-content"}}
|
||||||
|
<h2>{{.ActionTitle}}</h2>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="w-full" id="article-banner-container">
|
||||||
|
<img src="/image/serve/{{.Image}}" alt="Banner Image">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>Titel</h3>
|
||||||
|
<div class="border border-slate-200 dark:border-slate-800 mb-3 px-2 py-2 rounded-md w-full">
|
||||||
|
{{.Article.Title}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>Beschreibung</h3>
|
||||||
|
<div class="border border-slate-200 dark:border-slate-800 mb-3 px-2 py-2 rounded-md w-full">
|
||||||
|
{{.Article.Summary}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>Artikel</h3>
|
||||||
|
<div class="border border-slate-200 dark:border-slate-800 mb-3 px-2 py-2 rounded-md w-full">
|
||||||
|
<div class="prose text-slate-900 dark:text-slate-100">
|
||||||
|
{{.HTMLContent}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>Tags</h3>
|
||||||
|
<div class="border border-slate-200 dark:border-slate-800 mb-3 px-2 py-2 rounded-md w-full">
|
||||||
|
{{if .Article.IsInIssue}}
|
||||||
|
<span>Orient Express</span>
|
||||||
|
<br>
|
||||||
|
{{end}}
|
||||||
|
{{range .Tags}}
|
||||||
|
<span>{{.Name}}</span>
|
||||||
|
<br>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>Autoren</h3>
|
||||||
|
<div class="border border-slate-200 dark:border-slate-800 mb-3 px-2 py-2 rounded-md w-full">
|
||||||
|
{{range .Authors}}
|
||||||
|
<span>{{.FirstName}} {{.LastName}}</span>
|
||||||
|
<br>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>Mitwirkende</h3>
|
||||||
|
<div class="border border-slate-200 dark:border-slate-800 mb-3 px-2 py-2 rounded-md w-full">
|
||||||
|
{{range .Contributors}}
|
||||||
|
<span>{{.FirstName}} {{.LastName}}</span>
|
||||||
|
<br>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{if eq .Action "publish"}}
|
||||||
|
<div class="btn-area-3">
|
||||||
|
<input class="action-btn" type="submit" value="{{.ActionButton}}" hx-get="/article/{{.Action}}/{{.Article.ID}}"
|
||||||
|
hx-target="#page-content" />
|
||||||
|
<input class="btn" type="submit" value="Ablehnen" hx-get="/article/reject/{{.Article.ID}}"
|
||||||
|
hx-target="#page-content" />
|
||||||
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<div class="btn-area">
|
||||||
|
<input class="action-btn" type="submit" value="{{.ActionButton}}" hx-get="/article/{{.Action}}/{{.Article.ID}}"
|
||||||
|
hx-target="#page-content" />
|
||||||
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
{{end}}
|
@ -1,16 +0,0 @@
|
|||||||
{{define "page-content"}}
|
|
||||||
<h2>Editor</h2>
|
|
||||||
<form>
|
|
||||||
<input name="article-title" placeholder="Titel" type="text" value="{{.Article.Title}}" />
|
|
||||||
<textarea name="article-description" placeholder="Beschreibung">{{.Article.Description}}</textarea>
|
|
||||||
<textarea name="article-content" placeholder="Artikel">{{.Article.Content}}</textarea>
|
|
||||||
<input name="article-id" type="hidden" value="{{.Article.ID}}" />
|
|
||||||
|
|
||||||
{{range .Tags}}
|
|
||||||
<input id="tag-{{.Name}}" name="tags" type="checkbox" value="{{.ID}}" {{if index $.Selected .ID}}checked{{end}} />
|
|
||||||
<label for="tag-{{.Name}}">{{.Name}}</label>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
<input type="submit" value="Senden" hx-post="/resubmit-article/" hx-target="#page-content" />
|
|
||||||
</form>
|
|
||||||
{{end}}
|
|
24
web/templates/show-all-users.html
Normal file
24
web/templates/show-all-users.html
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{{define "page-content"}}
|
||||||
|
<h2>Alle Benutzer</h2>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
{{range .Users}}
|
||||||
|
<button class="btn" hx-get="/user/{{$.Action}}/{{.ID}}" hx-target="#page-content">
|
||||||
|
<h1 class="font-bold text-2xl">
|
||||||
|
{{.UserName}}
|
||||||
|
({{if eq .Role 0}}
|
||||||
|
Administrator
|
||||||
|
{{else if eq .Role 1}}
|
||||||
|
Herausgeber
|
||||||
|
{{else if eq .Role 2}}
|
||||||
|
Redakteur
|
||||||
|
{{else}}
|
||||||
|
Autor
|
||||||
|
{{end}})
|
||||||
|
</h1>
|
||||||
|
<p>{{.FirstName}} {{.LastName}}</p>
|
||||||
|
</button>
|
||||||
|
{{end}}
|
||||||
|
<button class="action-btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
@ -1,19 +0,0 @@
|
|||||||
{{define "page-content"}}
|
|
||||||
<form>
|
|
||||||
<h2>{{.Article.Title}}</h2>
|
|
||||||
<p>{{.Article.Description}}</p>
|
|
||||||
{{.Article.Content}}
|
|
||||||
|
|
||||||
<p>
|
|
||||||
{{range .Tags}}
|
|
||||||
{{.Name}}
|
|
||||||
{{end}}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<input name="id" type="hidden" value="{{.Article.ID}}" />
|
|
||||||
<input type="submit" value="Veröffentlichen" hx-post="/publish-article/" hx-target="#page-content" />
|
|
||||||
<input type="submit" value="Ablehnen" hx-post="/reject-article/" hx-target="#page-content" />
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<button hx-get="/hub/" hx-target="#page-content">Zurück</button>
|
|
||||||
{{end}}
|
|
@ -1,10 +1,13 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<form>
|
<h2>Artikel veröffentlichen</h2>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<input required id="{{.ID}}" name="id" type="radio" value="{{.ID}}" />
|
<button class="btn" hx-get="/article/review-unpublished/{{.ID}}" hx-target="#page-content">
|
||||||
<label for="{{.ID}}">{{.Title}}</label>
|
<h1 class="font-bold text-2xl">{{.Title}}</h1>
|
||||||
|
<p>{{.Summary}}</p>
|
||||||
|
</button>
|
||||||
{{end}}
|
{{end}}
|
||||||
<input type="submit" value="Auswählen" hx-post="/review-unpublished-article/" hx-target="#page-content" />
|
<button class="action-btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
||||||
</form>
|
</div>
|
||||||
<button hx-get="/hub/" hx-target="#page-content">Zurück</button>
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user