diff --git a/src/main/java/org/datasurvey/service/UserService.java b/src/main/java/org/datasurvey/service/UserService.java index e1d8bb5..227c590 100644 --- a/src/main/java/org/datasurvey/service/UserService.java +++ b/src/main/java/org/datasurvey/service/UserService.java @@ -156,7 +156,7 @@ public class UserService { * Modified to register extra user data * name, iconoPerfil, fechaNacimiento, estado, pais */ - public User registerUser(AdminUserDTO userDTO, String password, String name, Integer profileIcon, Integer isAdmin) { + public User registerUser(AdminUserDTO userDTO, String password, String name, Integer profileIcon, Integer isAdmin, Integer isGoogle) { userRepository .findOneByLogin(userDTO.getLogin().toLowerCase()) .ifPresent( @@ -190,7 +190,13 @@ public class UserService { newUser.setImageUrl(userDTO.getImageUrl()); newUser.setLangKey(userDTO.getLangKey()); // new user is not active - newUser.setActivated(false); + + if (isGoogle == 1) { + newUser.setActivated(true); + } else { + newUser.setActivated(false); + } + // new user gets registration key newUser.setActivationKey(RandomUtil.generateActivationKey()); Set authorities = new HashSet<>(); diff --git a/src/main/java/org/datasurvey/web/rest/AccountResource.java b/src/main/java/org/datasurvey/web/rest/AccountResource.java index 493ece3..afb4a0c 100644 --- a/src/main/java/org/datasurvey/web/rest/AccountResource.java +++ b/src/main/java/org/datasurvey/web/rest/AccountResource.java @@ -67,9 +67,13 @@ public class AccountResource { managedUserVM.getPassword(), managedUserVM.getName(), managedUserVM.getProfileIcon(), - managedUserVM.getIsAdmin() + managedUserVM.getIsAdmin(), + managedUserVM.getIsGoogle() ); - mailService.sendActivationEmail(user); + + if (managedUserVM.getIsGoogle() != 1) { + mailService.sendActivationEmail(user); + } } /** diff --git a/src/main/java/org/datasurvey/web/rest/vm/ManagedUserVM.java b/src/main/java/org/datasurvey/web/rest/vm/ManagedUserVM.java index 3d1dc73..5cc7a2b 100644 --- a/src/main/java/org/datasurvey/web/rest/vm/ManagedUserVM.java +++ b/src/main/java/org/datasurvey/web/rest/vm/ManagedUserVM.java @@ -24,6 +24,8 @@ public class ManagedUserVM extends AdminUserDTO { private Integer isAdmin; + private Integer isGoogle; + public ManagedUserVM() { // Empty constructor needed for Jackson. } @@ -60,6 +62,14 @@ public class ManagedUserVM extends AdminUserDTO { this.isAdmin = isAdmin; } + public Integer getIsGoogle() { + return isGoogle; + } + + public void setIsGoogle(Integer isGoogle) { + this.isGoogle = isGoogle; + } + // prettier-ignore @Override public String toString() { diff --git a/src/main/webapp/app/account/register/register.component.spec.ts b/src/main/webapp/app/account/register/register.component.spec.ts index 422a382..d040495 100644 --- a/src/main/webapp/app/account/register/register.component.spec.ts +++ b/src/main/webapp/app/account/register/register.component.spec.ts @@ -65,6 +65,7 @@ describe('Component Tests', () => { name: '', profileIcon: 1, isAdmin: 0, + isGoogle: 0, }); expect(comp.success).toBe(true); expect(comp.errorUserExists).toBe(false); diff --git a/src/main/webapp/app/account/register/register.component.ts b/src/main/webapp/app/account/register/register.component.ts index 6278989..8d1fa62 100644 --- a/src/main/webapp/app/account/register/register.component.ts +++ b/src/main/webapp/app/account/register/register.component.ts @@ -95,6 +95,7 @@ export class RegisterComponent implements AfterViewInit { name, profileIcon: this.profileIcon, isAdmin: 0, + isGoogle: 0, }) .subscribe( () => (this.success = true), diff --git a/src/main/webapp/app/account/register/register.model.ts b/src/main/webapp/app/account/register/register.model.ts index 3a3a97d..18a4688 100644 --- a/src/main/webapp/app/account/register/register.model.ts +++ b/src/main/webapp/app/account/register/register.model.ts @@ -6,6 +6,7 @@ export class Registration { public langKey: string, public name: string, public profileIcon: number, - public isAdmin: number + public isAdmin: number, + public isGoogle: number ) {} } diff --git a/src/main/webapp/app/entities/usuario-extra/update/usuario-extra-update.component.spec.ts b/src/main/webapp/app/entities/usuario-extra/update/usuario-extra-update.component.spec.ts index c2e698a..2382221 100644 --- a/src/main/webapp/app/entities/usuario-extra/update/usuario-extra-update.component.spec.ts +++ b/src/main/webapp/app/entities/usuario-extra/update/usuario-extra-update.component.spec.ts @@ -65,6 +65,7 @@ describe('Component Tests', () => { name: '', profileIcon: 1, isAdmin: 1, + isGoogle: 0, }); expect(comp.success).toBe(true); expect(comp.errorUserExists).toBe(false); diff --git a/src/main/webapp/app/entities/usuario-extra/update/usuario-extra-update.component.ts b/src/main/webapp/app/entities/usuario-extra/update/usuario-extra-update.component.ts index f712e2b..65f69de 100644 --- a/src/main/webapp/app/entities/usuario-extra/update/usuario-extra-update.component.ts +++ b/src/main/webapp/app/entities/usuario-extra/update/usuario-extra-update.component.ts @@ -93,6 +93,7 @@ export class UsuarioExtraUpdateComponent { name, profileIcon: this.profileIcon, isAdmin: 1, + isGoogle: 0, }) .subscribe( () => (this.success = true), diff --git a/src/main/webapp/app/login/login.component.ts b/src/main/webapp/app/login/login.component.ts index ea31bf4..0176be5 100644 --- a/src/main/webapp/app/login/login.component.ts +++ b/src/main/webapp/app/login/login.component.ts @@ -47,17 +47,17 @@ export class LoginComponent implements OnInit, AfterViewInit { ngOnInit(): void { //Servicio para verificar si el usuario se encuentra loggeado - this.authService.authState.subscribe(user => { + /*this.authService.authState.subscribe(user => { this.user = user; this.loggedIn = user != null; - console.log('correo: ' + user.email); + /!* console.log('correo: ' + user.email); console.log('correo: ' + user.name); - console.log('ID: ' + this.user.id); + console.log('ID: ' + this.user.id);*!/ this.authenticacionGoogle(); }); - +*/ // if already authenticated then navigate to home page this.accountService.identity().subscribe(() => { if (this.accountService.isAuthenticated()) { @@ -72,7 +72,18 @@ export class LoginComponent implements OnInit, AfterViewInit { //Inicio Google signInWithGoogle(): void { - this.authService.signIn(GoogleLoginProvider.PROVIDER_ID); + this.authService.signIn(GoogleLoginProvider.PROVIDER_ID).then(() => { + this.authService.authState.subscribe(user => { + this.user = user; + this.loggedIn = user != null; + + /* console.log('correo: ' + user.email); + console.log('correo: ' + user.name); + console.log('ID: ' + this.user.id);*/ + + this.authenticacionGoogle(); + }); + }); } authenticacionGoogle(): void { @@ -83,9 +94,8 @@ export class LoginComponent implements OnInit, AfterViewInit { // There were no routing during login (eg from navigationToStoredUrl) this.router.navigate(['']); } - console.log('SI existe'); }, - () => (this.authenticationError = true) + () => this.activateGoogle() /*this.registerService .save({ login: this.user.email, @@ -131,9 +141,13 @@ export class LoginComponent implements OnInit, AfterViewInit { name: this.user.name, profileIcon: this.randomProfilePic(), isAdmin: 0, + isGoogle: 1, }) .subscribe( - () => (this.success = true), + () => { + this.success = true; + this.authenticacionGoogle(); + }, response => this.processError(response) ); }