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) { // {{{
logger.Info("webserver", "request", "/node/tree")
var err error
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) { // {{{
var err error
logger.Info("webserver", "request", "/node/retrieve")
var err error
req := struct{ ID int }{}
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() {
node := Node{}
node.Complete = false
node.Crumbs = []Node{}
node.Children = []Node{}
node.Files = []File{}
if err = rows.StructScan(&node); err != nil {
return
}
@ -385,7 +388,7 @@ func SearchNodes(userID int, search string) (nodes []Node, err error) {// {{{
updated
FROM node
WHERE
user_id = $1
user_id = $1 AND
crypto_key_id IS NULL AND
(
content ~* $2 OR

View File

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

View File

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