Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hizla
waitlist
backend
Commits
9a0c93f0
Commit
9a0c93f0
authored
10 months ago
by
Levatax
Browse files
Options
Downloads
Plain Diff
Merge branch 'api-fixup' into 'main'
Fix up API paths and responses See merge request
!5
parents
9abc425a
5376d04a
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!5
Fix up API paths and responses
Pipeline
#962
failed
10 months ago
Stage: lint
Stage: test
Stage: build
Changes
3
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app.go
+2
-5
2 additions, 5 deletions
app.go
captcha.go
+2
-2
2 additions, 2 deletions
captcha.go
register.go
+9
-21
9 additions, 21 deletions
register.go
with
13 additions
and
28 deletions
app.go
+
2
−
5
View file @
9a0c93f0
...
@@ -54,11 +54,8 @@ func serve(sig chan os.Signal, db *leveldb.DB) error {
...
@@ -54,11 +54,8 @@ func serve(sig chan os.Signal, db *leveldb.DB) error {
confEnv
[
hCaptchaSiteKey
][
0
],
confEnv
[
hCaptchaSecretKey
][
0
])
confEnv
[
hCaptchaSiteKey
][
0
],
confEnv
[
hCaptchaSecretKey
][
0
])
}
}
// /register
routeHCaptchaSiteKey
(
app
,
"/api"
,
!
hCaptchaEnable
,
conf
[
hCaptchaSiteKey
])
routeRegister
(
app
,
db
,
captcha
)
routeRegister
(
app
,
"/api/register"
,
db
,
captcha
)
// /hcaptcha-site-key
routeHCaptchaSiteKey
(
app
,
!
hCaptchaEnable
,
conf
[
hCaptchaSiteKey
])
// graceful shutdown
// graceful shutdown
go
func
()
{
go
func
()
{
...
...
This diff is collapsed.
Click to expand it.
captcha.go
+
2
−
2
View file @
9a0c93f0
...
@@ -12,7 +12,7 @@ type respHSiteKey struct {
...
@@ -12,7 +12,7 @@ type respHSiteKey struct {
// Route to expose hCaptcha site key.
// Route to expose hCaptcha site key.
// Returns a constant pre-generated response
// Returns a constant pre-generated response
// to avoid unnecessary allocations or serialisations
// to avoid unnecessary allocations or serialisations
func
routeHCaptchaSiteKey
(
app
*
fiber
.
App
,
stub
bool
,
siteKey
string
)
{
func
routeHCaptchaSiteKey
(
app
*
fiber
.
App
,
p
string
,
stub
bool
,
siteKey
string
)
{
var
resp
string
var
resp
string
if
stub
{
if
stub
{
resp
=
mustConstResp
(
newMessage
(
false
,
"hCaptcha is not enabled on this instance."
))
resp
=
mustConstResp
(
newMessage
(
false
,
"hCaptcha is not enabled on this instance."
))
...
@@ -20,7 +20,7 @@ func routeHCaptchaSiteKey(app *fiber.App, stub bool, siteKey string) {
...
@@ -20,7 +20,7 @@ func routeHCaptchaSiteKey(app *fiber.App, stub bool, siteKey string) {
resp
=
mustConstResp
(
respHSiteKey
{
true
,
siteKey
})
resp
=
mustConstResp
(
respHSiteKey
{
true
,
siteKey
})
}
}
app
.
Get
(
"/captcha"
,
func
(
c
fiber
.
Ctx
)
error
{
app
.
Get
(
p
,
func
(
c
fiber
.
Ctx
)
error
{
c
.
Set
(
"Content-Type"
,
"application/json; charset=utf-8"
)
c
.
Set
(
"Content-Type"
,
"application/json; charset=utf-8"
)
return
c
.
SendString
(
resp
)
return
c
.
SendString
(
resp
)
})
})
...
...
This diff is collapsed.
Click to expand it.
register.go
+
9
−
21
View file @
9a0c93f0
...
@@ -15,18 +15,16 @@ type registration struct {
...
@@ -15,18 +15,16 @@ type registration struct {
}
}
// Waitlist registration route
// Waitlist registration route
func
routeRegister
(
app
*
fiber
.
App
,
db
*
leveldb
.
DB
,
captcha
fiber
.
Handler
)
{
func
routeRegister
(
app
*
fiber
.
App
,
p
string
,
db
*
leveldb
.
DB
,
captcha
fiber
.
Handler
)
{
app
.
Post
(
"/register"
,
func
(
c
fiber
.
Ctx
)
error
{
app
.
Post
(
p
,
func
(
c
fiber
.
Ctx
)
error
{
req
:=
new
(
registration
)
req
:=
new
(
registration
)
// Parse and validate the request
// Parse and validate the request
if
err
:=
c
.
Bind
()
.
Body
(
req
);
err
!=
nil
{
if
err
:=
c
.
Bind
()
.
Body
(
req
);
err
!=
nil
{
if
verbose
{
if
verbose
{
log
.
Printf
(
"invalid
request
from %q: %v"
,
c
.
IP
(),
err
)
log
.
Printf
(
"invalid
json
from %q: %v"
,
c
.
IP
(),
err
)
}
}
return
c
.
Status
(
fiber
.
StatusBadRequest
)
.
JSON
(
fiber
.
Map
{
return
c
.
Status
(
fiber
.
StatusBadRequest
)
.
JSON
(
newMessage
(
false
,
"Invalid request"
))
"message"
:
"Invalid request"
,
})
}
}
// Validate email format
// Validate email format
...
@@ -34,37 +32,27 @@ func routeRegister(app *fiber.App, db *leveldb.DB, captcha fiber.Handler) {
...
@@ -34,37 +32,27 @@ func routeRegister(app *fiber.App, db *leveldb.DB, captcha fiber.Handler) {
if
verbose
{
if
verbose
{
log
.
Printf
(
"invalid email from %q: %s"
,
c
.
IP
(),
req
.
Email
)
log
.
Printf
(
"invalid email from %q: %s"
,
c
.
IP
(),
req
.
Email
)
}
}
return
c
.
Status
(
fiber
.
StatusBadRequest
)
.
JSON
(
fiber
.
Map
{
return
c
.
Status
(
fiber
.
StatusBadRequest
)
.
JSON
(
newMessage
(
false
,
"Invalid email address"
))
"message"
:
"Invalid email format"
,
})
}
}
// Check if email is already registered
// Check if email is already registered
if
ok
,
err
:=
db
.
Has
([]
byte
(
req
.
Email
),
nil
);
err
!=
nil
{
if
ok
,
err
:=
db
.
Has
([]
byte
(
req
.
Email
),
nil
);
err
!=
nil
{
log
.
Printf
(
"cannot check for existence of email %q: %v"
,
req
.
Email
,
err
)
log
.
Printf
(
"cannot check for existence of email %q: %v"
,
req
.
Email
,
err
)
return
c
.
Status
(
fiber
.
StatusInternalServerError
)
.
JSON
(
fiber
.
Map
{
return
c
.
Status
(
fiber
.
StatusInternalServerError
)
.
JSON
(
newMessage
(
false
,
"Cannot check registration status"
))
"message"
:
"Error checking registration status"
,
})
}
else
if
ok
{
}
else
if
ok
{
if
verbose
{
if
verbose
{
log
.
Printf
(
"duplicate email from %q: %s"
,
c
.
IP
(),
req
.
Email
)
log
.
Printf
(
"duplicate email from %q: %s"
,
c
.
IP
(),
req
.
Email
)
}
}
return
c
.
Status
(
fiber
.
StatusConflict
)
.
JSON
(
fiber
.
Map
{
return
c
.
Status
(
fiber
.
StatusConflict
)
.
JSON
(
newMessage
(
false
,
"Email already registered"
))
"message"
:
"Email already registered"
,
})
}
}
// Save the email to the waitlist
// Save the email to the waitlist
if
err
:=
db
.
Put
([]
byte
(
req
.
Email
),
[]
byte
{
'x'
},
nil
);
err
!=
nil
{
if
err
:=
db
.
Put
([]
byte
(
req
.
Email
),
[]
byte
{
'x'
},
nil
);
err
!=
nil
{
log
.
Printf
(
"cannot register email %q: %v"
,
req
.
Email
,
err
)
log
.
Printf
(
"cannot register email %q: %v"
,
req
.
Email
,
err
)
return
c
.
Status
(
fiber
.
StatusInternalServerError
)
.
JSON
(
fiber
.
Map
{
return
c
.
Status
(
fiber
.
StatusInternalServerError
)
.
JSON
(
newMessage
(
false
,
"Cannot register email"
))
"message"
:
"Error registering email"
,
})
}
}
log
.
Printf
(
"registered email %q"
,
req
.
Email
)
log
.
Printf
(
"registered email %q"
,
req
.
Email
)
return
c
.
JSON
(
fiber
.
Map
{
return
c
.
JSON
(
newMessage
(
true
,
"Email registered successfully"
))
"message"
:
"Email registered successfully"
,
})
},
captcha
)
},
captcha
)
}
}
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