mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
common errors as variable.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@ -39,16 +39,16 @@ func (manager *SessionManagerCtx) CookieClearToken(w http.ResponseWriter, r *htt
|
||||
func (manager *SessionManagerCtx) Authenticate(r *http.Request) (types.Session, error) {
|
||||
token, ok := manager.getToken(r)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no authentication provided")
|
||||
return nil, errors.New("no authentication provided")
|
||||
}
|
||||
|
||||
session, ok := manager.GetByToken(token)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("session not found")
|
||||
return nil, types.ErrSessionNotFound
|
||||
}
|
||||
|
||||
if !session.Profile().CanLogin {
|
||||
return nil, fmt.Errorf("login disabled")
|
||||
return nil, types.ErrSessionLoginDisabled
|
||||
}
|
||||
|
||||
return session, nil
|
||||
|
@ -1,7 +1,7 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/kataras/go-events"
|
||||
@ -68,12 +68,12 @@ func (manager *SessionManagerCtx) Create(id string, profile types.MemberProfile)
|
||||
manager.sessionsMu.Lock()
|
||||
if _, ok := manager.sessions[id]; ok {
|
||||
manager.sessionsMu.Unlock()
|
||||
return nil, "", fmt.Errorf("session id already exists")
|
||||
return nil, "", types.ErrSessionAlreadyExists
|
||||
}
|
||||
|
||||
if _, ok := manager.tokens[token]; ok {
|
||||
manager.sessionsMu.Unlock()
|
||||
return nil, "", fmt.Errorf("session token already exists")
|
||||
return nil, "", errors.New("session token already exists")
|
||||
}
|
||||
|
||||
session := &SessionCtx{
|
||||
@ -98,7 +98,7 @@ func (manager *SessionManagerCtx) Update(id string, profile types.MemberProfile)
|
||||
session, ok := manager.sessions[id]
|
||||
if !ok {
|
||||
manager.sessionsMu.Unlock()
|
||||
return fmt.Errorf("session id not found")
|
||||
return types.ErrSessionNotFound
|
||||
}
|
||||
|
||||
session.profile = profile
|
||||
@ -114,7 +114,7 @@ func (manager *SessionManagerCtx) Delete(id string) error {
|
||||
session, ok := manager.sessions[id]
|
||||
if !ok {
|
||||
manager.sessionsMu.Unlock()
|
||||
return fmt.Errorf("session id not found")
|
||||
return types.ErrSessionNotFound
|
||||
}
|
||||
|
||||
delete(manager.tokens, session.token)
|
||||
|
Reference in New Issue
Block a user