mirror of
https://github.com/harness/drone.git
synced 2025-05-05 23:42:23 +08:00
[CODE-617]: Lint issues
This commit is contained in:
parent
fe9bc1a4db
commit
b8c239ed6d
@ -7,19 +7,17 @@ package user
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/harness/gitness/internal/api/usererror"
|
||||
"github.com/harness/gitness/internal/token"
|
||||
"github.com/harness/gitness/types"
|
||||
)
|
||||
|
||||
/*
|
||||
* Register creates a new user and returns a new session token on success.
|
||||
* This differs from the Create method as it doesn't require auth, but has limited
|
||||
* functionalities (unable to create admin user for example).
|
||||
*/
|
||||
// Register creates a new user and returns a new session token on success.
|
||||
// This differs from the Create method as it doesn't require auth, but has limited
|
||||
// functionalities (unable to create admin user for example).
|
||||
func (c *Controller) Register(ctx context.Context,
|
||||
in *CreateInput, config *types.Config) (*types.TokenResponse, error) {
|
||||
|
||||
signUpFlag := config.AllowSignUp
|
||||
if !signUpFlag {
|
||||
return nil, usererror.BadRequest("User sign-up is disabled.")
|
||||
|
@ -11,11 +11,8 @@ import (
|
||||
)
|
||||
|
||||
// RegisterCheck checks the DB and env config flag to return boolean
|
||||
// which represents if a user sign-up is allowed or not
|
||||
|
||||
func (c *Controller) RegisterCheck(ctx context.Context,
|
||||
config *types.Config) (*bool, error) {
|
||||
|
||||
// which represents if a user sign-up is allowed or not.
|
||||
func (c *Controller) RegisterCheck(ctx context.Context, config *types.Config) (*bool, error) {
|
||||
usrCount, err := c.principalStore.CountUsers(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
// HandleRegisterCheck returns an http.HandlerFunc that processes an http.Request
|
||||
// and returns a boolean true/false if user registration is allowed or not
|
||||
// and returns a boolean true/false if user registration is allowed or not.
|
||||
func HandleRegisterCheck(userCtrl *user.Controller, config *types.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
@ -24,6 +24,10 @@ type registerRequest struct {
|
||||
user.CreateInput
|
||||
}
|
||||
|
||||
type registrationCheckResponse struct {
|
||||
Allowed bool `json:"allowed"`
|
||||
}
|
||||
|
||||
// helper function that constructs the openapi specification
|
||||
// for the account registration and login endpoints.
|
||||
func buildAccount(reflector *openapi3.Reflector) {
|
||||
@ -55,4 +59,13 @@ func buildAccount(reflector *openapi3.Reflector) {
|
||||
_ = reflector.SetJSONResponse(&onRegister, new(usererror.Error), http.StatusInternalServerError)
|
||||
_ = reflector.SetJSONResponse(&onRegister, new(usererror.Error), http.StatusBadRequest)
|
||||
_ = reflector.Spec.AddOperation(http.MethodPost, "/register", onRegister)
|
||||
|
||||
onRegistrationCheck := openapi3.Operation{}
|
||||
onRegistrationCheck.WithTags("account")
|
||||
onRegistrationCheck.WithMapOfAnything(map[string]interface{}{"operationId": "onRegistrationCheck"})
|
||||
_ = reflector.SetRequest(&onRegistrationCheck, nil, http.MethodGet)
|
||||
_ = reflector.SetJSONResponse(&onRegistrationCheck, new(registrationCheckResponse), http.StatusOK)
|
||||
_ = reflector.SetJSONResponse(&onRegistrationCheck, new(usererror.Error), http.StatusInternalServerError)
|
||||
_ = reflector.SetJSONResponse(&onRegistrationCheck, new(usererror.Error), http.StatusBadRequest)
|
||||
_ = reflector.Spec.AddOperation(http.MethodGet, "/registration-check", onRegistrationCheck)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user