mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 01:34:24 +08:00
add user-friendly error
This commit is contained in:
@@ -151,6 +151,8 @@ func startWebServer(c *cli.Context) error {
|
|||||||
|
|
||||||
if config.EnableUserRegister {
|
if config.EnableUserRegister {
|
||||||
apiRoute.POST("/register.json", bindApi(api.Users.UserRegisterHandler))
|
apiRoute.POST("/register.json", bindApi(api.Users.UserRegisterHandler))
|
||||||
|
} else {
|
||||||
|
apiRoute.POST("/register.json", bindApi(api.Users.UserRegistrationNotAllowed))
|
||||||
}
|
}
|
||||||
|
|
||||||
apiRoute.GET("/logout.json", bindApi(api.Tokens.TokenRevokeCurrentHandler))
|
apiRoute.GET("/logout.json", bindApi(api.Tokens.TokenRevokeCurrentHandler))
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/mayswind/lab/pkg/log"
|
"github.com/mayswind/lab/pkg/log"
|
||||||
"github.com/mayswind/lab/pkg/models"
|
"github.com/mayswind/lab/pkg/models"
|
||||||
"github.com/mayswind/lab/pkg/services"
|
"github.com/mayswind/lab/pkg/services"
|
||||||
|
"github.com/mayswind/lab/pkg/settings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UsersApi represents user api
|
// UsersApi represents user api
|
||||||
@@ -27,6 +28,10 @@ var (
|
|||||||
|
|
||||||
// UserRegisterHandler saves a new user by request parameters
|
// UserRegisterHandler saves a new user by request parameters
|
||||||
func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Error) {
|
func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||||
|
if !settings.Container.Current.EnableUserRegister {
|
||||||
|
return a.UserRegistrationNotAllowed(c)
|
||||||
|
}
|
||||||
|
|
||||||
var userRegisterReq models.UserRegisterRequest
|
var userRegisterReq models.UserRegisterRequest
|
||||||
err := c.ShouldBindJSON(&userRegisterReq)
|
err := c.ShouldBindJSON(&userRegisterReq)
|
||||||
|
|
||||||
@@ -76,6 +81,11 @@ func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Erro
|
|||||||
return authResp, nil
|
return authResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UserRegistrationNotAllowed returns user registration not allowed error
|
||||||
|
func (a *UsersApi) UserRegistrationNotAllowed(c *core.Context) (interface{}, *errs.Error) {
|
||||||
|
return nil, errs.ErrUserRegistrationNotAllowed
|
||||||
|
}
|
||||||
|
|
||||||
// UserProfileHandler returns user profile of current user
|
// UserProfileHandler returns user profile of current user
|
||||||
func (a *UsersApi) UserProfileHandler(c *core.Context) (interface{}, *errs.Error) {
|
func (a *UsersApi) UserProfileHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||||
uid := c.GetCurrentUid()
|
uid := c.GetCurrentUid()
|
||||||
|
|||||||
@@ -17,4 +17,5 @@ var (
|
|||||||
ErrUserPasswordWrong = NewNormalError(NormalSubcategoryUser, 8, http.StatusBadRequest, "password is wrong")
|
ErrUserPasswordWrong = NewNormalError(NormalSubcategoryUser, 8, http.StatusBadRequest, "password is wrong")
|
||||||
ErrUsernameAlreadyExists = NewNormalError(NormalSubcategoryUser, 9, http.StatusBadRequest, "username already exists")
|
ErrUsernameAlreadyExists = NewNormalError(NormalSubcategoryUser, 9, http.StatusBadRequest, "username already exists")
|
||||||
ErrUserEmailAlreadyExists = NewNormalError(NormalSubcategoryUser, 10, http.StatusBadRequest, "email already exists")
|
ErrUserEmailAlreadyExists = NewNormalError(NormalSubcategoryUser, 10, http.StatusBadRequest, "email already exists")
|
||||||
|
ErrUserRegistrationNotAllowed = NewNormalError(NormalSubcategoryUser, 11, http.StatusBadRequest, "user registration not allowed")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -302,6 +302,7 @@ export default {
|
|||||||
'password is wrong': 'Password is wrong',
|
'password is wrong': 'Password is wrong',
|
||||||
'username already exists': 'Username already exists',
|
'username already exists': 'Username already exists',
|
||||||
'email already exists': 'Email already exists',
|
'email already exists': 'Email already exists',
|
||||||
|
'user registration not allowed': 'User registration is not allowed',
|
||||||
'login name is invalid': 'Login name is invalid',
|
'login name is invalid': 'Login name is invalid',
|
||||||
'login name or password is invalid': 'Login name or password is invalid',
|
'login name or password is invalid': 'Login name or password is invalid',
|
||||||
'login name or password is wrong': 'Login name or password is wrong',
|
'login name or password is wrong': 'Login name or password is wrong',
|
||||||
|
|||||||
@@ -302,6 +302,7 @@ export default {
|
|||||||
'password is wrong': '密码错误',
|
'password is wrong': '密码错误',
|
||||||
'username already exists': '用户名已经存在',
|
'username already exists': '用户名已经存在',
|
||||||
'email already exists': '邮箱已经存在',
|
'email already exists': '邮箱已经存在',
|
||||||
|
'user registration not allowed': '不允许用户注册',
|
||||||
'login name is invalid': '登录名无效',
|
'login name is invalid': '登录名无效',
|
||||||
'login name or password is invalid': '登录名或密码无效',
|
'login name or password is invalid': '登录名或密码无效',
|
||||||
'login name or password is wrong': '登录名或密码错误',
|
'login name or password is wrong': '登录名或密码错误',
|
||||||
|
|||||||
Reference in New Issue
Block a user