mirror of
https://github.com/traccar/traccar-web.git
synced 2025-01-09 04:37:33 +08:00
Merge pull request #147 from khfayzullaev/master
Admin should not add an existing username
This commit is contained in:
commit
f97b868dc1
@ -33,6 +33,7 @@ import org.traccar.web.shared.model.UserSettings;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.sencha.gxt.data.shared.ListStore;
|
||||
import com.sencha.gxt.widget.core.client.Dialog.PredefinedButton;
|
||||
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
|
||||
import com.sencha.gxt.widget.core.client.box.ConfirmMessageBox;
|
||||
import com.sencha.gxt.widget.core.client.event.HideEvent;
|
||||
|
||||
@ -97,6 +98,10 @@ public class SettingsController implements DeviceView.SettingsHandler {
|
||||
public void onSuccess(User result) {
|
||||
userStore.add(result);
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
new AlertMessageBox("Error", "Username is already taken").show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}).show();
|
||||
|
@ -193,9 +193,21 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService
|
||||
synchronized (entityManager) {
|
||||
entityManager.getTransaction().begin();
|
||||
try {
|
||||
entityManager.persist(user);
|
||||
entityManager.getTransaction().commit();
|
||||
return user;
|
||||
String login = user.getLogin();
|
||||
TypedQuery<User> query = entityManager.createQuery(
|
||||
"SELECT x FROM User x WHERE x.login = :login", User.class);
|
||||
query.setParameter("login", login);
|
||||
List<User> results = query.getResultList();
|
||||
|
||||
if (results.isEmpty()) {
|
||||
entityManager.persist(user);
|
||||
entityManager.getTransaction().commit();
|
||||
return user;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
entityManager.getTransaction().rollback();
|
||||
throw e;
|
||||
|
Loading…
Reference in New Issue
Block a user