1 |
57253
|
michele.ar
|
package eu.dnetlib.organizations.controller;
|
2 |
|
|
|
3 |
57537
|
michele.ar
|
import java.util.HashMap;
|
4 |
|
|
import java.util.Map;
|
5 |
|
|
|
6 |
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
7 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
8 |
57542
|
michele.ar
|
import org.springframework.web.bind.annotation.GetMapping;
|
9 |
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
10 |
57537
|
michele.ar
|
import org.springframework.web.bind.annotation.RequestParam;
|
11 |
57253
|
michele.ar
|
import org.springframework.web.bind.annotation.RestController;
|
12 |
|
|
|
13 |
57537
|
michele.ar
|
import eu.dnetlib.organizations.model.User;
|
14 |
57542
|
michele.ar
|
import eu.dnetlib.organizations.model.view.UserView;
|
15 |
57537
|
michele.ar
|
import eu.dnetlib.organizations.repository.UserRepository;
|
16 |
57542
|
michele.ar
|
import eu.dnetlib.organizations.repository.readonly.UserViewRepository;
|
17 |
57537
|
michele.ar
|
import eu.dnetlib.organizations.utils.OpenOrgsConstants;
|
18 |
|
|
|
19 |
57253
|
michele.ar
|
@RestController
|
20 |
|
|
public class UserController {
|
21 |
|
|
|
22 |
57537
|
michele.ar
|
private static final String DEFAULT_PASSWORD = "dnet";
|
23 |
|
|
|
24 |
|
|
@Autowired
|
25 |
|
|
private UserRepository userRepository;
|
26 |
57542
|
michele.ar
|
@Autowired
|
27 |
|
|
private UserViewRepository userViewRepository;
|
28 |
57537
|
michele.ar
|
|
29 |
57542
|
michele.ar
|
@PostMapping(value = "/public_api/newUser")
|
30 |
|
|
public Map<String, Integer> newUser(final @RequestParam String email) {
|
31 |
57537
|
michele.ar
|
final Map<String, Integer> res = new HashMap<>();
|
32 |
|
|
if (userRepository.existsById(email)) {
|
33 |
|
|
res.put("status", 2);
|
34 |
|
|
} else {
|
35 |
|
|
final User user = new User();
|
36 |
|
|
user.setEmail(email);
|
37 |
|
|
user.setPassword("{MD5}" + DigestUtils.md5Hex(DEFAULT_PASSWORD));
|
38 |
|
|
user.setRole(OpenOrgsConstants.pendingRole);
|
39 |
|
|
user.setValid(false);
|
40 |
|
|
userRepository.save(user);
|
41 |
|
|
res.put("status", 1);
|
42 |
|
|
}
|
43 |
|
|
return res;
|
44 |
|
|
}
|
45 |
|
|
|
46 |
57542
|
michele.ar
|
@GetMapping("/api/users")
|
47 |
|
|
public Iterable<UserView> users() {
|
48 |
|
|
return userViewRepository.findAll();
|
49 |
|
|
}
|
50 |
|
|
|
51 |
57253
|
michele.ar
|
}
|