Skip to content
Snippets Groups Projects
Commit 20c13bd7 authored by joalhelk's avatar joalhelk
Browse files

comments

parent e6b90068
No related branches found
No related tags found
No related merge requests found
......@@ -59,9 +59,12 @@ public class AdminFrame extends JPanel implements ActionListener {
revalidate();
}
/*
* Creates a user column for editing user details
*/
private void CreateUserField(UserType user) {
JLabel name = new JLabel(user.getName());
name.setForeground(Color.white);
JTextField name = new JTextField(20);
name.setText(user.getName());
panel.add(name, c);
JTextField email = new JTextField(20);
......@@ -85,7 +88,7 @@ public class AdminFrame extends JPanel implements ActionListener {
c.gridwidth = GridBagConstraints.REMAINDER;
JButton save = new JButton("Save");
save.addActionListener( evt -> {
performActionOnSave(name, email, enabled, locked, user.getId());
performActionOnSave(name.getText(), email.getText(), enabled.isSelected(), locked.isSelected(), user.getId());
});
panel.add(save, c);
c.gridwidth = 1;
......@@ -95,10 +98,10 @@ public class AdminFrame extends JPanel implements ActionListener {
* Handles the save button press
* Sends update request to server with new info
*/
private void performActionOnSave(JLabel name, JTextField email, JCheckBox enabled, JCheckBox locked, Long id) {
private void performActionOnSave(String name, String email, Boolean enabled, Boolean locked, Long id) {
if (!WelcomePage.handleSave()) return;
if(!HttpRequests.updateUser(name.getText(), email.getText(), enabled.isSelected(), locked.isSelected(), id)) WelcomePage.ErrorDialog();
if(!HttpRequests.updateUser(name, email, enabled, locked, id)) WelcomePage.ErrorDialog();
UpdateUsers();
}
......
......@@ -80,7 +80,7 @@ public class AppUserService implements UserDetailsService {
appUserRepository.deleteById(id);
}
// Update users name and/or email
// Update users info
@Transactional
public void updateUser(Long id, String name, String email, Boolean enabled, Boolean locked) {
log.info("Updating user: " + email);
......@@ -89,10 +89,12 @@ public class AppUserService implements UserDetailsService {
.orElseThrow(() -> new IllegalStateException(
"person with id " + id + " not found" ));
// Check if name isn't null/empty nor it isn't current name
if(name != null && name.length() > 0 && !Objects.equals(person.getName(), name)) {
person.setName(name);
}
// Check if email is given, isn't current email & isn't taken
if(email != null && email.length() > 0 && !Objects.equals(person.getEmail(), email)) {
Optional<AppUser> optionalPerson = appUserRepository.findByEmail(email);
if(optionalPerson.isPresent()) throw new IllegalStateException("email taken");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment