Implementacion Google finalizada

This commit is contained in:
Paola 2021-07-09 17:35:18 -06:00
commit 1340861658
9 changed files with 52 additions and 13 deletions

View File

@ -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
if (isGoogle == 1) {
newUser.setActivated(true);
} else {
newUser.setActivated(false);
}
// new user gets registration key
newUser.setActivationKey(RandomUtil.generateActivationKey());
Set<Authority> authorities = new HashSet<>();

View File

@ -67,10 +67,14 @@ public class AccountResource {
managedUserVM.getPassword(),
managedUserVM.getName(),
managedUserVM.getProfileIcon(),
managedUserVM.getIsAdmin()
managedUserVM.getIsAdmin(),
managedUserVM.getIsGoogle()
);
if (managedUserVM.getIsGoogle() != 1) {
mailService.sendActivationEmail(user);
}
}
/**
* {@code GET /activate} : activate the registered user.

View File

@ -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() {

View File

@ -65,6 +65,7 @@ describe('Component Tests', () => {
name: '',
profileIcon: 1,
isAdmin: 0,
isGoogle: 0,
});
expect(comp.success).toBe(true);
expect(comp.errorUserExists).toBe(false);

View File

@ -95,6 +95,7 @@ export class RegisterComponent implements AfterViewInit {
name,
profileIcon: this.profileIcon,
isAdmin: 0,
isGoogle: 0,
})
.subscribe(
() => (this.success = true),

View File

@ -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
) {}
}

View File

@ -65,6 +65,7 @@ describe('Component Tests', () => {
name: '',
profileIcon: 1,
isAdmin: 1,
isGoogle: 0,
});
expect(comp.success).toBe(true);
expect(comp.errorUserExists).toBe(false);

View File

@ -93,6 +93,7 @@ export class UsuarioExtraUpdateComponent {
name,
profileIcon: this.profileIcon,
isAdmin: 1,
isGoogle: 0,
})
.subscribe(
() => (this.success = true),

View File

@ -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)
);
}