Commiting changes long overdue
This commit is contained in:
parent
8cc411b89d
commit
3fbcfdcb5d
67
assets.go
67
assets.go
@ -475,40 +475,57 @@ ZfY39XJelrPeb2dTP1e8O5VLPwIAAP//0xnP9ywDAAA=
|
|||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"/templates/rss_feed.xml": {
|
||||||
|
local: "templates/rss_feed.xml",
|
||||||
|
size: 700,
|
||||||
|
modtime: 1547486966,
|
||||||
|
compressed: `
|
||||||
|
H4sIAAAAAAAC/2xSTY+bMBC951dMEbdt7bTqaev1alvUU9VDlZyiHAyeEivGIH/QShb/fQUG8qGcsGfe
|
||||||
|
e543D/b6v9HQo3WqNS/ZZ7LNXvmGWecuxS9km/ENAKtOwhjU4xmAeeU18j+qLJWHn4iS0VRKba3MmZ+8
|
||||||
|
754ptROIlEFrtFUr8V9rz45UbUNRKk9jJDtsOi08FsILsndoyT4oOQyMTkJJU6KrrOq8ag0fX4S/rYXH
|
||||||
|
ZIfWiAZHgWvWPJswdRA1cjSfgmN0vS9t578HpWUhPPJ7/bUzDXcDnRfjNf+6ZXT8TpUYwQpTI+TqI+Q9
|
||||||
|
PL/AreToxcEwJP6Hw4/ibfd2yOAJ8p4Ul/HhCbLjkWcJpzw26YE1jRjznvyefV+lAcC6UM528p78Es7v
|
||||||
|
OzmbWFoLtA5KJpxrg61wGL6lmw71cr5VmBgLfQrsOre75Cb+6OpxOPTiK0ZAI9NiGF1/P0atc3zzHgAA
|
||||||
|
//+UZXAKvAIAAA==
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
|
||||||
"/templates/user_dashboard.html": {
|
"/templates/user_dashboard.html": {
|
||||||
local: "templates/user_dashboard.html",
|
local: "templates/user_dashboard.html",
|
||||||
size: 45,
|
size: 97,
|
||||||
modtime: 1547160534,
|
modtime: 1547486320,
|
||||||
compressed: `
|
compressed: `
|
||||||
H4sIAAAAAAAC/7JJVMgoSk2zVdIvLU4t0k9LTU0pVrJzTcksUQguTSpOLsosKMnMzyu20U+04wIEAAD/
|
H4sIAAAAAAAC/7JJVMgoSk2zVdIvLU4t0k9LTU0pVrJzTcksUQguTSpOLsosKMnMzyu20U+04+JCqC4q
|
||||||
/2HSavctAAAA
|
LtavrtYLSc0tyEksSXVJLEnUCy3NTKmtVbILCg5WcEtNTQHrAQQAAP//EcPbEmEAAAA=
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
"/templates/user_feeds.html": {
|
"/templates/user_feeds.html": {
|
||||||
local: "templates/user_feeds.html",
|
local: "templates/user_feeds.html",
|
||||||
size: 3588,
|
size: 4065,
|
||||||
modtime: 1547234296,
|
modtime: 1547235825,
|
||||||
compressed: `
|
compressed: `
|
||||||
H4sIAAAAAAAC/5xXXY/aOBe+z6+wrLkIGia0t4UgtdP3lSpVu9JC92aEkIkPiTXGjmwHZjTiv69sJ9ih
|
H4sIAAAAAAAC/5xX3W7bNhS+11MQRC5kxJHbXdaWgTbdgALFBszpbgLPoMVjiyhNCiRlJwj87gNJyaQU
|
||||||
IWL3ApT4POf7wycLyo6I0RwTzrdaNqoAvS2kMIQJUHi5mFF2XCaLvVQHJMgBcrwHoFvd7HShWG2YFBoj
|
WfN2kcDS+c4Pv/PDowVlR8RojgnnGy1rVYDeFFIYwgQovFzMKDsuk8VOqgMS5AA53gHQja63ulCsMkwK
|
||||||
UtiHHM8aDWrW1JQY6EOWCUILJurGOHUWt7WSNEbmvYYcV4xSELhVEtOPhDeQY4xmTsiuMUaKlks3uwMz
|
jREp7I8cz2oNalZXlBjoQaTQ9fbATI69eBWJ/yK8hnSClwlCCyaq2riYrLGNdacxMq8V5LhklILATSSx
|
||||||
eLkiR1jMPGmZLGbW3mWy8AYskyNRKIhEOXpJPj6QIqIE9MCm6OGIvuQoW8Oh5sTAd2JI9kuDylbNbsWb
|
/GhN5BijmTOyrY2RotHyjvFyRY6wmHnRMlnM7KGWycKHsUyORKFgEuXoOXl7Q4qIPaA7NkV3R/QpR9kT
|
||||||
UqPzOU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KJQ8RW8t6JIcuxremMsW2mmHEK9bMtc9d63OxZ9dNm/010Kv
|
||||||
8sijgWEexl6wOnDYkTzvhr6SpzDabeqDD/rb+5qU9lK8zLKXT5uBLu1Gexyum1F1ym5GLPo0mmTu2wjl
|
+GvW1r7HVuvisa7ojQ4b5BV/8Zrad9poerJ9Pyp56vbgQAHZFPvUDteIl8cFEIF0xVkBV9Wm6KOvwHiq
|
||||||
kbMuJX5nnic3gzZPFrPu4+ifAAAA//9hEtQ2BA4AAA==
|
RWC3UTpkWz9XP8e659iDWdVbO0JC+M2Zr67WSp42+N7iMwUVJwWkeI6neOPa5ByMv4/BL5HezcCtG51o
|
||||||
|
4NoNYy1EHTTs5TlvbxIlT+GqsKkNZ9BfXp/I3q4vl1n1/GE90IXtJRzTdZVV5+wqY9En7SRz37Qojw7r
|
||||||
|
UuK/debJVdLmyWLWftT+EwAA///sH8RP4Q8AAA==
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleRequest(w http.ResponseWriter, req *http.Request) {
|
func handleRequest(w http.ResponseWriter, req *http.Request) {
|
||||||
@ -19,24 +16,3 @@ func handleRequest(w http.ResponseWriter, req *http.Request) {
|
|||||||
handleUserLoginForm(page)
|
handleUserLoginForm(page)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleRssFeed(w http.ResponseWriter, req *http.Request) {
|
|
||||||
vars := mux.Vars(req)
|
|
||||||
var uid string
|
|
||||||
var uidOk bool
|
|
||||||
if uid, uidOk = vars["uid"]; !uidOk {
|
|
||||||
userError(w)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.Header().Set("Content-Type", "application/xml")
|
|
||||||
v, err := buildRssFeed(uid)
|
|
||||||
if err != nil {
|
|
||||||
userError(w)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Fprint(w, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func buildRssFeed(uid string) (string, error) {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
73
endpoints_rss.go
Normal file
73
endpoints_rss.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
)
|
||||||
|
|
||||||
|
func handleRssFeed(w http.ResponseWriter, req *http.Request) {
|
||||||
|
page := initPageData(w, req)
|
||||||
|
|
||||||
|
vars := mux.Vars(req)
|
||||||
|
var uid string
|
||||||
|
var uidOk bool
|
||||||
|
if uid, uidOk = vars["uid"]; !uidOk {
|
||||||
|
userError(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Type", "application/xml")
|
||||||
|
var slug string
|
||||||
|
var slugOk bool
|
||||||
|
slug, slugOk = vars["slug"]
|
||||||
|
if !slugOk {
|
||||||
|
// Print the user's entire feed
|
||||||
|
buildUserRssFeed(page, uid)
|
||||||
|
} else {
|
||||||
|
// Print the feed for a specific slug
|
||||||
|
buildSlugRssFeed(page, uid, slug)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type rssPageData struct {
|
||||||
|
User *User
|
||||||
|
Feeds []Feed
|
||||||
|
BuildDate time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildUserRssFeed(page *pageData, uid string) {
|
||||||
|
var err error
|
||||||
|
rpd := new(rssPageData)
|
||||||
|
rpd.BuildDate = time.Now()
|
||||||
|
rpd.User, err = m.GetUser(uid)
|
||||||
|
if err != nil {
|
||||||
|
userError(page.session.w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, v := range rpd.User.SubSlugs {
|
||||||
|
pts := strings.Split(v, ";")
|
||||||
|
fd, err := m.GetFeed(pts[0], pts[1])
|
||||||
|
if err != nil {
|
||||||
|
userError(page.session.w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rpd.Feeds = append(rpd.Feeds, *fd)
|
||||||
|
}
|
||||||
|
page.TemplateData = rpd
|
||||||
|
page.showRss()
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildSlugRssFeed(page *pageData, uid, slug string) {
|
||||||
|
var err error
|
||||||
|
rpd := new(rssPageData)
|
||||||
|
rpd.BuildDate = time.Now()
|
||||||
|
rpd.User, err = m.GetUser(uid)
|
||||||
|
if err != nil {
|
||||||
|
userError(page.session.w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
page.TemplateData = rpd
|
||||||
|
page.showRss()
|
||||||
|
}
|
@ -75,6 +75,17 @@ func doLogin(uid, password string) error {
|
|||||||
|
|
||||||
func handleUserDashboard(page *pageData) {
|
func handleUserDashboard(page *pageData) {
|
||||||
page.SubTitle = "dashboard"
|
page.SubTitle = "dashboard"
|
||||||
|
var err error
|
||||||
|
id, err := page.session.getStringValue("id")
|
||||||
|
if err != nil {
|
||||||
|
userError(page.session.w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
page.TemplateData, err = m.GetUser(id)
|
||||||
|
if err != nil {
|
||||||
|
userError(page.session.w)
|
||||||
|
return
|
||||||
|
}
|
||||||
page.show("user_dashboard.html")
|
page.show("user_dashboard.html")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +131,11 @@ func handleUpdateUserSubs(page *pageData) {
|
|||||||
u, err = m.GetUser(id)
|
u, err = m.GetUser(id)
|
||||||
u.SubSlugs = userSubs
|
u.SubSlugs = userSubs
|
||||||
m.SaveUser(u)
|
m.SaveUser(u)
|
||||||
|
for k := range m.Users {
|
||||||
|
if m.Users[k].Uuid == id {
|
||||||
|
m.Users[k].SubSlugs = userSubs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
redirect("/user/dashboard", page.session.w, page.session.req)
|
redirect("/user/dashboard", page.session.w, page.session.req)
|
||||||
}
|
}
|
||||||
|
1
main.go
1
main.go
@ -72,6 +72,7 @@ func main() {
|
|||||||
pub.HandleFunc("/api/comics/{cid}/{function}", handleApiComicsCall)
|
pub.HandleFunc("/api/comics/{cid}/{function}", handleApiComicsCall)
|
||||||
*/
|
*/
|
||||||
pub.HandleFunc("/rss/{uid}", handleRssFeed)
|
pub.HandleFunc("/rss/{uid}", handleRssFeed)
|
||||||
|
pub.HandleFunc("/rss/{uid}/{slug}", handleRssFeed)
|
||||||
pub.HandleFunc("/user/{function}", handleUserRequest)
|
pub.HandleFunc("/user/{function}", handleUserRequest)
|
||||||
|
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
|
30
model.go
30
model.go
@ -10,8 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
|
dbOpen int
|
||||||
bolt *boltease.DB
|
bolt *boltease.DB
|
||||||
dbFileName string
|
dbFileName string
|
||||||
|
dbChanged bool
|
||||||
|
|
||||||
Users []User
|
Users []User
|
||||||
FeedSources []FeedSource
|
FeedSources []FeedSource
|
||||||
@ -48,10 +50,10 @@ func NewModel() (*model, error) {
|
|||||||
|
|
||||||
func (m *model) initDB() error {
|
func (m *model) initDB() error {
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
|
|
||||||
if err = m.bolt.MkBucketPath([]string{"site"}); err != nil {
|
if err = m.bolt.MkBucketPath([]string{"site"}); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -65,9 +67,31 @@ func (m *model) initDB() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *model) openDB() error {
|
||||||
|
m.dbOpen = m.dbOpen + 1
|
||||||
|
if m.dbOpen > 1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
if err = m.openDB(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *model) closeDB() {
|
||||||
|
m.dbOpen = m.dbOpen - 1
|
||||||
|
if m.dbOpen == 0 {
|
||||||
|
m.closeDB()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (m *model) saveChanges() {
|
func (m *model) saveChanges() {
|
||||||
|
fmt.Println("Saving Site to DB")
|
||||||
m.Site.SaveToDB()
|
m.Site.SaveToDB()
|
||||||
//m.SaveAllFeeds(m.Feeds)
|
//fmt.Println("Saving Feeds to DB")
|
||||||
|
//m.SaveAllFeeds(m.FeedSources)
|
||||||
|
fmt.Println("Saving Users to DB")
|
||||||
m.SaveAllUsers(m.Users)
|
m.SaveAllUsers(m.Users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"plugin"
|
"plugin"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -91,7 +92,7 @@ func NewFeed(s, n, a, source string) *Feed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Feed) GetBucket() []string {
|
func (f *Feed) GetBucket() []string {
|
||||||
return []string{"feed", f.Source, f.Slug}
|
return []string{"feeds", f.Source, f.Slug}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Feed) Update() error {
|
func (f *Feed) Update() error {
|
||||||
@ -146,10 +147,10 @@ func (f *Feed) GetRssItem() string {
|
|||||||
// DB Function to save a feed
|
// DB Function to save a feed
|
||||||
func (m *model) SaveFeed(f *Feed) error {
|
func (m *model) SaveFeed(f *Feed) error {
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
bkt := f.GetBucket()
|
bkt := f.GetBucket()
|
||||||
if err = m.bolt.MkBucketPath(bkt); err != nil {
|
if err = m.bolt.MkBucketPath(bkt); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -180,10 +181,10 @@ func (m *model) SaveFeed(f *Feed) error {
|
|||||||
// DB Function to get a feed
|
// DB Function to get a feed
|
||||||
func (m *model) GetFeed(source, slug string) (*Feed, error) {
|
func (m *model) GetFeed(source, slug string) (*Feed, error) {
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
ret := new(Feed)
|
ret := new(Feed)
|
||||||
ret.Source = source
|
ret.Source = source
|
||||||
ret.Slug = slug
|
ret.Slug = slug
|
||||||
@ -210,14 +211,17 @@ func (m *model) LoadFeeds() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save all feeds to the DB
|
// Save all feeds to the DB
|
||||||
func (m *model) SaveAllFeeds(feeds []Feed) {
|
func (m *model) SaveAllFeeds(feedSources []FeedSource) {
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
for i := range feeds {
|
for _, v := range feedSources {
|
||||||
m.SaveFeed(&feeds[i])
|
for j := range v.Feeds {
|
||||||
|
fmt.Printf("Saving Feed to DB (%s;%s)\n", v.Feeds[j].Source, v.Feeds[j].Slug)
|
||||||
|
m.SaveFeed(v.Feeds[j])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,10 +229,10 @@ func (m *model) SaveAllFeeds(feeds []Feed) {
|
|||||||
func (m *model) GetAllFeeds() []Feed {
|
func (m *model) GetAllFeeds() []Feed {
|
||||||
var ret []Feed
|
var ret []Feed
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
var srcs []string
|
var srcs []string
|
||||||
bkt := []string{"feeds"}
|
bkt := []string{"feeds"}
|
||||||
if srcs, err = m.bolt.GetBucketList(bkt); err != nil {
|
if srcs, err = m.bolt.GetBucketList(bkt); err != nil {
|
||||||
@ -253,10 +257,10 @@ func (m *model) GetAllFeeds() []Feed {
|
|||||||
// Delete a feed from the DB
|
// Delete a feed from the DB
|
||||||
func (m *model) DeleteFeed(slug string) error {
|
func (m *model) DeleteFeed(slug string) error {
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
|
|
||||||
return m.bolt.DeleteBucket([]string{"feeds"}, slug)
|
return m.bolt.DeleteBucket([]string{"feeds"}, slug)
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,10 @@ func NewSiteData(m *model) *SiteData {
|
|||||||
// load the site data out of the database
|
// load the site data out of the database
|
||||||
// If fields don't exist in the DB, don't clobber what is already in s
|
// If fields don't exist in the DB, don't clobber what is already in s
|
||||||
func (s *SiteData) LoadFromDB() error {
|
func (s *SiteData) LoadFromDB() error {
|
||||||
if err := s.m.bolt.OpenDB(); err != nil {
|
if err := s.m.openDB(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer s.m.bolt.CloseDB()
|
defer s.m.closeDB()
|
||||||
|
|
||||||
if title, _ := s.m.bolt.GetValue(s.mPath, "title"); strings.TrimSpace(title) != "" {
|
if title, _ := s.m.bolt.GetValue(s.mPath, "title"); strings.TrimSpace(title) != "" {
|
||||||
s.Title = title
|
s.Title = title
|
||||||
@ -78,10 +78,10 @@ func (s *SiteData) NeedsSave() bool {
|
|||||||
func (s *SiteData) SaveToDB() error {
|
func (s *SiteData) SaveToDB() error {
|
||||||
s.lastSave = time.Now()
|
s.lastSave = time.Now()
|
||||||
var err error
|
var err error
|
||||||
if err = s.m.bolt.OpenDB(); err != nil {
|
if err = s.m.openDB(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer s.m.bolt.CloseDB()
|
defer s.m.closeDB()
|
||||||
|
|
||||||
if err = s.m.bolt.SetValue(s.mPath, "title", s.Title); err != nil {
|
if err = s.m.bolt.SetValue(s.mPath, "title", s.Title); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -40,10 +40,10 @@ func (u *User) UpdateFeed() error {
|
|||||||
|
|
||||||
func (m *model) SaveUser(u *User) error {
|
func (m *model) SaveUser(u *User) error {
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
bkt := []string{"users", u.Uuid}
|
bkt := []string{"users", u.Uuid}
|
||||||
if err = m.bolt.MkBucketPath(bkt); err != nil {
|
if err = m.bolt.MkBucketPath(bkt); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -73,10 +73,10 @@ func (m *model) SaveUser(u *User) error {
|
|||||||
|
|
||||||
func (m *model) isValidUser(uid string) bool {
|
func (m *model) isValidUser(uid string) bool {
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
ret := new(User)
|
ret := new(User)
|
||||||
bkt := []string{"users", uid}
|
bkt := []string{"users", uid}
|
||||||
ret.Uuid = uid
|
ret.Uuid = uid
|
||||||
@ -105,10 +105,10 @@ func (m *model) GetUser(uid string) (*User, error) {
|
|||||||
return nil, errors.New("No user id given")
|
return nil, errors.New("No user id given")
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
ret := new(User)
|
ret := new(User)
|
||||||
bkt := []string{"users", uid}
|
bkt := []string{"users", uid}
|
||||||
ret.Uuid = uid
|
ret.Uuid = uid
|
||||||
@ -128,10 +128,10 @@ func (m *model) GetUser(uid string) (*User, error) {
|
|||||||
|
|
||||||
func (m *model) SaveAllUsers(users []User) {
|
func (m *model) SaveAllUsers(users []User) {
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
for i := range users {
|
for i := range users {
|
||||||
m.SaveUser(&users[i])
|
m.SaveUser(&users[i])
|
||||||
}
|
}
|
||||||
@ -145,10 +145,10 @@ func (m *model) LoadUsers() error {
|
|||||||
func (m *model) GetAllUsers() []User {
|
func (m *model) GetAllUsers() []User {
|
||||||
var err error
|
var err error
|
||||||
var ret []User
|
var ret []User
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
|
|
||||||
uids := m.GetUserIdList()
|
uids := m.GetUserIdList()
|
||||||
for _, uid := range uids {
|
for _, uid := range uids {
|
||||||
@ -161,10 +161,10 @@ func (m *model) GetAllUsers() []User {
|
|||||||
|
|
||||||
func (m *model) GetUserByName(nm string) (*User, error) {
|
func (m *model) GetUserByName(nm string) (*User, error) {
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
usrids := m.GetUserIdList()
|
usrids := m.GetUserIdList()
|
||||||
for i := range usrids {
|
for i := range usrids {
|
||||||
bkt := []string{"users", usrids[i]}
|
bkt := []string{"users", usrids[i]}
|
||||||
@ -180,10 +180,10 @@ func (m *model) GetUserByName(nm string) (*User, error) {
|
|||||||
func (m *model) GetUserIdList() []string {
|
func (m *model) GetUserIdList() []string {
|
||||||
var ret []string
|
var ret []string
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
bkt := []string{"users"}
|
bkt := []string{"users"}
|
||||||
ret, _ = m.bolt.GetBucketList(bkt)
|
ret, _ = m.bolt.GetBucketList(bkt)
|
||||||
return ret
|
return ret
|
||||||
@ -201,10 +201,10 @@ func (m *model) updateUserPassword(uid, password string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.bolt.OpenDB(); err != nil {
|
if err := m.openDB(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
|
|
||||||
usrPath := []string{"users", uid}
|
usrPath := []string{"users", uid}
|
||||||
return m.bolt.SetValue(usrPath, "password", string(cryptPw))
|
return m.bolt.SetValue(usrPath, "password", string(cryptPw))
|
||||||
@ -213,10 +213,10 @@ func (m *model) updateUserPassword(uid, password string) error {
|
|||||||
// Is the uid and pw given valid?
|
// Is the uid and pw given valid?
|
||||||
func (m *model) checkCredentials(uid, pw string) error {
|
func (m *model) checkCredentials(uid, pw string) error {
|
||||||
var err error
|
var err error
|
||||||
if err = m.bolt.OpenDB(); err != nil {
|
if err = m.openDB(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer m.bolt.CloseDB()
|
defer m.closeDB()
|
||||||
|
|
||||||
var uPw string
|
var uPw string
|
||||||
usrPath := []string{"users", uid}
|
usrPath := []string{"users", uid}
|
||||||
|
@ -38,3 +38,11 @@ func (p *pageData) show(tmplName string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *pageData) showRss() error {
|
||||||
|
if err := outputTemplate("rss_feed.xml", p, p.session.w); err != nil {
|
||||||
|
fmt.Printf("%s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
20
templates/rss_feed.xml
Normal file
20
templates/rss_feed.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<rss version="2.0">
|
||||||
|
<channel>
|
||||||
|
<title>Ribbit Feed</title>
|
||||||
|
<link>http://ribbit.bullercodeworks.com/edit/{{.TemplateData.User.Uuid}}</link>
|
||||||
|
<description>Feed for {{.TemplateData.User.Username}}</description>
|
||||||
|
<language>en-us</language>
|
||||||
|
<lastBuildDate>{{.TemplateData.BuildDate}}</lastBuildDate>
|
||||||
|
<ttl>40</ttl>
|
||||||
|
{{ range $i, $v := .TemplateData.Feeds }}
|
||||||
|
<item>
|
||||||
|
<title>{{$v.Name}}</title>
|
||||||
|
<pubDate>{{$v.LastUpdate}}</pubDate>
|
||||||
|
<guid>{{$v.Source}};{{$v.Slug}};{{$v.LastUpdate}}</guid>
|
||||||
|
<link></link>
|
||||||
|
<description><![CDATA[{{$v.Desc}}]]></description>
|
||||||
|
</item>
|
||||||
|
{{ end }}
|
||||||
|
</channel>
|
||||||
|
</rss>
|
@ -1 +1,3 @@
|
|||||||
<a href="/user/feeds">Edit Subscriptions</a>
|
<a href="/user/feeds">Edit Subscriptions</a>
|
||||||
|
|
||||||
|
<a href="/rss/{{.TemplateData.Uuid}}">RSS Feed</a>
|
||||||
|
Loading…
Reference in New Issue
Block a user