Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
ac560dfc
Commit
ac560dfc
authored
Jul 09, 2022
by
boojack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update get user by id
parent
1afc1834
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
10 deletions
+7
-10
basic_auth.go
server/basic_auth.go
+5
-3
user.go
server/user.go
+2
-7
No files found.
server/basic_auth.go
View file @
ac560dfc
...
...
@@ -55,7 +55,7 @@ func removeUserSession(c echo.Context) error {
func
BasicAuthMiddleware
(
s
*
Server
,
next
echo
.
HandlerFunc
)
echo
.
HandlerFunc
{
return
func
(
c
echo
.
Context
)
error
{
// Skip auth for some paths.
if
common
.
HasPrefixes
(
c
.
Path
(),
"/api/auth"
,
"/api/ping"
,
"/api/status"
)
{
if
common
.
HasPrefixes
(
c
.
Path
(),
"/api/auth"
,
"/api/ping"
,
"/api/status"
,
"/api/user/:id/"
)
{
return
next
(
c
)
}
...
...
@@ -76,9 +76,11 @@ func BasicAuthMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
}
}
if
common
.
HasPrefixes
(
c
.
Path
(),
"/api/memo"
,
"/api/tag"
,
"/api/shortcut"
,
"/api/user/:id/name"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
if
common
.
HasPrefixes
(
c
.
Path
(),
"/api/memo"
,
"/api/tag"
,
"/api/shortcut"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
if
_
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"creatorId"
));
err
==
nil
{
return
next
(
c
)
}
}
sess
,
err
:=
session
.
Get
(
"session"
,
c
)
if
err
!=
nil
{
...
...
server/user.go
View file @
ac560dfc
...
...
@@ -51,7 +51,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
return
nil
})
g
.
GET
(
"/user/:id
/name
"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/user/:id"
,
func
(
c
echo
.
Context
)
error
{
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted user id"
)
.
SetInternal
(
err
)
...
...
@@ -64,13 +64,8 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to fetch user"
)
.
SetInternal
(
err
)
}
username
:=
""
if
user
!=
nil
{
username
=
user
.
Name
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
user
name
));
err
!=
nil
{
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
user
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to encode user response"
)
.
SetInternal
(
err
)
}
return
nil
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment