Project

General

Profile

« Previous | Next » 

Revision 57596

User Registration form

View differences:

UserController.java
5 5

  
6 6
import org.apache.commons.codec.digest.DigestUtils;
7 7
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.security.core.Authentication;
9
import org.springframework.web.bind.annotation.DeleteMapping;
8 10
import org.springframework.web.bind.annotation.GetMapping;
9 11
import org.springframework.web.bind.annotation.PostMapping;
12
import org.springframework.web.bind.annotation.RequestBody;
10 13
import org.springframework.web.bind.annotation.RequestParam;
11 14
import org.springframework.web.bind.annotation.RestController;
12 15

  
......
14 17
import eu.dnetlib.organizations.model.view.UserView;
15 18
import eu.dnetlib.organizations.repository.UserRepository;
16 19
import eu.dnetlib.organizations.repository.readonly.UserViewRepository;
20
import eu.dnetlib.organizations.utils.DatabaseUtils;
17 21
import eu.dnetlib.organizations.utils.OpenOrgsConstants;
18 22

  
19 23
@RestController
......
25 29
	private UserRepository userRepository;
26 30
	@Autowired
27 31
	private UserViewRepository userViewRepository;
32
	@Autowired
33
	private DatabaseUtils dbUtils;
28 34

  
29 35
	@PostMapping(value = "/public_api/newUser")
30 36
	public Map<String, Integer> newUser(final @RequestParam String email) {
......
48 54
		return userViewRepository.findAll();
49 55
	}
50 56

  
57
	@PostMapping("/api/users")
58
	public Iterable<UserView> save(@RequestBody final UserView userView, final Authentication authentication) {
59
		if (authentication.getName().equals(userView.getEmail())) { throw new RuntimeException("You can't edit your own user"); }
60
		dbUtils.saveUser(userView);
61
		return users();
62
	}
63

  
64
	@DeleteMapping("/api/users")
65
	public Iterable<UserView> delete(final @RequestParam String email, final Authentication authentication) {
66
		if (authentication.getName().equals(email)) { throw new RuntimeException("You can't delete your own user"); }
67
		dbUtils.deleteUser(email);
68
		return users();
69
	}
70

  
51 71
}

Also available in: Unified diff