mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 06:40:50 +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 {
|
||||
panic(err)
|
||||
}
|
||||
password, err := term.PromptPassword("New Password: ", false)
|
||||
confirm, err := term.Prompt("Confirm Email: ")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
confirm, err := term.PromptPassword("Confirm Password: ", false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if confirm != password {
|
||||
panic("confirmed password mismatch")
|
||||
if confirm != email {
|
||||
panic("email mismatch")
|
||||
}
|
||||
|
||||
zrok, err := newZrokClient()
|
||||
@ -56,13 +52,11 @@ func (cmd *createAccountCommand) run(_ *cobra.Command, _ []string) {
|
||||
}
|
||||
req := identity.NewCreateAccountParams()
|
||||
req.Body = &rest_model_zrok.AccountRequest{
|
||||
Email: email,
|
||||
Password: password,
|
||||
Email: email,
|
||||
}
|
||||
resp, err := zrok.Identity.CreateAccount(req)
|
||||
_, err = zrok.Identity.CreateAccount(req)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
logrus.Infof("api token: %v", resp.Payload.Token)
|
||||
logrus.Infof("account request submitted")
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ func (self *registerHandler) Handle(params identity.RegisterParams) middleware.R
|
||||
|
||||
a := &store.Account{
|
||||
Email: ar.Email,
|
||||
Password: params.Body.Password,
|
||||
Password: hashPassword(params.Body.Password),
|
||||
Token: createToken(),
|
||||
}
|
||||
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
|
||||
*/
|
||||
type CreateAccountCreated struct {
|
||||
Payload *rest_model_zrok.AccountResponse
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return fmt.Sprintf("[POST /account][%d] createAccountCreated %+v", 201, o.Payload)
|
||||
return fmt.Sprintf("[POST /account][%d] createAccountCreated ", 201)
|
||||
}
|
||||
|
||||
func (o *CreateAccountCreated) String() string {
|
||||
return fmt.Sprintf("[POST /account][%d] createAccountCreated %+v", 201, o.Payload)
|
||||
}
|
||||
|
||||
func (o *CreateAccountCreated) GetPayload() *rest_model_zrok.AccountResponse {
|
||||
return o.Payload
|
||||
return fmt.Sprintf("[POST /account][%d] createAccountCreated ", 201)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,6 @@ type AccountRequest struct {
|
||||
|
||||
// email
|
||||
Email string `json:"email,omitempty"`
|
||||
|
||||
// password
|
||||
Password string `json:"password,omitempty"`
|
||||
}
|
||||
|
||||
// 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": {
|
||||
"201": {
|
||||
"description": "account created",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/accountResponse"
|
||||
}
|
||||
"description": "account created"
|
||||
},
|
||||
"400": {
|
||||
"description": "account not created (already exists)",
|
||||
@ -377,17 +374,6 @@ func init() {
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"accountResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -662,10 +648,7 @@ func init() {
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "account created",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/accountResponse"
|
||||
}
|
||||
"description": "account created"
|
||||
},
|
||||
"400": {
|
||||
"description": "account not created (already exists)",
|
||||
@ -987,17 +970,6 @@ func init() {
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"accountResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -22,11 +22,6 @@ CreateAccountCreated account created
|
||||
swagger:response createAccountCreated
|
||||
*/
|
||||
type CreateAccountCreated struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *rest_model_zrok.AccountResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewCreateAccountCreated creates CreateAccountCreated with default headers values
|
||||
@ -35,27 +30,12 @@ func NewCreateAccountCreated() *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
|
||||
func (o *CreateAccountCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
|
||||
|
||||
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
|
||||
|
@ -28,8 +28,6 @@ paths:
|
||||
responses:
|
||||
201:
|
||||
description: account created
|
||||
schema:
|
||||
$ref: "#/definitions/accountResponse"
|
||||
400:
|
||||
description: account not created (already exists)
|
||||
schema:
|
||||
@ -236,13 +234,6 @@ definitions:
|
||||
properties:
|
||||
email:
|
||||
type: string
|
||||
password:
|
||||
type: string
|
||||
accountResponse:
|
||||
type: object
|
||||
properties:
|
||||
token:
|
||||
type: string
|
||||
|
||||
authUser:
|
||||
type: object
|
||||
|
@ -5,7 +5,7 @@ import * as gateway from './gateway'
|
||||
/**
|
||||
* @param {object} options Optional options
|
||||
* @param {module:types.accountRequest} [options.body]
|
||||
* @return {Promise<module:types.accountResponse>} account created
|
||||
* @return {Promise<object>} account created
|
||||
*/
|
||||
export function createAccount(options) {
|
||||
if (!options) options = {}
|
||||
|
@ -6,14 +6,6 @@
|
||||
* @memberof module:types
|
||||
*
|
||||
* @property {string} email
|
||||
* @property {string} password
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef accountResponse
|
||||
* @memberof module:types
|
||||
*
|
||||
* @property {string} token
|
||||
*/
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user