Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Creating a username does not work properly for non-admin #54

Closed
pslosarz opened this issue May 15, 2023 · 0 comments
Closed

[Bug] Creating a username does not work properly for non-admin #54

pslosarz opened this issue May 15, 2023 · 0 comments

Comments

@pslosarz
Copy link

When creating a new user without admin role, information about the password is lost, making it impossible to login.

scanario:
Create a new user by api without admin role.

/api/user/save
{
    "type": "internal",
    "admin": false,
    "name": "Jon Doe",
    "loginName": "test",
    "password": "xxx",
    "passwordConfirm": "xxx",
    "email": "xxx@gmail.com",
    "roles": [
        "rolaxxx"
    ]
}

try logging in with your new credentials

api/user/sign-in
{"name":"test","password":"xxx"}

the response will be:

security: invalid principal or credential(1001)

[FIX] This is a fix for this case. The principle is the same as for creating a new admin account.
api/user.go:73

return func(c web.Context) error {
		args := &struct {
			Password string `json:"password"`
			*dao.User
		}{}
		err := c.Bind(args, true)
		if err == nil {
			ctx, cancel := misc.Context(defaultTimeout)
			defer cancel()

			user := args.User
			if user.ID == "" {
				user.Password = args.Password
				_, err = b.Create(ctx, user, c.User())
			} else {
				err = b.Update(ctx, user, c.User())
			}
		}
		return ajax(c, err)
}
@cuigh cuigh closed this as completed in 2a0b701 May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant