mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-26 18:20:57 +00:00
[GITEA] Fix session generation for database
- If the session doesn't exist, it shouldn't be expected that the
variable is non-nil. Define the session variable instead and insert that.
- Add unit tests to test the behavior of the database sessions code .
- Regression caused by dd30d9d5c0
.
- Resolves https://codeberg.org/forgejo/forgejo/issues/2042
This commit is contained in:
parent
d9dab91cec
commit
90307ad200
2 changed files with 147 additions and 2 deletions
|
@ -45,8 +45,11 @@ func ReadSession(ctx context.Context, key string) (*Session, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
} else if !exist {
|
||||
session.Expiry = timeutil.TimeStampNow()
|
||||
if err := db.Insert(ctx, &session); err != nil {
|
||||
session = &Session{
|
||||
Key: key,
|
||||
Expiry: timeutil.TimeStampNow(),
|
||||
}
|
||||
if err := db.Insert(ctx, session); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue