mirror of
https://github.com/openziti/zrok.git
synced 2024-11-07 16:54:23 +01:00
more cleanups and polish; working registration (#50)
This commit is contained in:
parent
5fae000dad
commit
9cf3cf6f05
@ -38,16 +38,12 @@ func (cmd *createAccountCommand) run(_ *cobra.Command, _ []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
password, err := term.PromptPassword("New Password: ", false)
|
confirm, err := term.Prompt("Confirm Email: ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
confirm, err := term.PromptPassword("Confirm Password: ", false)
|
if confirm != email {
|
||||||
if err != nil {
|
panic("email mismatch")
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if confirm != password {
|
|
||||||
panic("confirmed password mismatch")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zrok, err := newZrokClient()
|
zrok, err := newZrokClient()
|
||||||
@ -56,13 +52,11 @@ func (cmd *createAccountCommand) run(_ *cobra.Command, _ []string) {
|
|||||||
}
|
}
|
||||||
req := identity.NewCreateAccountParams()
|
req := identity.NewCreateAccountParams()
|
||||||
req.Body = &rest_model_zrok.AccountRequest{
|
req.Body = &rest_model_zrok.AccountRequest{
|
||||||
Email: email,
|
Email: email,
|
||||||
Password: password,
|
|
||||||
}
|
}
|
||||||
resp, err := zrok.Identity.CreateAccount(req)
|
_, err = zrok.Identity.CreateAccount(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
logrus.Infof("account request submitted")
|
||||||
logrus.Infof("api token: %v", resp.Payload.Token)
|
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func (self *registerHandler) Handle(params identity.RegisterParams) middleware.R
|
|||||||
|
|
||||||
a := &store.Account{
|
a := &store.Account{
|
||||||
Email: ar.Email,
|
Email: ar.Email,
|
||||||
Password: params.Body.Password,
|
Password: hashPassword(params.Body.Password),
|
||||||
Token: createToken(),
|
Token: createToken(),
|
||||||
}
|
}
|
||||||
if _, err := str.CreateAccount(a, tx); err != nil {
|
if _, err := str.CreateAccount(a, tx); err != nil {
|
||||||
|
@ -57,7 +57,6 @@ CreateAccountCreated describes a response with status code 201, with default hea
|
|||||||
account created
|
account created
|
||||||
*/
|
*/
|
||||||
type CreateAccountCreated struct {
|
type CreateAccountCreated struct {
|
||||||
Payload *rest_model_zrok.AccountResponse
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsSuccess returns true when this create account created response has a 2xx status code
|
// IsSuccess returns true when this create account created response has a 2xx status code
|
||||||
@ -86,26 +85,15 @@ func (o *CreateAccountCreated) IsCode(code int) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *CreateAccountCreated) Error() string {
|
func (o *CreateAccountCreated) Error() string {
|
||||||
return fmt.Sprintf("[POST /account][%d] createAccountCreated %+v", 201, o.Payload)
|
return fmt.Sprintf("[POST /account][%d] createAccountCreated ", 201)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *CreateAccountCreated) String() string {
|
func (o *CreateAccountCreated) String() string {
|
||||||
return fmt.Sprintf("[POST /account][%d] createAccountCreated %+v", 201, o.Payload)
|
return fmt.Sprintf("[POST /account][%d] createAccountCreated ", 201)
|
||||||
}
|
|
||||||
|
|
||||||
func (o *CreateAccountCreated) GetPayload() *rest_model_zrok.AccountResponse {
|
|
||||||
return o.Payload
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *CreateAccountCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
func (o *CreateAccountCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||||
|
|
||||||
o.Payload = new(rest_model_zrok.AccountResponse)
|
|
||||||
|
|
||||||
// response payload
|
|
||||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +19,6 @@ type AccountRequest struct {
|
|||||||
|
|
||||||
// email
|
// email
|
||||||
Email string `json:"email,omitempty"`
|
Email string `json:"email,omitempty"`
|
||||||
|
|
||||||
// password
|
|
||||||
Password string `json:"password,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates this account request
|
// Validate validates this account request
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
// Code generated by go-swagger; DO NOT EDIT.
|
|
||||||
|
|
||||||
package rest_model_zrok
|
|
||||||
|
|
||||||
// This file was generated by the swagger tool.
|
|
||||||
// Editing this file might prove futile when you re-run the swagger generate command
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/go-openapi/strfmt"
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AccountResponse account response
|
|
||||||
//
|
|
||||||
// swagger:model accountResponse
|
|
||||||
type AccountResponse struct {
|
|
||||||
|
|
||||||
// token
|
|
||||||
Token string `json:"token,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate validates this account response
|
|
||||||
func (m *AccountResponse) Validate(formats strfmt.Registry) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ContextValidate validates this account response based on context it is used
|
|
||||||
func (m *AccountResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalBinary interface implementation
|
|
||||||
func (m *AccountResponse) MarshalBinary() ([]byte, error) {
|
|
||||||
if m == nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
return swag.WriteJSON(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalBinary interface implementation
|
|
||||||
func (m *AccountResponse) UnmarshalBinary(b []byte) error {
|
|
||||||
var res AccountResponse
|
|
||||||
if err := swag.ReadJSON(b, &res); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*m = res
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -52,10 +52,7 @@ func init() {
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"201": {
|
"201": {
|
||||||
"description": "account created",
|
"description": "account created"
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/accountResponse"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "account not created (already exists)",
|
"description": "account not created (already exists)",
|
||||||
@ -377,17 +374,6 @@ func init() {
|
|||||||
"properties": {
|
"properties": {
|
||||||
"email": {
|
"email": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
|
||||||
"password": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"accountResponse": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"token": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -662,10 +648,7 @@ func init() {
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"201": {
|
"201": {
|
||||||
"description": "account created",
|
"description": "account created"
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/accountResponse"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "account not created (already exists)",
|
"description": "account not created (already exists)",
|
||||||
@ -987,17 +970,6 @@ func init() {
|
|||||||
"properties": {
|
"properties": {
|
||||||
"email": {
|
"email": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
|
||||||
"password": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"accountResponse": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"token": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -22,11 +22,6 @@ CreateAccountCreated account created
|
|||||||
swagger:response createAccountCreated
|
swagger:response createAccountCreated
|
||||||
*/
|
*/
|
||||||
type CreateAccountCreated struct {
|
type CreateAccountCreated struct {
|
||||||
|
|
||||||
/*
|
|
||||||
In: Body
|
|
||||||
*/
|
|
||||||
Payload *rest_model_zrok.AccountResponse `json:"body,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCreateAccountCreated creates CreateAccountCreated with default headers values
|
// NewCreateAccountCreated creates CreateAccountCreated with default headers values
|
||||||
@ -35,27 +30,12 @@ func NewCreateAccountCreated() *CreateAccountCreated {
|
|||||||
return &CreateAccountCreated{}
|
return &CreateAccountCreated{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithPayload adds the payload to the create account created response
|
|
||||||
func (o *CreateAccountCreated) WithPayload(payload *rest_model_zrok.AccountResponse) *CreateAccountCreated {
|
|
||||||
o.Payload = payload
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetPayload sets the payload to the create account created response
|
|
||||||
func (o *CreateAccountCreated) SetPayload(payload *rest_model_zrok.AccountResponse) {
|
|
||||||
o.Payload = payload
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteResponse to the client
|
// WriteResponse to the client
|
||||||
func (o *CreateAccountCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
func (o *CreateAccountCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||||
|
|
||||||
|
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
|
||||||
|
|
||||||
rw.WriteHeader(201)
|
rw.WriteHeader(201)
|
||||||
if o.Payload != nil {
|
|
||||||
payload := o.Payload
|
|
||||||
if err := producer.Produce(rw, payload); err != nil {
|
|
||||||
panic(err) // let the recovery middleware deal with this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateAccountBadRequestCode is the HTTP code returned for type CreateAccountBadRequest
|
// CreateAccountBadRequestCode is the HTTP code returned for type CreateAccountBadRequest
|
||||||
|
@ -28,8 +28,6 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
201:
|
201:
|
||||||
description: account created
|
description: account created
|
||||||
schema:
|
|
||||||
$ref: "#/definitions/accountResponse"
|
|
||||||
400:
|
400:
|
||||||
description: account not created (already exists)
|
description: account not created (already exists)
|
||||||
schema:
|
schema:
|
||||||
@ -236,13 +234,6 @@ definitions:
|
|||||||
properties:
|
properties:
|
||||||
email:
|
email:
|
||||||
type: string
|
type: string
|
||||||
password:
|
|
||||||
type: string
|
|
||||||
accountResponse:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
token:
|
|
||||||
type: string
|
|
||||||
|
|
||||||
authUser:
|
authUser:
|
||||||
type: object
|
type: object
|
||||||
|
@ -5,7 +5,7 @@ import * as gateway from './gateway'
|
|||||||
/**
|
/**
|
||||||
* @param {object} options Optional options
|
* @param {object} options Optional options
|
||||||
* @param {module:types.accountRequest} [options.body]
|
* @param {module:types.accountRequest} [options.body]
|
||||||
* @return {Promise<module:types.accountResponse>} account created
|
* @return {Promise<object>} account created
|
||||||
*/
|
*/
|
||||||
export function createAccount(options) {
|
export function createAccount(options) {
|
||||||
if (!options) options = {}
|
if (!options) options = {}
|
||||||
|
@ -6,14 +6,6 @@
|
|||||||
* @memberof module:types
|
* @memberof module:types
|
||||||
*
|
*
|
||||||
* @property {string} email
|
* @property {string} email
|
||||||
* @property {string} password
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef accountResponse
|
|
||||||
* @memberof module:types
|
|
||||||
*
|
|
||||||
* @property {string} token
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user