mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 10:45:47 +08:00
Improve response message.
This commit is contained in:
parent
d6715c7601
commit
0127f8fb63
@ -64,7 +64,7 @@ func (c *ApiController) Register() {
|
|||||||
var resp Response
|
var resp Response
|
||||||
|
|
||||||
if c.GetSessionUser() != "" {
|
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.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
@ -95,7 +95,7 @@ func (c *ApiController) Register() {
|
|||||||
//c.SetSessionUser(user)
|
//c.SetSessionUser(user)
|
||||||
|
|
||||||
util.LogInfo(c.Ctx, "API: [%s] is registered as new user", 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
|
c.Data["json"] = resp
|
||||||
@ -124,7 +124,7 @@ func (c *ApiController) GetAccount() {
|
|||||||
var resp Response
|
var resp Response
|
||||||
|
|
||||||
if c.GetSessionUser() == "" {
|
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.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
@ -145,7 +145,7 @@ func (c *ApiController) UploadAvatar() {
|
|||||||
|
|
||||||
msg := object.CheckUserLogin(userObj.Owner+"/"+userObj.Name, c.Ctx.Request.Form.Get("password"))
|
msg := object.CheckUserLogin(userObj.Owner+"/"+userObj.Name, c.Ctx.Request.Form.Get("password"))
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
resp = Response{Status: "error", Msg: "Password wrong"}
|
resp = Response{Status: "error", Msg: "Wrong password"}
|
||||||
c.Data["json"] = resp
|
c.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
|
@ -48,7 +48,7 @@ func (c *ApiController) HandleLoggedIn(userId string, form *RequestForm) *Respon
|
|||||||
code := object.GetOAuthCode(userId, clientId, responseType, redirectUri, scope, state)
|
code := object.GetOAuthCode(userId, clientId, responseType, redirectUri, scope, state)
|
||||||
resp = codeToResponse(code)
|
resp = codeToResponse(code)
|
||||||
} else {
|
} 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
|
return resp
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ func (c *ApiController) Login() {
|
|||||||
if form.Username != "" {
|
if form.Username != "" {
|
||||||
if form.Type == ResponseTypeLogin {
|
if form.Type == ResponseTypeLogin {
|
||||||
if c.GetSessionUser() != "" {
|
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.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
@ -123,7 +123,7 @@ func (c *ApiController) Login() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !token.Valid() {
|
if !token.Valid() {
|
||||||
resp = &Response{Status: "error", Msg: "invalid token"}
|
resp = &Response{Status: "error", Msg: "Invalid token"}
|
||||||
c.Data["json"] = resp
|
c.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
@ -131,7 +131,7 @@ func (c *ApiController) Login() {
|
|||||||
|
|
||||||
userInfo, err := idProvider.GetUserInfo(token)
|
userInfo, err := idProvider.GetUserInfo(token)
|
||||||
if err != nil {
|
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.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
@ -159,12 +159,12 @@ func (c *ApiController) Login() {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
if !application.EnableSignUp {
|
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.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
} else {
|
} 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.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
@ -174,7 +174,7 @@ func (c *ApiController) Login() {
|
|||||||
} else {
|
} else {
|
||||||
userId := c.GetSessionUser()
|
userId := c.GetSessionUser()
|
||||||
if userId == "" {
|
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.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
@ -184,7 +184,7 @@ func (c *ApiController) Login() {
|
|||||||
if isLinked {
|
if isLinked {
|
||||||
resp = &Response{Status: "ok", Msg: "", Data: isLinked}
|
resp = &Response{Status: "ok", Msg: "", Data: isLinked}
|
||||||
} else {
|
} 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 {
|
//if len(object.GetMemberAvatar(userId)) == 0 {
|
||||||
// avatar := UploadAvatarToOSS(tempUserAccount.AvatarUrl, userId)
|
// avatar := UploadAvatarToOSS(tempUserAccount.AvatarUrl, userId)
|
||||||
|
@ -35,8 +35,8 @@ func (c *ApiController) SetSessionUser(user string) {
|
|||||||
|
|
||||||
func wrapActionResponse(affected bool) *Response {
|
func wrapActionResponse(affected bool) *Response {
|
||||||
if affected {
|
if affected {
|
||||||
return &Response{Status: "ok", Msg: "", Data: "affected"}
|
return &Response{Status: "ok", Msg: "", Data: "Affected"}
|
||||||
} else {
|
} else {
|
||||||
return &Response{Status: "ok", Msg: "", Data: "unaffected"}
|
return &Response{Status: "ok", Msg: "", Data: "Unaffected"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ func CheckOAuthLogin(clientId string, responseType string, redirectUri string, s
|
|||||||
|
|
||||||
application := getApplicationByClientId(clientId)
|
application := getApplicationByClientId(clientId)
|
||||||
if application == nil {
|
if application == nil {
|
||||||
return "invalid client_id", nil
|
return "Invalid client_id", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
validUri := false
|
validUri := false
|
||||||
@ -150,7 +150,7 @@ func GetOAuthCode(userId string, clientId string, responseType string, redirectU
|
|||||||
user := GetUser(userId)
|
user := GetUser(userId)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return &Code{
|
return &Code{
|
||||||
Message: "invalid user_id",
|
Message: "Invalid user_id",
|
||||||
Code: "",
|
Code: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
|||||||
application := getApplicationByClientId(clientId)
|
application := getApplicationByClientId(clientId)
|
||||||
if application == nil {
|
if application == nil {
|
||||||
return &TokenWrapper{
|
return &TokenWrapper{
|
||||||
AccessToken: "invalid client_id",
|
AccessToken: "Invalid client_id",
|
||||||
TokenType: "",
|
TokenType: "",
|
||||||
ExpiresIn: 0,
|
ExpiresIn: 0,
|
||||||
Scope: "",
|
Scope: "",
|
||||||
@ -210,7 +210,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
|||||||
token := getTokenByCode(code)
|
token := getTokenByCode(code)
|
||||||
if token == nil {
|
if token == nil {
|
||||||
return &TokenWrapper{
|
return &TokenWrapper{
|
||||||
AccessToken: "invalid code",
|
AccessToken: "Invalid code",
|
||||||
TokenType: "",
|
TokenType: "",
|
||||||
ExpiresIn: 0,
|
ExpiresIn: 0,
|
||||||
Scope: "",
|
Scope: "",
|
||||||
@ -219,7 +219,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
|||||||
|
|
||||||
if application.Name != token.Application {
|
if application.Name != token.Application {
|
||||||
return &TokenWrapper{
|
return &TokenWrapper{
|
||||||
AccessToken: "token is for wrong application (client_id)",
|
AccessToken: "The token is for wrong application (client_id)",
|
||||||
TokenType: "",
|
TokenType: "",
|
||||||
ExpiresIn: 0,
|
ExpiresIn: 0,
|
||||||
Scope: "",
|
Scope: "",
|
||||||
@ -228,7 +228,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
|||||||
|
|
||||||
if application.ClientSecret != clientSecret {
|
if application.ClientSecret != clientSecret {
|
||||||
return &TokenWrapper{
|
return &TokenWrapper{
|
||||||
AccessToken: "invalid client_secret",
|
AccessToken: "Invalid client_secret",
|
||||||
TokenType: "",
|
TokenType: "",
|
||||||
ExpiresIn: 0,
|
ExpiresIn: 0,
|
||||||
Scope: "",
|
Scope: "",
|
||||||
|
@ -93,7 +93,7 @@ func getObject(ctx *context.Context) (string, string) {
|
|||||||
func denyRequest(ctx *context.Context) {
|
func denyRequest(ctx *context.Context) {
|
||||||
w := ctx.ResponseWriter
|
w := ctx.ResponseWriter
|
||||||
w.WriteHeader(403)
|
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)))
|
_, err := w.Write([]byte(util.StructToJson(resp)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -289,7 +289,7 @@ class ApplicationEditPage extends React.Component {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `failed to connect to server: ${error}`);
|
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ class OrganizationEditPage extends React.Component {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `failed to connect to server: ${error}`);
|
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ class ProviderEditPage extends React.Component {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `failed to connect to server: ${error}`);
|
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ class UserEditPage extends React.Component {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Setting.showMessage("error", `failed to connect to server: ${error}`);
|
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,6 @@ class AuthCallback extends React.Component {
|
|||||||
// Util.showMessage("success", `Authorization code: ${res.data}`);
|
// Util.showMessage("success", `Authorization code: ${res.data}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Util.showMessage("error", `Log in failed:${res.msg}`);
|
|
||||||
this.setState({
|
this.setState({
|
||||||
msg: res.msg,
|
msg: res.msg,
|
||||||
});
|
});
|
||||||
|
@ -168,12 +168,12 @@ class LoginPage extends React.Component {
|
|||||||
style={{width: "100%"}}
|
style={{width: "100%"}}
|
||||||
disabled={!application.enablePassword}
|
disabled={!application.enablePassword}
|
||||||
>
|
>
|
||||||
Login
|
Sign In
|
||||||
</Button>
|
</Button>
|
||||||
{
|
{
|
||||||
!application.enableSignUp ? null : (
|
!application.enableSignUp ? null : (
|
||||||
<div style={{float: "right"}}>
|
<div style={{float: "right"}}>
|
||||||
No account yet,
|
No account yet?
|
||||||
<Link to={"/register"}>
|
<Link to={"/register"}>
|
||||||
sign up now
|
sign up now
|
||||||
</Link>
|
</Link>
|
||||||
|
@ -221,7 +221,7 @@ class RegisterPage extends React.Component {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item {...tailFormItemLayout}>
|
<Form.Item {...tailFormItemLayout}>
|
||||||
<Button type="primary" htmlType="submit">
|
<Button type="primary" htmlType="submit">
|
||||||
Register
|
Sign Up
|
||||||
</Button>
|
</Button>
|
||||||
Have account?
|
Have account?
|
||||||
<Link to={"/login"}>
|
<Link to={"/login"}>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user