use of com.tvd12.ezyhttp.server.core.annotation.RequestBody in project ezyfox-examples by tvd12.
the class GoogleService method getAccessToken.
@SuppressWarnings("unchecked")
@Override
public String getAccessToken(String code) {
Map<String, Object> requestBody = EzyMapBuilder.mapBuilder().put("client_id", clientId).put("client_secret", clientSecret).put("redirect_uri", redirectUri).put("code", code).put("grant_type", "authorization_code").build();
PostRequest request = new PostRequest().setURL(getTokenUri).setEntity(RequestEntity.builder().contentType(ContentTypes.APPLICATION_X_WWW_FORM_URLENCODED).body(requestBody).build()).setResponseType(Map.class);
try {
Map<String, Object> response = httpClientProxy.call(request, DEFAULT_GOOGLE_AUTH_TIMEOUT);
return (String) response.get("access_token");
} catch (Exception e) {
logger.info("get google access token error", e);
return null;
}
}
use of com.tvd12.ezyhttp.server.core.annotation.RequestBody in project ezyfox-examples by tvd12.
the class RegisterController method registerPost.
@DoPost("/register")
public Redirect registerPost(@RequestBody RegisterRequest request) {
final User user = new User(request.getUsername(), request.getPassword(), request.getBirthOfDate(), LocalDate.now(), LocalDateTime.now());
userService.addUser(user);
return Redirect.to("/user/" + request.getUsername());
}
use of com.tvd12.ezyhttp.server.core.annotation.RequestBody in project ezyfox-examples by tvd12.
the class UserController method userSavePost.
@DoPost("/user/save")
public Object userSavePost(@UserId long userId, @RequestBody UpdateUserRequest request) {
User user = userService.getUserById(userId);
if (user == null) {
throw new UserNotFoundException("user with id: " + userId + " not found");
}
user.setEmail(request.getEmail());
user.setFullName(request.getFirstName() + " " + request.getLastName());
user.setFirstName(request.getFirstName());
user.setLastName(request.getLastName());
user.setStatus(UserStatus.UPDATED);
user.setPassword(EzySHA256.cryptUtfToLowercase(request.getPassword()));
userService.saveUser(user);
return Redirect.builder().uri("/home").build();
}
Aggregations