small ui fix and added better error for tokens

This commit is contained in:
Cam Otts 2023-02-07 19:06:35 -06:00
parent 0b1274dab2
commit 92b5a4fd2a
No known key found for this signature in database
GPG Key ID: 367B7C7EBD84A8BD
6 changed files with 51 additions and 9 deletions

View File

@ -118,7 +118,7 @@ func newInviteTui() inviteTui {
m.cursorStyle = m.focusedStyle.Copy()
m.noStyle = lipgloss.NewStyle()
m.helpStyle = m.blurredStyle.Copy()
m.focusedButton = m.focusedStyle.Copy().Render("[ Submit ]")
m.focusedButton = m.focusedStyle.Copy().Render("[*Submit*]")
m.blurredButton = fmt.Sprintf("[ %v ]", m.blurredStyle.Render("Submit"))
m.msgOk = m.noStyle.Render("enter and confirm your email address...")
m.msg = m.msgOk

View File

@ -3,6 +3,7 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/account"
"github.com/openziti/zrok/util"
"github.com/sirupsen/logrus"
@ -41,7 +42,7 @@ func (self *inviteHandler) Handle(params account.InviteParams) middleware.Respon
inviteToken, err := str.GetInviteTokenByToken(params.Body.Token, tx)
if err != nil {
logrus.Errorf("cannot get invite token '%v' for '%v': %v", params.Body.Token, params.Body.Email, err)
return account.NewInviteUnauthorized()
return account.NewInviteBadRequest().WithPayload(rest_model_zrok.ErrorMessage("Missing invite token"))
}
if err := str.DeleteInviteToken(inviteToken.Id, tx); err != nil {
logrus.Error(err)
@ -63,7 +64,7 @@ func (self *inviteHandler) Handle(params account.InviteParams) middleware.Respon
if _, err := str.FindAccountWithEmail(params.Body.Email, tx); err == nil {
logrus.Errorf("found account for '%v', cannot process account request", params.Body.Email)
return account.NewInviteBadRequest()
return account.NewInviteBadRequest().WithPayload(rest_model_zrok.ErrorMessage("Duplicate email found"))
} else {
logrus.Infof("no account found for '%v': %v", params.Body.Email, err)
}

View File

@ -7,9 +7,12 @@ package account
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
"github.com/openziti/zrok/rest_model_zrok"
)
// InviteReader is a Reader for the Invite structure.
@ -111,6 +114,7 @@ InviteBadRequest describes a response with status code 400, with default header
invitation not created (already exists)
*/
type InviteBadRequest struct {
Payload rest_model_zrok.ErrorMessage
}
// IsSuccess returns true when this invite bad request response has a 2xx status code
@ -139,15 +143,24 @@ func (o *InviteBadRequest) IsCode(code int) bool {
}
func (o *InviteBadRequest) Error() string {
return fmt.Sprintf("[POST /invite][%d] inviteBadRequest ", 400)
return fmt.Sprintf("[POST /invite][%d] inviteBadRequest %+v", 400, o.Payload)
}
func (o *InviteBadRequest) String() string {
return fmt.Sprintf("[POST /invite][%d] inviteBadRequest ", 400)
return fmt.Sprintf("[POST /invite][%d] inviteBadRequest %+v", 400, o.Payload)
}
func (o *InviteBadRequest) GetPayload() rest_model_zrok.ErrorMessage {
return o.Payload
}
func (o *InviteBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@ -442,7 +442,10 @@ func init() {
"description": "invitation created"
},
"400": {
"description": "invitation not created (already exists)"
"description": "invitation not created (already exists)",
"schema": {
"$ref": "#/definitions/errorMessage"
}
},
"401": {
"description": "unauthorized"
@ -1717,7 +1720,10 @@ func init() {
"description": "invitation created"
},
"400": {
"description": "invitation not created (already exists)"
"description": "invitation not created (already exists)",
"schema": {
"$ref": "#/definitions/errorMessage"
}
},
"401": {
"description": "unauthorized"

View File

@ -9,6 +9,8 @@ import (
"net/http"
"github.com/go-openapi/runtime"
"github.com/openziti/zrok/rest_model_zrok"
)
// InviteCreatedCode is the HTTP code returned for type InviteCreated
@ -45,6 +47,11 @@ InviteBadRequest invitation not created (already exists)
swagger:response inviteBadRequest
*/
type InviteBadRequest struct {
/*
In: Body
*/
Payload rest_model_zrok.ErrorMessage `json:"body,omitempty"`
}
// NewInviteBadRequest creates InviteBadRequest with default headers values
@ -53,12 +60,25 @@ func NewInviteBadRequest() *InviteBadRequest {
return &InviteBadRequest{}
}
// WithPayload adds the payload to the invite bad request response
func (o *InviteBadRequest) WithPayload(payload rest_model_zrok.ErrorMessage) *InviteBadRequest {
o.Payload = payload
return o
}
// SetPayload sets the payload to the invite bad request response
func (o *InviteBadRequest) SetPayload(payload rest_model_zrok.ErrorMessage) {
o.Payload = payload
}
// WriteResponse to the client
func (o *InviteBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(400)
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
// InviteUnauthorizedCode is the HTTP code returned for type InviteUnauthorized

View File

@ -30,6 +30,8 @@ paths:
description: invitation created
400:
description: invitation not created (already exists)
schema:
$ref: '#/definitions/errorMessage'
401:
description: unauthorized
500: