kopia lustrzana https://github.com/reiver/greatape
feat(api): ✨ username availability
rodzic
a273e3c7a0
commit
29b364553f
|
@ -0,0 +1,14 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import . "github.com/reiver/greatape/components/contracts"
|
||||||
|
|
||||||
|
func CheckUsernameAvailability(x IDispatcher, username string) (ICheckUsernameAvailabilityResult, error) {
|
||||||
|
isAvailable := true
|
||||||
|
if x.IdentityExistsWhich(func(identity IIdentity) bool {
|
||||||
|
return identity.Username() == username
|
||||||
|
}) {
|
||||||
|
isAvailable = false
|
||||||
|
}
|
||||||
|
|
||||||
|
return x.NewCheckUsernameAvailabilityResult(isAvailable), nil
|
||||||
|
}
|
|
@ -45,6 +45,18 @@ func TestEchoApi(test *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCheckUsernameAvailabilityApi(test *testing.T) {
|
||||||
|
input := &CheckUsernameAvailabilityRequest{
|
||||||
|
Username: "username",
|
||||||
|
}
|
||||||
|
|
||||||
|
if output, err := api.CheckUsernameAvailability(input); err != nil {
|
||||||
|
test.Fatal(err)
|
||||||
|
} else if output == nil {
|
||||||
|
test.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSignupApi(test *testing.T) {
|
func TestSignupApi(test *testing.T) {
|
||||||
input := &SignupRequest{
|
input := &SignupRequest{
|
||||||
Username: "username",
|
Username: "username",
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
. "github.com/reiver/greatape/components/api/protobuf"
|
||||||
|
. "github.com/reiver/greatape/components/contracts"
|
||||||
|
. "github.com/xeronith/diamante/contracts/network/http"
|
||||||
|
pipeline "github.com/xeronith/diamante/network/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type checkUsernameAvailabilityHandler struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckUsernameAvailabilityHandler() IHttpHandler {
|
||||||
|
return &checkUsernameAvailabilityHandler{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (handler *checkUsernameAvailabilityHandler) Method() string {
|
||||||
|
return http.MethodPost
|
||||||
|
}
|
||||||
|
|
||||||
|
func (handler *checkUsernameAvailabilityHandler) Path() string {
|
||||||
|
return "/api/v1/check-username"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (handler *checkUsernameAvailabilityHandler) HandlerFunc() HttpHandlerFunc {
|
||||||
|
return func(x IServerDispatcher) error {
|
||||||
|
request := &CheckUsernameAvailabilityRequest{}
|
||||||
|
result := &CheckUsernameAvailabilityResult{}
|
||||||
|
|
||||||
|
onRequestUnmarshalled := func(request *CheckUsernameAvailabilityRequest) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return pipeline.Handle(x,
|
||||||
|
"check_username_availability",
|
||||||
|
CHECK_USERNAME_AVAILABILITY_REQUEST,
|
||||||
|
CHECK_USERNAME_AVAILABILITY_RESULT,
|
||||||
|
request, result,
|
||||||
|
onRequestUnmarshalled,
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ type httpHandlerFactory struct{}
|
||||||
func (factory *httpHandlerFactory) Handlers() []IHttpHandler {
|
func (factory *httpHandlerFactory) Handlers() []IHttpHandler {
|
||||||
return []IHttpHandler{
|
return []IHttpHandler{
|
||||||
EchoHandler(), // │ P . /api/v1/echo
|
EchoHandler(), // │ P . /api/v1/echo
|
||||||
|
CheckUsernameAvailabilityHandler(), // │ P . /api/v1/check-username
|
||||||
SignupHandler(), // │ P . /api/v1/signup
|
SignupHandler(), // │ P . /api/v1/signup
|
||||||
VerifyHandler(), // │ P . /api/v1/verify
|
VerifyHandler(), // │ P . /api/v1/verify
|
||||||
LoginHandler(), // │ P . /api/v1/login
|
LoginHandler(), // │ P . /api/v1/login
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package operations
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/reiver/greatape/components/api/protobuf"
|
||||||
|
. "github.com/reiver/greatape/components/api/services"
|
||||||
|
. "github.com/reiver/greatape/components/contracts"
|
||||||
|
. "github.com/xeronith/diamante/contracts/operation"
|
||||||
|
. "github.com/xeronith/diamante/contracts/service"
|
||||||
|
. "github.com/xeronith/diamante/contracts/system"
|
||||||
|
. "github.com/xeronith/diamante/operation"
|
||||||
|
)
|
||||||
|
|
||||||
|
type checkUsernameAvailabilityOperation struct {
|
||||||
|
Operation
|
||||||
|
|
||||||
|
run func(IContext, *CheckUsernameAvailabilityRequest) (*CheckUsernameAvailabilityResult, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckUsernameAvailabilityOperation() IOperation {
|
||||||
|
return &checkUsernameAvailabilityOperation{
|
||||||
|
run: CheckUsernameAvailabilityService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *checkUsernameAvailabilityOperation) Id() (ID, ID) {
|
||||||
|
return CHECK_USERNAME_AVAILABILITY_REQUEST, CHECK_USERNAME_AVAILABILITY_RESULT
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *checkUsernameAvailabilityOperation) InputContainer() Pointer {
|
||||||
|
return new(CheckUsernameAvailabilityRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *checkUsernameAvailabilityOperation) OutputContainer() Pointer {
|
||||||
|
return new(CheckUsernameAvailabilityResult)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *checkUsernameAvailabilityOperation) Execute(context IContext, payload Pointer) (Pointer, error) {
|
||||||
|
return operation.run(context, payload.(*CheckUsernameAvailabilityRequest))
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
func (operation *checkUsernameAvailabilityOperation) ExecutionTimeLimits() (Duration, Duration, Duration) {
|
||||||
|
var (
|
||||||
|
TIME_LIMIT_WARNING Duration = 20_000_000
|
||||||
|
TIME_LIMIT_ALERT Duration = 35_000_000
|
||||||
|
TIME_LIMIT_CRITICAL Duration = 50_000_000
|
||||||
|
)
|
||||||
|
|
||||||
|
return TIME_LIMIT_WARNING, TIME_LIMIT_ALERT, TIME_LIMIT_CRITICAL
|
||||||
|
}
|
||||||
|
*/
|
|
@ -8,6 +8,7 @@ func (factory *operationFactory) Operations() []IOperation {
|
||||||
return []IOperation{
|
return []IOperation{
|
||||||
SystemCallOperation(),
|
SystemCallOperation(),
|
||||||
EchoOperation(),
|
EchoOperation(),
|
||||||
|
CheckUsernameAvailabilityOperation(),
|
||||||
SignupOperation(),
|
SignupOperation(),
|
||||||
VerifyOperation(),
|
VerifyOperation(),
|
||||||
LoginOperation(),
|
LoginOperation(),
|
||||||
|
|
Plik diff jest za duży
Load Diff
|
@ -25,6 +25,16 @@ message EchoResult {
|
||||||
Document document = 0x00000001;
|
Document document = 0x00000001;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// API: CheckUsernameAvailability
|
||||||
|
//-----------------------------------------------------------
|
||||||
|
message CheckUsernameAvailabilityRequest {
|
||||||
|
string username = 0x00000001;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CheckUsernameAvailabilityResult {
|
||||||
|
bool isAvailable = 0x00000001;
|
||||||
|
}
|
||||||
|
|
||||||
// API: Signup
|
// API: Signup
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
message SignupRequest {
|
message SignupRequest {
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/reiver/greatape/components/api/protobuf"
|
||||||
|
. "github.com/reiver/greatape/components/contracts"
|
||||||
|
"github.com/reiver/greatape/components/core"
|
||||||
|
. "github.com/xeronith/diamante/contracts/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
// noinspection GoUnusedParameter
|
||||||
|
func CheckUsernameAvailabilityService(context IContext, input *CheckUsernameAvailabilityRequest) (result *CheckUsernameAvailabilityResult, err error) {
|
||||||
|
conductor := core.Conductor
|
||||||
|
_ = CHECK_USERNAME_AVAILABILITY_REQUEST
|
||||||
|
|
||||||
|
conductor.LogRemoteCall(context, INITIALIZE, "check_username_availability", input, result, err)
|
||||||
|
defer func() { conductor.LogRemoteCall(context, FINALIZE, "check_username_availability", input, result, err) }()
|
||||||
|
|
||||||
|
_result, _err := conductor.CheckUsernameAvailability(input.Username, context.Identity())
|
||||||
|
if _err != nil {
|
||||||
|
err = _err
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = _result
|
||||||
|
|
||||||
|
result = context.ResultContainer().(*CheckUsernameAvailabilityResult)
|
||||||
|
result.IsAvailable = _result.IsAvailable()
|
||||||
|
return result, nil
|
||||||
|
}
|
|
@ -50,6 +50,8 @@ const (
|
||||||
ERROR_MESSAGE_UNKNOWN_SPI = "ERROR_MESSAGE_UNKNOWN_SPI"
|
ERROR_MESSAGE_UNKNOWN_SPI = "ERROR_MESSAGE_UNKNOWN_SPI"
|
||||||
ERROR_MESSAGE_INVALID_ID = "ERROR_MESSAGE_INVALID_ID"
|
ERROR_MESSAGE_INVALID_ID = "ERROR_MESSAGE_INVALID_ID"
|
||||||
ERROR_MESSAGE_INVALID_PARAMETERS = "ERROR_MESSAGE_INVALID_PARAMETERS"
|
ERROR_MESSAGE_INVALID_PARAMETERS = "ERROR_MESSAGE_INVALID_PARAMETERS"
|
||||||
|
ERROR_MESSAGE_INVALID_USERNAME_FOR_CHECK_USERNAME_AVAILABILITY = "ERROR_MESSAGE_INVALID_USERNAME_FOR_CHECK_USERNAME_AVAILABILITY"
|
||||||
|
ERROR_MESSAGE_INVALID_USERNAME_FOR_SIGNUP = "ERROR_MESSAGE_INVALID_USERNAME_FOR_SIGNUP"
|
||||||
ERROR_MESSAGE_INVALID_EMAIL_FOR_SIGNUP = "ERROR_MESSAGE_INVALID_EMAIL_FOR_SIGNUP"
|
ERROR_MESSAGE_INVALID_EMAIL_FOR_SIGNUP = "ERROR_MESSAGE_INVALID_EMAIL_FOR_SIGNUP"
|
||||||
ERROR_MESSAGE_INVALID_PASSWORD_FOR_SIGNUP = "ERROR_MESSAGE_INVALID_PASSWORD_FOR_SIGNUP"
|
ERROR_MESSAGE_INVALID_PASSWORD_FOR_SIGNUP = "ERROR_MESSAGE_INVALID_PASSWORD_FOR_SIGNUP"
|
||||||
ERROR_MESSAGE_INVALID_EMAIL_FOR_VERIFY = "ERROR_MESSAGE_INVALID_EMAIL_FOR_VERIFY"
|
ERROR_MESSAGE_INVALID_EMAIL_FOR_VERIFY = "ERROR_MESSAGE_INVALID_EMAIL_FOR_VERIFY"
|
||||||
|
@ -115,6 +117,8 @@ var (
|
||||||
ERROR_UNKNOWN_SPI = errors.New(ERROR_MESSAGE_UNKNOWN_SPI)
|
ERROR_UNKNOWN_SPI = errors.New(ERROR_MESSAGE_UNKNOWN_SPI)
|
||||||
ERROR_INVALID_ID = errors.New(ERROR_MESSAGE_INVALID_ID)
|
ERROR_INVALID_ID = errors.New(ERROR_MESSAGE_INVALID_ID)
|
||||||
ERROR_INVALID_PARAMETERS = errors.New(ERROR_MESSAGE_INVALID_PARAMETERS)
|
ERROR_INVALID_PARAMETERS = errors.New(ERROR_MESSAGE_INVALID_PARAMETERS)
|
||||||
|
ERROR_INVALID_USERNAME_FOR_CHECK_USERNAME_AVAILABILITY = errors.New(ERROR_MESSAGE_INVALID_USERNAME_FOR_CHECK_USERNAME_AVAILABILITY)
|
||||||
|
ERROR_INVALID_USERNAME_FOR_SIGNUP = errors.New(ERROR_MESSAGE_INVALID_USERNAME_FOR_SIGNUP)
|
||||||
ERROR_INVALID_EMAIL_FOR_SIGNUP = errors.New(ERROR_MESSAGE_INVALID_EMAIL_FOR_SIGNUP)
|
ERROR_INVALID_EMAIL_FOR_SIGNUP = errors.New(ERROR_MESSAGE_INVALID_EMAIL_FOR_SIGNUP)
|
||||||
ERROR_INVALID_PASSWORD_FOR_SIGNUP = errors.New(ERROR_MESSAGE_INVALID_PASSWORD_FOR_SIGNUP)
|
ERROR_INVALID_PASSWORD_FOR_SIGNUP = errors.New(ERROR_MESSAGE_INVALID_PASSWORD_FOR_SIGNUP)
|
||||||
ERROR_INVALID_EMAIL_FOR_VERIFY = errors.New(ERROR_MESSAGE_INVALID_EMAIL_FOR_VERIFY)
|
ERROR_INVALID_EMAIL_FOR_VERIFY = errors.New(ERROR_MESSAGE_INVALID_EMAIL_FOR_VERIFY)
|
||||||
|
|
|
@ -47,6 +47,8 @@ var Errors = Resource{
|
||||||
ERROR_MESSAGE_UNKNOWN_SPI: "unknown_spi",
|
ERROR_MESSAGE_UNKNOWN_SPI: "unknown_spi",
|
||||||
ERROR_MESSAGE_INVALID_ID: "invalid_id",
|
ERROR_MESSAGE_INVALID_ID: "invalid_id",
|
||||||
ERROR_MESSAGE_INVALID_PARAMETERS: "invalid_parameters",
|
ERROR_MESSAGE_INVALID_PARAMETERS: "invalid_parameters",
|
||||||
|
ERROR_MESSAGE_INVALID_USERNAME_FOR_CHECK_USERNAME_AVAILABILITY: "invalid_username",
|
||||||
|
ERROR_MESSAGE_INVALID_USERNAME_FOR_SIGNUP: "invalid_username",
|
||||||
ERROR_MESSAGE_INVALID_EMAIL_FOR_SIGNUP: "invalid_email",
|
ERROR_MESSAGE_INVALID_EMAIL_FOR_SIGNUP: "invalid_email",
|
||||||
ERROR_MESSAGE_INVALID_PASSWORD_FOR_SIGNUP: "invalid_password",
|
ERROR_MESSAGE_INVALID_PASSWORD_FOR_SIGNUP: "invalid_password",
|
||||||
ERROR_MESSAGE_INVALID_EMAIL_FOR_VERIFY: "invalid_email",
|
ERROR_MESSAGE_INVALID_EMAIL_FOR_VERIFY: "invalid_email",
|
||||||
|
|
|
@ -8,6 +8,7 @@ type IApi interface {
|
||||||
//API Methods
|
//API Methods
|
||||||
SystemCall(*SystemCallRequest) (*SystemCallResult, error)
|
SystemCall(*SystemCallRequest) (*SystemCallResult, error)
|
||||||
Echo(*EchoRequest) (*EchoResult, error)
|
Echo(*EchoRequest) (*EchoResult, error)
|
||||||
|
CheckUsernameAvailability(*CheckUsernameAvailabilityRequest) (*CheckUsernameAvailabilityResult, error)
|
||||||
Signup(*SignupRequest) (*SignupResult, error)
|
Signup(*SignupRequest) (*SignupResult, error)
|
||||||
Verify(*VerifyRequest) (*VerifyResult, error)
|
Verify(*VerifyRequest) (*VerifyResult, error)
|
||||||
Login(*LoginRequest) (*LoginResult, error)
|
Login(*LoginRequest) (*LoginResult, error)
|
||||||
|
|
|
@ -12,6 +12,10 @@ const (
|
||||||
ECHO_REQUEST = 0x0541BD72
|
ECHO_REQUEST = 0x0541BD72
|
||||||
ECHO_RESULT = 0xAB2FF7D4
|
ECHO_RESULT = 0xAB2FF7D4
|
||||||
|
|
||||||
|
//CheckUsernameAvailabilityOperation
|
||||||
|
CHECK_USERNAME_AVAILABILITY_REQUEST = 0xA9501A55
|
||||||
|
CHECK_USERNAME_AVAILABILITY_RESULT = 0x067190FF
|
||||||
|
|
||||||
//SignupOperation
|
//SignupOperation
|
||||||
SIGNUP_REQUEST = 0x48DB23BF
|
SIGNUP_REQUEST = 0x48DB23BF
|
||||||
SIGNUP_RESULT = 0x83D062B4
|
SIGNUP_RESULT = 0x83D062B4
|
||||||
|
@ -85,6 +89,8 @@ var OPCODES = Opcodes{
|
||||||
0x00000000: "N/A",
|
0x00000000: "N/A",
|
||||||
0x0541BD72: "ECHO",
|
0x0541BD72: "ECHO",
|
||||||
0xAB2FF7D4: "Echo",
|
0xAB2FF7D4: "Echo",
|
||||||
|
0xA9501A55: "CHECK_USERNAME_AVAILABILITY",
|
||||||
|
0x067190FF: "CheckUsernameAvailability",
|
||||||
0x48DB23BF: "SIGNUP",
|
0x48DB23BF: "SIGNUP",
|
||||||
0x83D062B4: "Signup",
|
0x83D062B4: "Signup",
|
||||||
0x8B78F7F6: "VERIFY",
|
0x8B78F7F6: "VERIFY",
|
||||||
|
|
|
@ -56,6 +56,7 @@ type (
|
||||||
Filter(predicate SpiFilterPredicate) ISpiCollection
|
Filter(predicate SpiFilterPredicate) ISpiCollection
|
||||||
Map(predicate SpiMapPredicate) ISpiCollection
|
Map(predicate SpiMapPredicate) ISpiCollection
|
||||||
Echo(document IDocument, editor Identity) (IEchoResult, error)
|
Echo(document IDocument, editor Identity) (IEchoResult, error)
|
||||||
|
CheckUsernameAvailability(username string, editor Identity) (ICheckUsernameAvailabilityResult, error)
|
||||||
Signup(username string, email string, password string, editor Identity) (ISignupResult, error)
|
Signup(username string, email string, password string, editor Identity) (ISignupResult, error)
|
||||||
Verify(email string, token string, code string, editor Identity) (IVerifyResult, error)
|
Verify(email string, token string, code string, editor Identity) (IVerifyResult, error)
|
||||||
Login(email string, password string, editor Identity) (ILoginResult, error)
|
Login(email string, password string, editor Identity) (ILoginResult, error)
|
||||||
|
@ -79,6 +80,10 @@ type (
|
||||||
Document() IDocument
|
Document() IDocument
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ICheckUsernameAvailabilityResult interface {
|
||||||
|
IsAvailable() bool
|
||||||
|
}
|
||||||
|
|
||||||
ISignupResult interface {
|
ISignupResult interface {
|
||||||
Token() string
|
Token() string
|
||||||
Code() string
|
Code() string
|
||||||
|
|
|
@ -258,6 +258,7 @@ type (
|
||||||
RemoveSpi(id int64, editor Identity) (ISpi, error)
|
RemoveSpi(id int64, editor Identity) (ISpi, error)
|
||||||
RemoveSpiAtomic(transaction ITransaction, id int64, editor Identity) (ISpi, error)
|
RemoveSpiAtomic(transaction ITransaction, id int64, editor Identity) (ISpi, error)
|
||||||
Echo(document IDocument, editor Identity) (IEchoResult, error)
|
Echo(document IDocument, editor Identity) (IEchoResult, error)
|
||||||
|
CheckUsernameAvailability(username string, editor Identity) (ICheckUsernameAvailabilityResult, error)
|
||||||
Signup(username string, email string, password string, editor Identity) (ISignupResult, error)
|
Signup(username string, email string, password string, editor Identity) (ISignupResult, error)
|
||||||
Verify(email string, token string, code string, editor Identity) (IVerifyResult, error)
|
Verify(email string, token string, code string, editor Identity) (IVerifyResult, error)
|
||||||
Login(email string, password string, editor Identity) (ILoginResult, error)
|
Login(email string, password string, editor Identity) (ILoginResult, error)
|
||||||
|
@ -294,6 +295,7 @@ type (
|
||||||
NewActivityPubFollower(id int64, handle string, inbox string, subject string, activity string, accepted bool) (IActivityPubFollower, error)
|
NewActivityPubFollower(id int64, handle string, inbox string, subject string, activity string, accepted bool) (IActivityPubFollower, error)
|
||||||
NewSpi() (ISpi, error)
|
NewSpi() (ISpi, error)
|
||||||
NewEchoResult(document IDocument, ignored interface{}) IEchoResult
|
NewEchoResult(document IDocument, ignored interface{}) IEchoResult
|
||||||
|
NewCheckUsernameAvailabilityResult(isAvailable bool, ignored interface{}) ICheckUsernameAvailabilityResult
|
||||||
NewSignupResult(token string, code string, ignored interface{}) ISignupResult
|
NewSignupResult(token string, code string, ignored interface{}) ISignupResult
|
||||||
NewVerifyResult(token string, ignored interface{}) IVerifyResult
|
NewVerifyResult(token string, ignored interface{}) IVerifyResult
|
||||||
NewLoginResult(username string, token string, ignored interface{}) ILoginResult
|
NewLoginResult(username string, token string, ignored interface{}) ILoginResult
|
||||||
|
|
|
@ -1033,6 +1033,7 @@ type IDispatcher interface {
|
||||||
// the transaction if used in an x.Atomic context. This method is synchronous.
|
// the transaction if used in an x.Atomic context. This method is synchronous.
|
||||||
RemoveSpi(id int64) ISpi
|
RemoveSpi(id int64) ISpi
|
||||||
Echo(document IDocument) (IEchoResult, error)
|
Echo(document IDocument) (IEchoResult, error)
|
||||||
|
CheckUsernameAvailability(username string) (ICheckUsernameAvailabilityResult, error)
|
||||||
Signup(username string, email string, password string) (ISignupResult, error)
|
Signup(username string, email string, password string) (ISignupResult, error)
|
||||||
Verify(email string, token string, code string) (IVerifyResult, error)
|
Verify(email string, token string, code string) (IVerifyResult, error)
|
||||||
Login(email string, password string) (ILoginResult, error)
|
Login(email string, password string) (ILoginResult, error)
|
||||||
|
@ -1121,6 +1122,8 @@ type IDispatcher interface {
|
||||||
NewSpis() ISpiCollection
|
NewSpis() ISpiCollection
|
||||||
// NewEchoResult creates a new result container for 'Echo' system action.
|
// NewEchoResult creates a new result container for 'Echo' system action.
|
||||||
NewEchoResult(document IDocument) IEchoResult
|
NewEchoResult(document IDocument) IEchoResult
|
||||||
|
// NewCheckUsernameAvailabilityResult creates a new result container for 'Check Username Availability' system action.
|
||||||
|
NewCheckUsernameAvailabilityResult(isAvailable bool) ICheckUsernameAvailabilityResult
|
||||||
// NewSignupResult creates a new result container for 'Signup' system action.
|
// NewSignupResult creates a new result container for 'Signup' system action.
|
||||||
NewSignupResult(token string, code string) ISignupResult
|
NewSignupResult(token string, code string) ISignupResult
|
||||||
// NewVerifyResult creates a new result container for 'Verify' system action.
|
// NewVerifyResult creates a new result container for 'Verify' system action.
|
||||||
|
|
|
@ -25,6 +25,16 @@ func (api *api) Echo(request *EchoRequest) (*EchoResult, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *api) CheckUsernameAvailability(request *CheckUsernameAvailabilityRequest) (*CheckUsernameAvailabilityResult, error) {
|
||||||
|
result, err := api.call(CHECK_USERNAME_AVAILABILITY_REQUEST, request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*CheckUsernameAvailabilityResult), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (api *api) Signup(request *SignupRequest) (*SignupResult, error) {
|
func (api *api) Signup(request *SignupRequest) (*SignupResult, error) {
|
||||||
result, err := api.call(SIGNUP_REQUEST, request)
|
result, err := api.call(SIGNUP_REQUEST, request)
|
||||||
|
|
||||||
|
@ -198,6 +208,7 @@ func (api *api) GetInbox(request *GetInboxRequest) (*GetInboxResult, error) {
|
||||||
func init() {
|
func init() {
|
||||||
API_RESULT[SYSTEM_CALL_RESULT] = SystemCallResult{}
|
API_RESULT[SYSTEM_CALL_RESULT] = SystemCallResult{}
|
||||||
API_RESULT[ECHO_RESULT] = EchoResult{}
|
API_RESULT[ECHO_RESULT] = EchoResult{}
|
||||||
|
API_RESULT[CHECK_USERNAME_AVAILABILITY_RESULT] = CheckUsernameAvailabilityResult{}
|
||||||
API_RESULT[SIGNUP_RESULT] = SignupResult{}
|
API_RESULT[SIGNUP_RESULT] = SignupResult{}
|
||||||
API_RESULT[VERIFY_RESULT] = VerifyResult{}
|
API_RESULT[VERIFY_RESULT] = VerifyResult{}
|
||||||
API_RESULT[LOGIN_RESULT] = LoginResult{}
|
API_RESULT[LOGIN_RESULT] = LoginResult{}
|
||||||
|
|
|
@ -1099,6 +1099,10 @@ func (conductor *conductor) Echo(document IDocument, editor Identity) (IEchoResu
|
||||||
return conductor.spiManager.Echo(document, editor)
|
return conductor.spiManager.Echo(document, editor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (conductor *conductor) CheckUsernameAvailability(username string, editor Identity) (ICheckUsernameAvailabilityResult, error) {
|
||||||
|
return conductor.spiManager.CheckUsernameAvailability(username, editor)
|
||||||
|
}
|
||||||
|
|
||||||
func (conductor *conductor) Signup(username string, email string, password string, editor Identity) (ISignupResult, error) {
|
func (conductor *conductor) Signup(username string, email string, password string, editor Identity) (ISignupResult, error) {
|
||||||
return conductor.spiManager.Signup(username, email, password, editor)
|
return conductor.spiManager.Signup(username, email, password, editor)
|
||||||
}
|
}
|
||||||
|
@ -1239,6 +1243,10 @@ func (conductor *conductor) NewEchoResult(document IDocument, _ interface{}) IEc
|
||||||
return NewEchoResult(document, nil)
|
return NewEchoResult(document, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (conductor *conductor) NewCheckUsernameAvailabilityResult(isAvailable bool, _ interface{}) ICheckUsernameAvailabilityResult {
|
||||||
|
return NewCheckUsernameAvailabilityResult(isAvailable, nil)
|
||||||
|
}
|
||||||
|
|
||||||
func (conductor *conductor) NewSignupResult(token string, code string, _ interface{}) ISignupResult {
|
func (conductor *conductor) NewSignupResult(token string, code string, _ interface{}) ISignupResult {
|
||||||
return NewSignupResult(token, code, nil)
|
return NewSignupResult(token, code, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,6 +256,10 @@ func (dispatcher *dispatcher) Echo(document IDocument) (IEchoResult, error) {
|
||||||
return dispatcher.conductor.SpiManager().Echo(document, dispatcher.identity)
|
return dispatcher.conductor.SpiManager().Echo(document, dispatcher.identity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dispatcher *dispatcher) CheckUsernameAvailability(username string) (ICheckUsernameAvailabilityResult, error) {
|
||||||
|
return dispatcher.conductor.SpiManager().CheckUsernameAvailability(username, dispatcher.identity)
|
||||||
|
}
|
||||||
|
|
||||||
func (dispatcher *dispatcher) Signup(username string, email string, password string) (ISignupResult, error) {
|
func (dispatcher *dispatcher) Signup(username string, email string, password string) (ISignupResult, error) {
|
||||||
return dispatcher.conductor.SpiManager().Signup(username, email, password, dispatcher.identity)
|
return dispatcher.conductor.SpiManager().Signup(username, email, password, dispatcher.identity)
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,6 +231,45 @@ func (manager *spiManager) Echo(document IDocument, editor Identity) (result IEc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//region ICheckUsernameAvailabilityResult Implementation
|
||||||
|
|
||||||
|
type checkUsernameAvailabilityResult struct {
|
||||||
|
isAvailable bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCheckUsernameAvailabilityResult(isAvailable bool, _ interface{}) ICheckUsernameAvailabilityResult {
|
||||||
|
return &checkUsernameAvailabilityResult{
|
||||||
|
isAvailable: isAvailable,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (result checkUsernameAvailabilityResult) IsAvailable() bool {
|
||||||
|
return result.isAvailable
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
func (manager *spiManager) CheckUsernameAvailability(username string, editor Identity) (result ICheckUsernameAvailabilityResult, err error) {
|
||||||
|
if !validators.UsernameIsValid(username) {
|
||||||
|
return nil, ERROR_INVALID_USERNAME_FOR_CHECK_USERNAME_AVAILABILITY
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if reason := recover(); reason != nil {
|
||||||
|
err = manager.Error(reason)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
editor.Lock(CHECK_USERNAME_AVAILABILITY_REQUEST)
|
||||||
|
defer editor.Unlock(CHECK_USERNAME_AVAILABILITY_REQUEST)
|
||||||
|
|
||||||
|
if result, err = commands.CheckUsernameAvailability(NewDispatcher(Conductor, editor), username); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//region ISignupResult Implementation
|
//region ISignupResult Implementation
|
||||||
|
|
||||||
type signupResult struct {
|
type signupResult struct {
|
||||||
|
@ -264,6 +303,10 @@ func (manager *spiManager) Signup(username string, email string, password string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !validators.UsernameIsValid(username) {
|
||||||
|
return nil, ERROR_INVALID_USERNAME_FOR_SIGNUP
|
||||||
|
}
|
||||||
|
|
||||||
if !validators.PasswordIsValid(password) {
|
if !validators.PasswordIsValid(password) {
|
||||||
return nil, ERROR_INVALID_PASSWORD_FOR_SIGNUP
|
return nil, ERROR_INVALID_PASSWORD_FOR_SIGNUP
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,6 +160,17 @@ func TestSpiManager_Echo(test *testing.T) {
|
||||||
_ = result
|
_ = result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSpiManager_CheckUsernameAvailability(test *testing.T) {
|
||||||
|
manager := Conductor.SpiManager()
|
||||||
|
|
||||||
|
result, err := manager.CheckUsernameAvailability("username", nil)
|
||||||
|
if err != nil {
|
||||||
|
test.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = result
|
||||||
|
}
|
||||||
|
|
||||||
func TestSpiManager_Signup(test *testing.T) {
|
func TestSpiManager_Signup(test *testing.T) {
|
||||||
manager := Conductor.SpiManager()
|
manager := Conductor.SpiManager()
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,10 @@ func (dispatcher *dispatcher) NewEchoResult(document IDocument) IEchoResult {
|
||||||
return NewEchoResult(document, nil)
|
return NewEchoResult(document, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dispatcher *dispatcher) NewCheckUsernameAvailabilityResult(isAvailable bool) ICheckUsernameAvailabilityResult {
|
||||||
|
return NewCheckUsernameAvailabilityResult(isAvailable, nil)
|
||||||
|
}
|
||||||
|
|
||||||
func (dispatcher *dispatcher) NewSignupResult(token string, code string) ISignupResult {
|
func (dispatcher *dispatcher) NewSignupResult(token string, code string) ISignupResult {
|
||||||
return NewSignupResult(token, code, nil)
|
return NewSignupResult(token, code, nil)
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue