Skip to content

Commit

Permalink
Merge pull request #14 from rohit-zip/main
Browse files Browse the repository at this point in the history
feature/auto-generated-username-added
  • Loading branch information
rohit-zip authored Jun 17, 2024
2 parents af00a27 + c28c43b commit 938b25f
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.bloggios.auth.provider.modal.UserEntity;
import com.bloggios.auth.provider.payload.GoogleOauthUserInfo;
import com.bloggios.auth.provider.utils.IpUtils;
import com.bloggios.auth.provider.utils.UsernameGenerator;
import lombok.RequiredArgsConstructor;
import org.springframework.core.env.Environment;
import org.springframework.security.crypto.password.PasswordEncoder;
Expand Down Expand Up @@ -58,15 +59,16 @@
public class OauthUserToUserAuthTransformer {

private final RoleDao roleDao;
private final PasswordEncoder passwordEncoder;
private final Environment environment;
private final UsernameGenerator usernameGenerator;

public UserEntity transform(GoogleOauthUserInfo googleOauthUserInfo, HttpServletRequest httpServletRequest) {
RoleEntity userRole = roleDao.findById(USER_ROLE);
RoleEntity dummyRole = roleDao.findById(DUMMY_ROLE);
List<RoleEntity> roleEntities = new ArrayList<>(List.of(userRole, dummyRole));
return UserEntity.builder()
.oauthId(googleOauthUserInfo.getGoogleUserId())
.username(usernameGenerator.generate(googleOauthUserInfo.getEmail()))
.email(googleOauthUserInfo.getEmail())
.apiVersion(environment.getProperty(EnvironmentConstants.APPLICATION_VERSION))
.version(UUID.randomUUID().toString())
Expand Down

0 comments on commit 938b25f

Please sign in to comment.