use of org.youngmonkeys.example.ezyhttp.login.entity.User in project ezyfox-examples by tvd12.
the class UserService method saveFacebookUserInfo.
@Override
public User saveFacebookUserInfo(com.restfb.types.User userFacebook) {
User user = new User();
user.setThirdPartyId(userFacebook.getId());
user.setEmail(userFacebook.getId());
user.setFullName(userFacebook.getName());
user.setAccountType(AccountType.FACEBOOK);
user.setDeleted(false);
user.setStatus(UserStatus.REGISTER);
userRepository.save(user);
return user;
}
use of org.youngmonkeys.example.ezyhttp.login.entity.User in project ezyfox-examples by tvd12.
the class UserService method saveGoogleUserInfo.
@Override
public User saveGoogleUserInfo(Userinfo googleUserInfo) {
// create new user information
User user = new User();
user.setEmail(googleUserInfo.getEmail());
user.setFullName(googleUserInfo.getName());
user.setLastName(googleUserInfo.getFamilyName());
user.setFirstName(googleUserInfo.getGivenName());
user.setAvatarURL(googleUserInfo.getPicture());
user.setAccountType(AccountType.GOOGLE);
user.setDeleted(false);
user.setStatus(UserStatus.REGISTER);
userRepository.save(user);
return user;
}
use of org.youngmonkeys.example.ezyhttp.login.entity.User in project ezyfox-examples by tvd12.
the class LoginController method loginWithGoogle.
@DoGet("/google-login-callback")
public Object loginWithGoogle(@RequestParam String code) {
String googleAccessToken = googleService.getAccessToken(code);
if (googleAccessToken == null) {
return Redirect.to("/login-error");
}
Userinfo googleUserInfo = googleService.getUserInfoByAccessToken(googleAccessToken);
if (googleUserInfo == null) {
return Redirect.to("/login-error");
}
boolean userExisted = true;
User user = userService.getUserInfoByEmail(googleUserInfo.getEmail());
if (user == null) {
userExisted = false;
user = userService.saveGoogleUserInfo(googleUserInfo);
userDataService.saveGoogleToken(user.getId(), googleAccessToken);
}
String accessToken = authenticationService.generateAccessToken(user.getId());
return userExisted && user.getStatus() == UserStatus.UPDATED ? Redirect.builder().uri("/home").addCookie("accessToken", accessToken).build() : Redirect.builder().uri("/user/update").addCookie("accessToken", accessToken).build();
}
use of org.youngmonkeys.example.ezyhttp.login.entity.User in project ezyfox-examples by tvd12.
the class LoginController method loginWithFacebook.
@DoGet("/facebook-login-callback")
public Object loginWithFacebook(@RequestParam String code) {
String facebookAccessToken = facebookService.getAccessToken(code);
if (facebookAccessToken == null) {
return Redirect.to("/login-error");
}
com.restfb.types.User userFacebook = facebookService.getUserInfoByAccessToken(facebookAccessToken);
if (userFacebook == null) {
return Redirect.to("/login-error");
}
boolean userExisted = true;
User user = userService.getUserByThirdPartyId(userFacebook.getId());
if (user == null) {
userExisted = false;
user = userService.saveFacebookUserInfo(userFacebook);
userDataService.saveFacebookToken(user.getId(), facebookAccessToken);
}
String accessToken = authenticationService.generateAccessToken(user.getId());
return userExisted && user.getStatus() == UserStatus.UPDATED ? Redirect.builder().uri("/home").addCookie("accessToken", accessToken).build() : Redirect.builder().uri("/user/update").addCookie("accessToken", accessToken).build();
}
use of org.youngmonkeys.example.ezyhttp.login.entity.User 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