Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
invinoveritas
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gbe
invinoveritas
Commits
0545c7b8
Commit
0545c7b8
authored
3 years ago
by
gbe
Browse files
Options
Downloads
Patches
Plain Diff
fix auth stuff on empty db
parent
8ab51aab
No related branches found
No related tags found
No related merge requests found
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-3
1 addition, 3 deletions
.gitignore
auth/auth.go
+5
-7
5 additions, 7 deletions
auth/auth.go
handler-index.go
+2
-0
2 additions, 0 deletions
handler-index.go
session/authprovider.go
+5
-3
5 additions, 3 deletions
session/authprovider.go
with
13 additions
and
13 deletions
.gitignore
+
1
−
3
View file @
0545c7b8
vino.ql
vino.sqlite*
vino.db
.[0-9a-f]*
invinoveritas
invinoveritas
\ No newline at end of file
This diff is collapsed.
Click to expand it.
auth/auth.go
+
5
−
7
View file @
0545c7b8
...
@@ -69,16 +69,14 @@ func Require(next http.Handler, authFailed http.Handler, provider Provider) http
...
@@ -69,16 +69,14 @@ func Require(next http.Handler, authFailed http.Handler, provider Provider) http
}
}
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
var
token
string
cookie
,
err
:=
r
.
Cookie
(
"session"
)
cookie
,
err
:=
r
.
Cookie
(
"session"
)
if
err
!=
nil
{
if
err
==
nil
{
anonAuth
(
w
,
r
)
token
=
cookie
.
Value
return
}
}
level
.
Debug
(
log
.
Get
(
r
))
.
user
,
err
:=
provider
.
Valid
(
r
.
Context
(),
token
)
Log
(
"cookie"
,
cookie
,
"msg"
,
"got auth cookie"
)
user
,
err
:=
provider
.
Valid
(
r
.
Context
(),
cookie
.
Value
)
if
errors
.
Is
(
err
,
ErrAuthFailed
)
{
if
errors
.
Is
(
err
,
ErrAuthFailed
)
{
anonAuth
(
w
,
r
)
anonAuth
(
w
,
r
)
return
return
...
...
This diff is collapsed.
Click to expand it.
handler-index.go
+
2
−
0
View file @
0545c7b8
...
@@ -33,6 +33,8 @@ func (h Handler) index() http.Handler {
...
@@ -33,6 +33,8 @@ func (h Handler) index() http.Handler {
tpl
=
template
.
Must
(
template
.
ParseFS
(
templateFS
,
"templates/base.tpl"
,
"templates/index.tpl"
))
tpl
=
template
.
Must
(
template
.
ParseFS
(
templateFS
,
"templates/base.tpl"
,
"templates/index.tpl"
))
})
})
level
.
Debug
(
log
.
Get
(
r
))
.
Log
(
"user"
,
auth
.
Get
(
r
))
if
r
.
Method
==
"GET"
{
if
r
.
Method
==
"GET"
{
wines
,
err
:=
h
.
Q
.
ListWines
(
r
.
Context
())
wines
,
err
:=
h
.
Q
.
ListWines
(
r
.
Context
())
if
err
!=
nil
{
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
session/authprovider.go
+
5
−
3
View file @
0545c7b8
...
@@ -97,6 +97,8 @@ func (a Provider) Valid(ctx context.Context, token string) (*auth.User, error) {
...
@@ -97,6 +97,8 @@ func (a Provider) Valid(ctx context.Context, token string) (*auth.User, error) {
)
)
err
=
a
.
q
.
RunTx
(
ctx
,
func
(
ctx
context
.
Context
,
q
*
query
.
Queries
)
error
{
err
=
a
.
q
.
RunTx
(
ctx
,
func
(
ctx
context
.
Context
,
q
*
query
.
Queries
)
error
{
level
.
Debug
(
log
.
GetContext
(
ctx
))
.
Log
(
"msg"
,
"checking session token"
,
"token"
,
token
)
user
.
Name
,
err
=
q
.
IsValidSession
(
ctx
,
token
)
user
.
Name
,
err
=
q
.
IsValidSession
(
ctx
,
token
)
if
errors
.
Is
(
err
,
sql
.
ErrNoRows
)
{
if
errors
.
Is
(
err
,
sql
.
ErrNoRows
)
{
// Let's see if there are any users at all. If not, we let 'em in.
// Let's see if there are any users at all. If not, we let 'em in.
...
@@ -188,7 +190,7 @@ func (a Provider) Handler(templateFS fs.FS) http.Handler {
...
@@ -188,7 +190,7 @@ func (a Provider) Handler(templateFS fs.FS) http.Handler {
return
fmt
.
Errorf
(
"executing auth template: %w"
,
err
)
return
fmt
.
Errorf
(
"executing auth template: %w"
,
err
)
}
}
return
nil
return
auth
.
ErrAuthFailed
}
}
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"getting salted password: %w"
,
err
)
return
fmt
.
Errorf
(
"getting salted password: %w"
,
err
)
...
@@ -215,7 +217,7 @@ func (a Provider) Handler(templateFS fs.FS) http.Handler {
...
@@ -215,7 +217,7 @@ func (a Provider) Handler(templateFS fs.FS) http.Handler {
return
fmt
.
Errorf
(
"executing auth template: %w"
,
err
)
return
fmt
.
Errorf
(
"executing auth template: %w"
,
err
)
}
}
return
nil
return
auth
.
ErrAuthFailed
}
}
log
=
kitlog
.
With
(
log
,
"user_id"
,
userData
.
UserID
)
log
=
kitlog
.
With
(
log
,
"user_id"
,
userData
.
UserID
)
...
@@ -252,7 +254,7 @@ func (a Provider) Handler(templateFS fs.FS) http.Handler {
...
@@ -252,7 +254,7 @@ func (a Provider) Handler(templateFS fs.FS) http.Handler {
}
}
level
.
Debug
(
log
)
.
level
.
Debug
(
log
)
.
Log
(
"cookie"
,
cookie
,
"msg"
,
"setting token cookie"
)
Log
(
"cookie"
,
fmt
.
Sprintf
(
"%#v"
,
cookie
)
,
"msg"
,
"setting token cookie"
)
http
.
SetCookie
(
w
,
&
cookie
)
http
.
SetCookie
(
w
,
&
cookie
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment