add comments
This commit is contained in:
@@ -11,16 +11,19 @@ import (
|
||||
"github.com/mayswind/lab/pkg/validators"
|
||||
)
|
||||
|
||||
// AccountsApi represents account api
|
||||
type AccountsApi struct {
|
||||
accounts *services.AccountService
|
||||
}
|
||||
|
||||
// Initialize an account api singleton instance
|
||||
var (
|
||||
Accounts = &AccountsApi{
|
||||
accounts: services.Accounts,
|
||||
}
|
||||
)
|
||||
|
||||
// AccountListHandler returns accounts list of current user
|
||||
func (a *AccountsApi) AccountListHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var accountListReq models.AccountListRequest
|
||||
err := c.ShouldBindQuery(&accountListReq)
|
||||
@@ -80,6 +83,7 @@ func (a *AccountsApi) AccountListHandler(c *core.Context) (interface{}, *errs.Er
|
||||
return userFinalAccountResps, nil
|
||||
}
|
||||
|
||||
// AccountGetHandler returns one specific account of current user
|
||||
func (a *AccountsApi) AccountGetHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var accountGetReq models.AccountGetRequest
|
||||
err := c.ShouldBindQuery(&accountGetReq)
|
||||
@@ -122,6 +126,7 @@ func (a *AccountsApi) AccountGetHandler(c *core.Context) (interface{}, *errs.Err
|
||||
return accountResp, nil
|
||||
}
|
||||
|
||||
// AccountCreateHandler saves a new account by request parameters for current user
|
||||
func (a *AccountsApi) AccountCreateHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var accountCreateReq models.AccountCreateRequest
|
||||
err := c.ShouldBindJSON(&accountCreateReq)
|
||||
@@ -203,6 +208,7 @@ func (a *AccountsApi) AccountCreateHandler(c *core.Context) (interface{}, *errs.
|
||||
return accountInfoResp, nil
|
||||
}
|
||||
|
||||
// AccountModifyHandler saves an existed account by request parameters for current user
|
||||
func (a *AccountsApi) AccountModifyHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var accountModifyReq models.AccountModifyRequest
|
||||
err := c.ShouldBindJSON(&accountModifyReq)
|
||||
@@ -276,6 +282,7 @@ func (a *AccountsApi) AccountModifyHandler(c *core.Context) (interface{}, *errs.
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AccountHideHandler hides an existed account by request parameters for current user
|
||||
func (a *AccountsApi) AccountHideHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var accountHideReq models.AccountHideRequest
|
||||
err := c.ShouldBindJSON(&accountHideReq)
|
||||
@@ -297,6 +304,7 @@ func (a *AccountsApi) AccountHideHandler(c *core.Context) (interface{}, *errs.Er
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AccountMoveHandler moves display order of existed accounts by request parameters for current user
|
||||
func (a *AccountsApi) AccountMoveHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var accountMoveReq models.AccountMoveRequest
|
||||
err := c.ShouldBindJSON(&accountMoveReq)
|
||||
@@ -331,6 +339,7 @@ func (a *AccountsApi) AccountMoveHandler(c *core.Context) (interface{}, *errs.Er
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AccountDeleteHandler deletes an existed account by request parameters for current user
|
||||
func (a *AccountsApi) AccountDeleteHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var accountDeleteReq models.AccountDeleteRequest
|
||||
err := c.ShouldBindJSON(&accountDeleteReq)
|
||||
|
||||
@@ -10,12 +10,14 @@ import (
|
||||
"github.com/mayswind/lab/pkg/services"
|
||||
)
|
||||
|
||||
// AuthorizationsApi represents authorization api
|
||||
type AuthorizationsApi struct {
|
||||
users *services.UserService
|
||||
tokens *services.TokenService
|
||||
twoFactorAuthorizations *services.TwoFactorAuthorizationService
|
||||
}
|
||||
|
||||
// Initialize a authorization api singleton instance
|
||||
var (
|
||||
Authorizations = &AuthorizationsApi{
|
||||
users: services.Users,
|
||||
@@ -24,6 +26,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// AuthorizeHandler verifies and authorizes current login request
|
||||
func (a *AuthorizationsApi) AuthorizeHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var credential models.UserLoginRequest
|
||||
err := c.ShouldBindJSON(&credential)
|
||||
@@ -79,6 +82,7 @@ func (a *AuthorizationsApi) AuthorizeHandler(c *core.Context) (interface{}, *err
|
||||
return authResp, nil
|
||||
}
|
||||
|
||||
// TwoFactorAuthorizeHandler verifies and authorizes current 2fa login by passcode
|
||||
func (a *AuthorizationsApi) TwoFactorAuthorizeHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var credential models.TwoFactorLoginRequest
|
||||
err := c.ShouldBindJSON(&credential)
|
||||
@@ -130,6 +134,7 @@ func (a *AuthorizationsApi) TwoFactorAuthorizeHandler(c *core.Context) (interfac
|
||||
return authResp, nil
|
||||
}
|
||||
|
||||
// TwoFactorAuthorizeByRecoveryCodeHandler verifies and authorizes current 2fa login by recovery code
|
||||
func (a *AuthorizationsApi) TwoFactorAuthorizeByRecoveryCodeHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var credential models.TwoFactorRecoveryCodeLoginRequest
|
||||
err := c.ShouldBindJSON(&credential)
|
||||
|
||||
@@ -5,16 +5,20 @@ import (
|
||||
"github.com/mayswind/lab/pkg/errs"
|
||||
)
|
||||
|
||||
// DefaultApi represents default api
|
||||
type DefaultApi struct{}
|
||||
|
||||
// Initialize a default api singleton instance
|
||||
var (
|
||||
Default = &DefaultApi{}
|
||||
)
|
||||
|
||||
// ApiNotFound returns api not found error
|
||||
func (a *DefaultApi) ApiNotFound(c *core.Context) (interface{}, *errs.Error) {
|
||||
return nil, errs.ErrApiNotFound
|
||||
}
|
||||
|
||||
// MethodNotAllowed returns method not allowed error
|
||||
func (a *DefaultApi) MethodNotAllowed(c *core.Context) (interface{}, *errs.Error) {
|
||||
return nil, errs.ErrMethodNotAllowed
|
||||
}
|
||||
|
||||
@@ -11,14 +11,18 @@ import (
|
||||
"github.com/mayswind/lab/pkg/models"
|
||||
)
|
||||
|
||||
// EuroCentralBankExchangeRateUrl represents euro central bank exchange rate date url
|
||||
const EuroCentralBankExchangeRateUrl = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
|
||||
|
||||
// ExchangeRatesApi represents exchange rate api
|
||||
type ExchangeRatesApi struct{}
|
||||
|
||||
// Initialize a exchange rate api singleton instance
|
||||
var (
|
||||
ExchangeRates = &ExchangeRatesApi{}
|
||||
)
|
||||
|
||||
// LatestExchangeRateHandler returns latest exchange rate data
|
||||
func (a *ExchangeRatesApi) LatestExchangeRateHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
uid := c.GetCurrentUid()
|
||||
resp, err := http.Get(EuroCentralBankExchangeRateUrl)
|
||||
|
||||
@@ -11,11 +11,13 @@ import (
|
||||
"github.com/mayswind/lab/pkg/utils"
|
||||
)
|
||||
|
||||
// TokensApi represents token api
|
||||
type TokensApi struct {
|
||||
tokens *services.TokenService
|
||||
users *services.UserService
|
||||
}
|
||||
|
||||
// Initialize a token api singleton instance
|
||||
var (
|
||||
Tokens = &TokensApi{
|
||||
tokens: services.Tokens,
|
||||
@@ -23,6 +25,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// TokenListHandler returns available token list of current user
|
||||
func (a *TokensApi) TokenListHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
uid := c.GetCurrentUid()
|
||||
tokens, err := a.tokens.GetAllUnexpiredNormalTokensByUid(uid)
|
||||
@@ -57,6 +60,7 @@ func (a *TokensApi) TokenListHandler(c *core.Context) (interface{}, *errs.Error)
|
||||
return tokenResps, nil
|
||||
}
|
||||
|
||||
// TokenRevokeCurrentHandler revokes current token of current user
|
||||
func (a *TokensApi) TokenRevokeCurrentHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
_, claims, err := a.tokens.ParseToken(c)
|
||||
|
||||
@@ -96,6 +100,7 @@ func (a *TokensApi) TokenRevokeCurrentHandler(c *core.Context) (interface{}, *er
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// TokenRevokeHandler revokes specific token of current user
|
||||
func (a *TokensApi) TokenRevokeHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var tokenRevokeReq models.TokenRevokeRequest
|
||||
err := c.ShouldBindJSON(&tokenRevokeReq)
|
||||
@@ -133,6 +138,7 @@ func (a *TokensApi) TokenRevokeHandler(c *core.Context) (interface{}, *errs.Erro
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// TokenRevokeAllHandler revokes all tokens of current user except current token
|
||||
func (a *TokensApi) TokenRevokeAllHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
uid := c.GetCurrentUid()
|
||||
tokens, err := a.tokens.GetAllTokensByUid(uid)
|
||||
@@ -167,6 +173,7 @@ func (a *TokensApi) TokenRevokeAllHandler(c *core.Context) (interface{}, *errs.E
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// TokenRefreshHandler refresh current token of current user
|
||||
func (a *TokensApi) TokenRefreshHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
uid := c.GetCurrentUid()
|
||||
user, err := a.users.GetUserById(uid)
|
||||
|
||||
@@ -10,16 +10,19 @@ import (
|
||||
"github.com/mayswind/lab/pkg/services"
|
||||
)
|
||||
|
||||
// TransactionCategoriesApi represents transaction category api
|
||||
type TransactionCategoriesApi struct {
|
||||
categories *services.TransactionCategoryService
|
||||
}
|
||||
|
||||
// Initialize a transaction category api singleton instance
|
||||
var (
|
||||
TransactionCategories = &TransactionCategoriesApi{
|
||||
categories: services.TransactionCategories,
|
||||
}
|
||||
)
|
||||
|
||||
// CategoryListHandler returns transaction category list of current user
|
||||
func (a *TransactionCategoriesApi) CategoryListHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var categoryListReq models.TransactionCategoryListRequest
|
||||
err := c.ShouldBindQuery(&categoryListReq)
|
||||
@@ -40,6 +43,7 @@ func (a *TransactionCategoriesApi) CategoryListHandler(c *core.Context) (interfa
|
||||
return a.getTransactionCategoryListByTypeResponse(categories, categoryListReq.ParentId)
|
||||
}
|
||||
|
||||
// CategoryGetHandler returns one specific transaction category of current user
|
||||
func (a *TransactionCategoriesApi) CategoryGetHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var categoryGetReq models.TransactionCategoryGetRequest
|
||||
err := c.ShouldBindQuery(&categoryGetReq)
|
||||
@@ -62,6 +66,7 @@ func (a *TransactionCategoriesApi) CategoryGetHandler(c *core.Context) (interfac
|
||||
return categoryResp, nil
|
||||
}
|
||||
|
||||
// CategoryCreateHandler saves a new transaction category by request parameters for current user
|
||||
func (a *TransactionCategoriesApi) CategoryCreateHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var categoryCreateReq models.TransactionCategoryCreateRequest
|
||||
err := c.ShouldBindJSON(&categoryCreateReq)
|
||||
@@ -126,6 +131,7 @@ func (a *TransactionCategoriesApi) CategoryCreateHandler(c *core.Context) (inter
|
||||
return categoryResp, nil
|
||||
}
|
||||
|
||||
// CategoryCreateBatchHandler saves some new transaction category by request parameters for current user
|
||||
func (a *TransactionCategoriesApi) CategoryCreateBatchHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var categoryCreateBatchReq models.TransactionCategoryCreateBatchRequest
|
||||
err := c.ShouldBindJSON(&categoryCreateBatchReq)
|
||||
@@ -187,6 +193,7 @@ func (a *TransactionCategoriesApi) CategoryCreateBatchHandler(c *core.Context) (
|
||||
return a.getTransactionCategoryListByTypeResponse(categories, 0)
|
||||
}
|
||||
|
||||
// CategoryModifyHandler saves an existed transaction category by request parameters for current user
|
||||
func (a *TransactionCategoriesApi) CategoryModifyHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var categoryModifyReq models.TransactionCategoryModifyRequest
|
||||
err := c.ShouldBindJSON(&categoryModifyReq)
|
||||
@@ -234,6 +241,7 @@ func (a *TransactionCategoriesApi) CategoryModifyHandler(c *core.Context) (inter
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// CategoryHideHandler hides an existed transaction category by request parameters for current user
|
||||
func (a *TransactionCategoriesApi) CategoryHideHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var categoryHideReq models.TransactionCategoryHideRequest
|
||||
err := c.ShouldBindJSON(&categoryHideReq)
|
||||
@@ -255,6 +263,7 @@ func (a *TransactionCategoriesApi) CategoryHideHandler(c *core.Context) (interfa
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// CategoryMoveHandler moves display order of existed transaction categories by request parameters for current user
|
||||
func (a *TransactionCategoriesApi) CategoryMoveHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var categoryMoveReq models.TransactionCategoryMoveRequest
|
||||
err := c.ShouldBindJSON(&categoryMoveReq)
|
||||
@@ -289,6 +298,7 @@ func (a *TransactionCategoriesApi) CategoryMoveHandler(c *core.Context) (interfa
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// CategoryDeleteHandler deletes an existed transaction category by request parameters for current user
|
||||
func (a *TransactionCategoriesApi) CategoryDeleteHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var categoryDeleteReq models.TransactionCategoryDeleteRequest
|
||||
err := c.ShouldBindJSON(&categoryDeleteReq)
|
||||
|
||||
@@ -10,16 +10,19 @@ import (
|
||||
"github.com/mayswind/lab/pkg/services"
|
||||
)
|
||||
|
||||
// TransactionTagsApi represents transaction tag api
|
||||
type TransactionTagsApi struct {
|
||||
tags *services.TransactionTagService
|
||||
}
|
||||
|
||||
// Initialize a transaction tag api singleton instance
|
||||
var (
|
||||
TransactionTags = &TransactionTagsApi{
|
||||
tags: services.TransactionTags,
|
||||
}
|
||||
)
|
||||
|
||||
// TagListHandler returns transaction tag list of current user
|
||||
func (a *TransactionTagsApi) TagListHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
uid := c.GetCurrentUid()
|
||||
tags, err := a.tags.GetAllTagsByUid(uid)
|
||||
@@ -40,6 +43,7 @@ func (a *TransactionTagsApi) TagListHandler(c *core.Context) (interface{}, *errs
|
||||
return tagResps, nil
|
||||
}
|
||||
|
||||
// TagGetHandler returns one specific transaction tag of current user
|
||||
func (a *TransactionTagsApi) TagGetHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var tagGetReq models.TransactionTagGetRequest
|
||||
err := c.ShouldBindQuery(&tagGetReq)
|
||||
@@ -62,6 +66,7 @@ func (a *TransactionTagsApi) TagGetHandler(c *core.Context) (interface{}, *errs.
|
||||
return tagResp, nil
|
||||
}
|
||||
|
||||
// TagCreateHandler saves a new transaction tag by request parameters for current user
|
||||
func (a *TransactionTagsApi) TagCreateHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var tagCreateReq models.TransactionTagCreateRequest
|
||||
err := c.ShouldBindJSON(&tagCreateReq)
|
||||
@@ -96,6 +101,7 @@ func (a *TransactionTagsApi) TagCreateHandler(c *core.Context) (interface{}, *er
|
||||
return tagResp, nil
|
||||
}
|
||||
|
||||
// TagModifyHandler saves an existed transaction tag by request parameters for current user
|
||||
func (a *TransactionTagsApi) TagModifyHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var tagModifyReq models.TransactionTagModifyRequest
|
||||
err := c.ShouldBindJSON(&tagModifyReq)
|
||||
@@ -138,6 +144,7 @@ func (a *TransactionTagsApi) TagModifyHandler(c *core.Context) (interface{}, *er
|
||||
return tagResp, nil
|
||||
}
|
||||
|
||||
// TagHideHandler hides an transaction tag by request parameters for current user
|
||||
func (a *TransactionTagsApi) TagHideHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var tagHideReq models.TransactionTagHideRequest
|
||||
err := c.ShouldBindJSON(&tagHideReq)
|
||||
@@ -159,6 +166,7 @@ func (a *TransactionTagsApi) TagHideHandler(c *core.Context) (interface{}, *errs
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// TagMoveHandler moves display order of existed transaction tags by request parameters for current user
|
||||
func (a *TransactionTagsApi) TagMoveHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var tagMoveReq models.TransactionTagMoveRequest
|
||||
err := c.ShouldBindJSON(&tagMoveReq)
|
||||
@@ -193,6 +201,7 @@ func (a *TransactionTagsApi) TagMoveHandler(c *core.Context) (interface{}, *errs
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// TagDeleteHandler deletes an existed transaction tag by request parameters for current user
|
||||
func (a *TransactionTagsApi) TagDeleteHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var tagDeleteReq models.TransactionTagDeleteRequest
|
||||
err := c.ShouldBindJSON(&tagDeleteReq)
|
||||
|
||||
@@ -11,11 +11,13 @@ import (
|
||||
"github.com/mayswind/lab/pkg/utils"
|
||||
)
|
||||
|
||||
// TransactionsApi represents transaction api
|
||||
type TransactionsApi struct {
|
||||
transactions *services.TransactionService
|
||||
transactionTags *services.TransactionTagService
|
||||
}
|
||||
|
||||
// Initialize a transaction api singleton instance
|
||||
var (
|
||||
Transactions = &TransactionsApi{
|
||||
transactions: services.Transactions,
|
||||
@@ -23,6 +25,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// TransactionListHandler returns transaction list of current user
|
||||
func (a *TransactionsApi) TransactionListHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var transactionListReq models.TransactionListByMaxTimeRequest
|
||||
err := c.ShouldBindQuery(&transactionListReq)
|
||||
@@ -76,6 +79,7 @@ func (a *TransactionsApi) TransactionListHandler(c *core.Context) (interface{},
|
||||
return transactionResps, nil
|
||||
}
|
||||
|
||||
// TransactionMonthListHandler returns transaction list of current user by month
|
||||
func (a *TransactionsApi) TransactionMonthListHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var transactionListReq models.TransactionListInMonthByPageRequest
|
||||
err := c.ShouldBindQuery(&transactionListReq)
|
||||
@@ -116,6 +120,7 @@ func (a *TransactionsApi) TransactionMonthListHandler(c *core.Context) (interfac
|
||||
return transactionResps, nil
|
||||
}
|
||||
|
||||
// TransactionGetHandler returns one specific transaction of current user
|
||||
func (a *TransactionsApi) TransactionGetHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var transactionGetReq models.TransactionGetRequest
|
||||
err := c.ShouldBindQuery(&transactionGetReq)
|
||||
@@ -146,6 +151,7 @@ func (a *TransactionsApi) TransactionGetHandler(c *core.Context) (interface{}, *
|
||||
return transactionResp, nil
|
||||
}
|
||||
|
||||
// TransactionCreateHandler saves a new transaction by request parameters for current user
|
||||
func (a *TransactionsApi) TransactionCreateHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var transactionCreateReq models.TransactionCreateRequest
|
||||
err := c.ShouldBindJSON(&transactionCreateReq)
|
||||
@@ -195,6 +201,7 @@ func (a *TransactionsApi) TransactionCreateHandler(c *core.Context) (interface{}
|
||||
return transactionResp, nil
|
||||
}
|
||||
|
||||
// TransactionModifyHandler saves an existed transaction by request parameters for current user
|
||||
func (a *TransactionsApi) TransactionModifyHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var transactionModifyReq models.TransactionModifyRequest
|
||||
err := c.ShouldBindJSON(&transactionModifyReq)
|
||||
@@ -259,6 +266,7 @@ func (a *TransactionsApi) TransactionModifyHandler(c *core.Context) (interface{}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// TransactionDeleteHandler deletes an existed transaction by request parameters for current user
|
||||
func (a *TransactionsApi) TransactionDeleteHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var transactionDeleteReq models.TransactionDeleteRequest
|
||||
err := c.ShouldBindJSON(&transactionDeleteReq)
|
||||
|
||||
@@ -15,12 +15,14 @@ import (
|
||||
"github.com/mayswind/lab/pkg/services"
|
||||
)
|
||||
|
||||
// TwoFactorAuthorizationsApi represents 2fa api
|
||||
type TwoFactorAuthorizationsApi struct {
|
||||
twoFactorAuthorizations *services.TwoFactorAuthorizationService
|
||||
users *services.UserService
|
||||
tokens *services.TokenService
|
||||
}
|
||||
|
||||
// Initialize a 2fa api singleton instance
|
||||
var (
|
||||
TwoFactorAuthorizations = &TwoFactorAuthorizationsApi{
|
||||
twoFactorAuthorizations: services.TwoFactorAuthorizations,
|
||||
@@ -29,6 +31,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// TwoFactorStatusHandler returns 2fa status of current user
|
||||
func (a *TwoFactorAuthorizationsApi) TwoFactorStatusHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
uid := c.GetCurrentUid()
|
||||
twoFactorSetting, err := a.twoFactorAuthorizations.GetUserTwoFactorSettingByUid(uid)
|
||||
@@ -54,6 +57,7 @@ func (a *TwoFactorAuthorizationsApi) TwoFactorStatusHandler(c *core.Context) (in
|
||||
return statusResp, nil
|
||||
}
|
||||
|
||||
// TwoFactorEnableRequestHandler returns a new 2fa secret and qr code for current user to set 2fa and verify passcode next
|
||||
func (a *TwoFactorAuthorizationsApi) TwoFactorEnableRequestHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
uid := c.GetCurrentUid()
|
||||
enabled, err := a.twoFactorAuthorizations.ExistsTwoFactorSetting(uid)
|
||||
@@ -105,6 +109,7 @@ func (a *TwoFactorAuthorizationsApi) TwoFactorEnableRequestHandler(c *core.Conte
|
||||
return enableResp, nil
|
||||
}
|
||||
|
||||
// TwoFactorEnableConfirmHandler enables 2fa for current user
|
||||
func (a *TwoFactorAuthorizationsApi) TwoFactorEnableConfirmHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var confirmReq models.TwoFactorEnableConfirmRequest
|
||||
err := c.ShouldBindJSON(&confirmReq)
|
||||
@@ -202,6 +207,7 @@ func (a *TwoFactorAuthorizationsApi) TwoFactorEnableConfirmHandler(c *core.Conte
|
||||
return confirmResp, nil
|
||||
}
|
||||
|
||||
// TwoFactorDisableHandler disables 2fa for current user
|
||||
func (a *TwoFactorAuthorizationsApi) TwoFactorDisableHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var disableReq models.TwoFactorDisableRequest
|
||||
err := c.ShouldBindJSON(&disableReq)
|
||||
@@ -256,6 +262,7 @@ func (a *TwoFactorAuthorizationsApi) TwoFactorDisableHandler(c *core.Context) (i
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// TwoFactorRecoveryCodeRegenerateHandler returns new 2fa recovery codes and revokes old recovery codes for current user
|
||||
func (a *TwoFactorAuthorizationsApi) TwoFactorRecoveryCodeRegenerateHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var regenerateReq models.TwoFactorRegenerateRecoveryCodeRequest
|
||||
err := c.ShouldBindJSON(®enerateReq)
|
||||
|
||||
@@ -11,11 +11,13 @@ import (
|
||||
"github.com/mayswind/lab/pkg/services"
|
||||
)
|
||||
|
||||
// UsersApi represents user api
|
||||
type UsersApi struct {
|
||||
users *services.UserService
|
||||
tokens *services.TokenService
|
||||
}
|
||||
|
||||
// Initialize a user api singleton instance
|
||||
var (
|
||||
Users = &UsersApi{
|
||||
users: services.Users,
|
||||
@@ -23,6 +25,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// UserRegisterHandler saves a new user by request parameters
|
||||
func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var userRegisterReq models.UserRegisterRequest
|
||||
err := c.ShouldBindJSON(&userRegisterReq)
|
||||
@@ -73,6 +76,7 @@ func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Erro
|
||||
return authResp, nil
|
||||
}
|
||||
|
||||
// UserProfileHandler returns user profile of current user
|
||||
func (a *UsersApi) UserProfileHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
uid := c.GetCurrentUid()
|
||||
user, err := a.users.GetUserById(uid)
|
||||
@@ -89,6 +93,7 @@ func (a *UsersApi) UserProfileHandler(c *core.Context) (interface{}, *errs.Error
|
||||
return userResp, nil
|
||||
}
|
||||
|
||||
// UserUpdateProfileHandler saves user profile by request parameters for current user
|
||||
func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var userUpdateReq models.UserProfileUpdateRequest
|
||||
err := c.ShouldBindJSON(&userUpdateReq)
|
||||
|
||||
Reference in New Issue
Block a user