store only UID in session vars, not complete user
This commit is contained in:
+1
-7
@@ -10,7 +10,6 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -35,11 +34,6 @@ type User struct {
|
|||||||
DOB *time.Time `db:"dob"`
|
DOB *time.Time `db:"dob"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// init registers data types from this module.
|
|
||||||
func init() {
|
|
||||||
gob.Register(User{})
|
|
||||||
}
|
|
||||||
|
|
||||||
/* AmGetUser returns a reference to the specified user.
|
/* AmGetUser returns a reference to the specified user.
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* uid - The UID of the user.
|
* uid - The UID of the user.
|
||||||
@@ -59,7 +53,7 @@ func AmGetUser(uid int32) (*User, error) {
|
|||||||
return &(rc[0]), err
|
return &(rc[0]), err
|
||||||
}
|
}
|
||||||
|
|
||||||
/* AmGetAmonUser returns a reference to the anonymous user.
|
/* AmGetAnonUser returns a reference to the anonymous user.
|
||||||
* Returns:
|
* Returns:
|
||||||
* Pointer to User containing anonymous user data, or nil
|
* Pointer to User containing anonymous user data, or nil
|
||||||
* Standard Go error status
|
* Standard Go error status
|
||||||
|
|||||||
+5
-1
@@ -49,7 +49,11 @@ type amContext struct {
|
|||||||
|
|
||||||
// CurrentUser returns the current user from the session.
|
// CurrentUser returns the current user from the session.
|
||||||
func (c *amContext) CurrentUser() *database.User {
|
func (c *amContext) CurrentUser() *database.User {
|
||||||
return c.session.Values["user"].(*database.User)
|
u, err := database.AmGetUser(c.session.Values["user_id"].(int32))
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("unable to retrieve current user")
|
||||||
|
}
|
||||||
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
// RC returns the HTTP result code for the current operation.
|
// RC returns the HTTP result code for the current operation.
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ func SetupAmSession(session *sessions.Session) {
|
|||||||
session.Values["temp"] = "Active"
|
session.Values["temp"] = "Active"
|
||||||
u, err := database.AmGetAnonUser()
|
u, err := database.AmGetAnonUser()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
session.Values["user"] = u
|
session.Values["user_id"] = u.Uid
|
||||||
} else {
|
} else {
|
||||||
log.Errorf("Unable to load anon user: %v", err)
|
log.Errorf("Unable to load anon user: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user