Skip to content

Commit

Permalink
GG-19546 Fixed creation of user by admin. (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
nva committed Jun 19, 2019
1 parent 1d2119d commit 37a121c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export class DialogAdminCreateUser {
this.IgniteMessages.showInfo(`User ${this.data.email} created`);
this.close({});
})
.catch((res) => {
.catch((err) => {
this.loading.finish('createUser');
this.IgniteMessages.showError(null, res.data);
this.setServerError(res.data);
this.IgniteMessages.showError(null, err);
this.setServerError(err.message);
});
}
}
2 changes: 1 addition & 1 deletion modules/web-console/frontend/app/core/admin/Admin.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ export default class IgniteAdminData {
registerUser(userInfo) {
return this.$http.put('/api/v1/admin/users', userInfo)
.then(({ data }) => data)
.catch(this.Messages.showError);
.catch(({data}) => {throw data;});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public AccountsRepository(Ignite ignite, TransactionManager txMgr) {
this.txMgr = txMgr;

accountsTbl = new Table<Account>(ignite, "accounts")
.addUniqueIndex(Account::getUsername, (acc) -> "Account with email '" + acc.getUsername() + "' already registered")
.addUniqueIndex(a -> a.getUsername().trim().toLowerCase(), (acc) -> "Account with email '" + acc.getUsername() + "' already registered")
.addUniqueIndex(Account::getToken, (acc) -> "Account with token '" + acc.getToken() + "' already registered");
}

Expand Down Expand Up @@ -117,9 +117,6 @@ public boolean ensureFirstUser() {
*/
public Account create(Account account) throws AuthenticationServiceException {
try (Transaction tx = txMgr.txStart()) {
if (accountsTbl.getByIndex(account.getUsername()) != null)
throw new IgniteException("Account with email already exists: " + account.getUsername());

account.setAdmin(ensureFirstUser());

save(account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,6 @@ public Account save(UUID accId, ChangeUserRequest changes) {
try (Transaction tx = txMgr.txStart()) {
Account acc = accountsRepo.getById(accId);

String oldEmail = acc.getEmail();
String newEmail = changes.getEmail();

if (!oldEmail.equals(newEmail)) {
Account accByEmail = accountsRepo.getByEmail(oldEmail);

if (!acc.getId().equals(accByEmail.getId()))
throw new IllegalStateException("User with this email already registered");
}

String oldTok = acc.getToken();

acc.update(changes);
Expand Down

0 comments on commit 37a121c

Please sign in to comment.