mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 14:50:55 +01:00
small ui fix and added better error for tokens
This commit is contained in:
parent
0b1274dab2
commit
92b5a4fd2a
@ -118,7 +118,7 @@ func newInviteTui() inviteTui {
|
|||||||
m.cursorStyle = m.focusedStyle.Copy()
|
m.cursorStyle = m.focusedStyle.Copy()
|
||||||
m.noStyle = lipgloss.NewStyle()
|
m.noStyle = lipgloss.NewStyle()
|
||||||
m.helpStyle = m.blurredStyle.Copy()
|
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.blurredButton = fmt.Sprintf("[ %v ]", m.blurredStyle.Render("Submit"))
|
||||||
m.msgOk = m.noStyle.Render("enter and confirm your email address...")
|
m.msgOk = m.noStyle.Render("enter and confirm your email address...")
|
||||||
m.msg = m.msgOk
|
m.msg = m.msgOk
|
||||||
|
@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"github.com/go-openapi/runtime/middleware"
|
"github.com/go-openapi/runtime/middleware"
|
||||||
"github.com/openziti/zrok/controller/store"
|
"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/rest_server_zrok/operations/account"
|
||||||
"github.com/openziti/zrok/util"
|
"github.com/openziti/zrok/util"
|
||||||
"github.com/sirupsen/logrus"
|
"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)
|
inviteToken, err := str.GetInviteTokenByToken(params.Body.Token, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("cannot get invite token '%v' for '%v': %v", params.Body.Token, params.Body.Email, err)
|
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 {
|
if err := str.DeleteInviteToken(inviteToken.Id, tx); err != nil {
|
||||||
logrus.Error(err)
|
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 {
|
if _, err := str.FindAccountWithEmail(params.Body.Email, tx); err == nil {
|
||||||
logrus.Errorf("found account for '%v', cannot process account request", params.Body.Email)
|
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 {
|
} else {
|
||||||
logrus.Infof("no account found for '%v': %v", params.Body.Email, err)
|
logrus.Infof("no account found for '%v': %v", params.Body.Email, err)
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,12 @@ package account
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/go-openapi/runtime"
|
"github.com/go-openapi/runtime"
|
||||||
"github.com/go-openapi/strfmt"
|
"github.com/go-openapi/strfmt"
|
||||||
|
|
||||||
|
"github.com/openziti/zrok/rest_model_zrok"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InviteReader is a Reader for the Invite structure.
|
// 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)
|
invitation not created (already exists)
|
||||||
*/
|
*/
|
||||||
type InviteBadRequest struct {
|
type InviteBadRequest struct {
|
||||||
|
Payload rest_model_zrok.ErrorMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsSuccess returns true when this invite bad request response has a 2xx status code
|
// 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 {
|
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 {
|
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 {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,7 +442,10 @@ func init() {
|
|||||||
"description": "invitation created"
|
"description": "invitation created"
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "invitation not created (already exists)"
|
"description": "invitation not created (already exists)",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/errorMessage"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "unauthorized"
|
"description": "unauthorized"
|
||||||
@ -1717,7 +1720,10 @@ func init() {
|
|||||||
"description": "invitation created"
|
"description": "invitation created"
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "invitation not created (already exists)"
|
"description": "invitation not created (already exists)",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/errorMessage"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "unauthorized"
|
"description": "unauthorized"
|
||||||
|
@ -9,6 +9,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/go-openapi/runtime"
|
"github.com/go-openapi/runtime"
|
||||||
|
|
||||||
|
"github.com/openziti/zrok/rest_model_zrok"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InviteCreatedCode is the HTTP code returned for type InviteCreated
|
// InviteCreatedCode is the HTTP code returned for type InviteCreated
|
||||||
@ -45,6 +47,11 @@ InviteBadRequest invitation not created (already exists)
|
|||||||
swagger:response inviteBadRequest
|
swagger:response inviteBadRequest
|
||||||
*/
|
*/
|
||||||
type InviteBadRequest struct {
|
type InviteBadRequest struct {
|
||||||
|
|
||||||
|
/*
|
||||||
|
In: Body
|
||||||
|
*/
|
||||||
|
Payload rest_model_zrok.ErrorMessage `json:"body,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewInviteBadRequest creates InviteBadRequest with default headers values
|
// NewInviteBadRequest creates InviteBadRequest with default headers values
|
||||||
@ -53,12 +60,25 @@ func NewInviteBadRequest() *InviteBadRequest {
|
|||||||
return &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
|
// WriteResponse to the client
|
||||||
func (o *InviteBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
func (o *InviteBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||||
|
|
||||||
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
|
|
||||||
|
|
||||||
rw.WriteHeader(400)
|
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
|
// InviteUnauthorizedCode is the HTTP code returned for type InviteUnauthorized
|
||||||
|
@ -30,6 +30,8 @@ paths:
|
|||||||
description: invitation created
|
description: invitation created
|
||||||
400:
|
400:
|
||||||
description: invitation not created (already exists)
|
description: invitation not created (already exists)
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/errorMessage'
|
||||||
401:
|
401:
|
||||||
description: unauthorized
|
description: unauthorized
|
||||||
500:
|
500:
|
||||||
|
Loading…
Reference in New Issue
Block a user