Improve response message.

This commit is contained in:
Yang Luo 2021-03-28 08:59:12 +08:00
parent d6715c7601
commit 0127f8fb63
12 changed files with 28 additions and 29 deletions

View File

@ -64,7 +64,7 @@ func (c *ApiController) Register() {
var resp Response
if c.GetSessionUser() != "" {
resp = Response{Status: "error", Msg: "please log out first before signing up", Data: c.GetSessionUser()}
resp = Response{Status: "error", Msg: "Please log out first before signing up", Data: c.GetSessionUser()}
c.Data["json"] = resp
c.ServeJSON()
return
@ -95,7 +95,7 @@ func (c *ApiController) Register() {
//c.SetSessionUser(user)
util.LogInfo(c.Ctx, "API: [%s] is registered as new user", user)
resp = Response{Status: "ok", Msg: "注册成功", Data: user}
resp = Response{Status: "ok", Msg: "", Data: user}
}
c.Data["json"] = resp
@ -124,7 +124,7 @@ func (c *ApiController) GetAccount() {
var resp Response
if c.GetSessionUser() == "" {
resp = Response{Status: "error", Msg: "please sign in first", Data: c.GetSessionUser()}
resp = Response{Status: "error", Msg: "Please sign in first", Data: c.GetSessionUser()}
c.Data["json"] = resp
c.ServeJSON()
return
@ -145,7 +145,7 @@ func (c *ApiController) UploadAvatar() {
msg := object.CheckUserLogin(userObj.Owner+"/"+userObj.Name, c.Ctx.Request.Form.Get("password"))
if msg != "" {
resp = Response{Status: "error", Msg: "Password wrong"}
resp = Response{Status: "error", Msg: "Wrong password"}
c.Data["json"] = resp
c.ServeJSON()
return

View File

@ -48,7 +48,7 @@ func (c *ApiController) HandleLoggedIn(userId string, form *RequestForm) *Respon
code := object.GetOAuthCode(userId, clientId, responseType, redirectUri, scope, state)
resp = codeToResponse(code)
} else {
resp = &Response{Status: "error", Msg: fmt.Sprintf("unknown response type: %s", form.Type)}
resp = &Response{Status: "error", Msg: fmt.Sprintf("Unknown response type: %s", form.Type)}
}
return resp
}
@ -83,7 +83,7 @@ func (c *ApiController) Login() {
if form.Username != "" {
if form.Type == ResponseTypeLogin {
if c.GetSessionUser() != "" {
resp = &Response{Status: "error", Msg: "please log out first before signing in", Data: c.GetSessionUser()}
resp = &Response{Status: "error", Msg: "Please log out first before signing in", Data: c.GetSessionUser()}
c.Data["json"] = resp
c.ServeJSON()
return
@ -123,7 +123,7 @@ func (c *ApiController) Login() {
}
if !token.Valid() {
resp = &Response{Status: "error", Msg: "invalid token"}
resp = &Response{Status: "error", Msg: "Invalid token"}
c.Data["json"] = resp
c.ServeJSON()
return
@ -131,7 +131,7 @@ func (c *ApiController) Login() {
userInfo, err := idProvider.GetUserInfo(token)
if err != nil {
resp = &Response{Status: "error", Msg: "login failed, please try again."}
resp = &Response{Status: "error", Msg: fmt.Sprintf("Failed to login in: %s", err.Error())}
c.Data["json"] = resp
c.ServeJSON()
return
@ -159,12 +159,12 @@ func (c *ApiController) Login() {
//}
if !application.EnableSignUp {
resp = &Response{Status: "error", Msg: fmt.Sprintf("the account for provider: %s and username: %s does not exist and is not allowed to register as new account, please contact your IT support", provider.Type, userInfo.Username)}
resp = &Response{Status: "error", Msg: fmt.Sprintf("The account for provider: %s and username: %s does not exist and is not allowed to register as new account, please contact your IT support", provider.Type, userInfo.Username)}
c.Data["json"] = resp
c.ServeJSON()
return
} else {
resp = &Response{Status: "error", Msg: fmt.Sprintf("the account for provider: %s and username: %s does not exist, please register an account first", provider.Type, userInfo.Username)}
resp = &Response{Status: "error", Msg: fmt.Sprintf("The account for provider: %s and username: %s does not exist, please register an account first", provider.Type, userInfo.Username)}
c.Data["json"] = resp
c.ServeJSON()
return
@ -174,7 +174,7 @@ func (c *ApiController) Login() {
} else {
userId := c.GetSessionUser()
if userId == "" {
resp = &Response{Status: "error", Msg: "user doesn't exist", Data: userInfo}
resp = &Response{Status: "error", Msg: "The account does not exist", Data: userInfo}
c.Data["json"] = resp
c.ServeJSON()
return
@ -184,7 +184,7 @@ func (c *ApiController) Login() {
if isLinked {
resp = &Response{Status: "ok", Msg: "", Data: isLinked}
} else {
resp = &Response{Status: "error", Msg: "link account failed", Data: isLinked}
resp = &Response{Status: "error", Msg: "Failed to link user account", Data: isLinked}
}
//if len(object.GetMemberAvatar(userId)) == 0 {
// avatar := UploadAvatarToOSS(tempUserAccount.AvatarUrl, userId)

View File

@ -35,8 +35,8 @@ func (c *ApiController) SetSessionUser(user string) {
func wrapActionResponse(affected bool) *Response {
if affected {
return &Response{Status: "ok", Msg: "", Data: "affected"}
return &Response{Status: "ok", Msg: "", Data: "Affected"}
} else {
return &Response{Status: "ok", Msg: "", Data: "unaffected"}
return &Response{Status: "ok", Msg: "", Data: "Unaffected"}
}
}

View File

@ -129,7 +129,7 @@ func CheckOAuthLogin(clientId string, responseType string, redirectUri string, s
application := getApplicationByClientId(clientId)
if application == nil {
return "invalid client_id", nil
return "Invalid client_id", nil
}
validUri := false
@ -150,7 +150,7 @@ func GetOAuthCode(userId string, clientId string, responseType string, redirectU
user := GetUser(userId)
if user == nil {
return &Code{
Message: "invalid user_id",
Message: "Invalid user_id",
Code: "",
}
}
@ -191,7 +191,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
application := getApplicationByClientId(clientId)
if application == nil {
return &TokenWrapper{
AccessToken: "invalid client_id",
AccessToken: "Invalid client_id",
TokenType: "",
ExpiresIn: 0,
Scope: "",
@ -210,7 +210,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
token := getTokenByCode(code)
if token == nil {
return &TokenWrapper{
AccessToken: "invalid code",
AccessToken: "Invalid code",
TokenType: "",
ExpiresIn: 0,
Scope: "",
@ -219,7 +219,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
if application.Name != token.Application {
return &TokenWrapper{
AccessToken: "token is for wrong application (client_id)",
AccessToken: "The token is for wrong application (client_id)",
TokenType: "",
ExpiresIn: 0,
Scope: "",
@ -228,7 +228,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
if application.ClientSecret != clientSecret {
return &TokenWrapper{
AccessToken: "invalid client_secret",
AccessToken: "Invalid client_secret",
TokenType: "",
ExpiresIn: 0,
Scope: "",

View File

@ -93,7 +93,7 @@ func getObject(ctx *context.Context) (string, string) {
func denyRequest(ctx *context.Context) {
w := ctx.ResponseWriter
w.WriteHeader(403)
resp := &controllers.Response{Status: "error", Msg: "unauthorized operation"}
resp := &controllers.Response{Status: "error", Msg: "Unauthorized operation"}
_, err := w.Write([]byte(util.StructToJson(resp)))
if err != nil {
panic(err)

View File

@ -289,7 +289,7 @@ class ApplicationEditPage extends React.Component {
}
})
.catch(error => {
Setting.showMessage("error", `failed to connect to server: ${error}`);
Setting.showMessage("error", `Failed to connect to server: ${error}`);
});
}

View File

@ -116,7 +116,7 @@ class OrganizationEditPage extends React.Component {
}
})
.catch(error => {
Setting.showMessage("error", `failed to connect to server: ${error}`);
Setting.showMessage("error", `Failed to connect to server: ${error}`);
});
}

View File

@ -155,7 +155,7 @@ class ProviderEditPage extends React.Component {
}
})
.catch(error => {
Setting.showMessage("error", `failed to connect to server: ${error}`);
Setting.showMessage("error", `Failed to connect to server: ${error}`);
});
}

View File

@ -283,7 +283,7 @@ class UserEditPage extends React.Component {
}
})
.catch(error => {
Setting.showMessage("error", `failed to connect to server: ${error}`);
Setting.showMessage("error", `Failed to connect to server: ${error}`);
});
}

View File

@ -83,7 +83,6 @@ class AuthCallback extends React.Component {
// Util.showMessage("success", `Authorization code: ${res.data}`);
}
} else {
// Util.showMessage("error", `Log in failed${res.msg}`);
this.setState({
msg: res.msg,
});

View File

@ -168,12 +168,12 @@ class LoginPage extends React.Component {
style={{width: "100%"}}
disabled={!application.enablePassword}
>
Login
Sign In
</Button>
{
!application.enableSignUp ? null : (
<div style={{float: "right"}}>
No account yet,&nbsp;
No account yet?&nbsp;
<Link to={"/register"}>
sign up now
</Link>

View File

@ -221,7 +221,7 @@ class RegisterPage extends React.Component {
</Form.Item>
<Form.Item {...tailFormItemLayout}>
<Button type="primary" htmlType="submit">
Register
Sign Up
</Button>
&nbsp;&nbsp;&nbsp;Have account?&nbsp;
<Link to={"/login"}>