User session fixes

This commit is contained in:
Magnus Åhall 2024-01-05 21:14:55 +01:00
parent 52fba2289e
commit afa113b8b7
5 changed files with 11 additions and 42 deletions

35
db.go
View File

@ -1,35 +0,0 @@
package main
import (
// External
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
// Standard
"fmt"
)
var (
dbConn string
db *sqlx.DB
)
func dbInit() (err error) { // {{{
dbConn = fmt.Sprintf(
"host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
config.Database.Host,
config.Database.Port,
config.Database.Username,
config.Database.Password,
config.Database.Name,
)
logger.Info("db", "op", "connect", "host", config.Database.Host, "port", config.Database.Port)
if db, err = sqlx.Connect("postgres", dbConn); err != nil {
return
}
return
} // }}}
// vim: foldmethod=marker

View File

@ -172,6 +172,7 @@ func userPassword(w http.ResponseWriter, r *http.Request) { // {{{
*/ */
func nodeTree(w http.ResponseWriter, r *http.Request, sess *session.T) { // {{{ func nodeTree(w http.ResponseWriter, r *http.Request, sess *session.T) { // {{{
logger.Info("webserver", "request", "/node/tree")
var err error var err error
req := struct{ StartNodeID int }{} req := struct{ StartNodeID int }{}
@ -192,8 +193,8 @@ func nodeTree(w http.ResponseWriter, r *http.Request, sess *session.T) { // {{{
}) })
} // }}} } // }}}
func nodeRetrieve(w http.ResponseWriter, r *http.Request, sess *session.T) { // {{{ func nodeRetrieve(w http.ResponseWriter, r *http.Request, sess *session.T) { // {{{
var err error
logger.Info("webserver", "request", "/node/retrieve") logger.Info("webserver", "request", "/node/retrieve")
var err error
req := struct{ ID int }{} req := struct{ ID int }{}
if err = parseRequest(r, &req); err != nil { if err = parseRequest(r, &req); err != nil {

View File

@ -79,6 +79,9 @@ func NodeTree(userID, startNodeID int) (nodes []Node, err error) {// {{{
for rows.Next() { for rows.Next() {
node := Node{} node := Node{}
node.Complete = false node.Complete = false
node.Crumbs = []Node{}
node.Children = []Node{}
node.Files = []File{}
if err = rows.StructScan(&node); err != nil { if err = rows.StructScan(&node); err != nil {
return return
} }
@ -385,7 +388,7 @@ func SearchNodes(userID int, search string) (nodes []Node, err error) {// {{{
updated updated
FROM node FROM node
WHERE WHERE
user_id = $1 user_id = $1 AND
crypto_key_id IS NULL AND crypto_key_id IS NULL AND
( (
content ~* $2 OR content ~* $2 OR

View File

@ -25,7 +25,7 @@ class App extends Component {
this.startNode = null this.startNode = null
//this.setStartNode() this.setStartNode()
}//}}} }//}}}
render() {//{{{ render() {//{{{
let app_el = document.getElementById('app') let app_el = document.getElementById('app')

View File

@ -1,10 +1,10 @@
export class Session { export class Session {
constructor(app) { constructor(app) {//{{{
this.app = app this.app = app
this.UUID = '' this.UUID = ''
this.initialized = false this.initialized = false
this.UserID = 0 this.UserID = 0
} }//}}}
initialize() {//{{{ initialize() {//{{{
// Retrieving the stored session UUID, if any. // Retrieving the stored session UUID, if any.
@ -29,7 +29,7 @@ export class Session {
if (res.Error === undefined) { if (res.Error === undefined) {
// Session exists on server. // Session exists on server.
// Not necessarily authenticated. // Not necessarily authenticated.
this.UserID = res.UserID // could be 0 this.UserID = res.Session.UserID // could be 0
this.initialized = true this.initialized = true
this.app.forceUpdate() this.app.forceUpdate()
} else { } else {
@ -58,7 +58,7 @@ export class Session {
}) })
.then(res => { .then(res => {
if (res.Authenticated) { if (res.Authenticated) {
this.UserID = res.Session.UserID this.UserID = res.UserID
this.app.forceUpdate() this.app.forceUpdate()
} else { } else {
this.app.login.current.authentication_failed.value = true this.app.login.current.authentication_failed.value = true