Skip to content

Commit

Permalink
35 fix details (#20)
Browse files Browse the repository at this point in the history
* Adiciona mensagens personalizadas

* Se o usuário não tiver ativado a conta e tentar fazer login, redirecionar para a tela de ativar a conta e mostrar o erro

Signed-off-by: DaviMarinho <[email protected]>

* Corrige redirecionamento para editar usuário

Signed-off-by: DaviMarinho <[email protected]>

* Os inputs vem com as informações do usuário

Signed-off-by: DaviMarinho <[email protected]>

* Adiciona primeng e o tema da aplicação

Signed-off-by: DaviMarinho <[email protected]>

* Quando o usuário estiver logado não consegue acessar login e registro

Signed-off-by: DaviMarinho <[email protected]>

* Adiciona e melhora mensagens de erro, e cria o logout

Signed-off-by: DaviMarinho <[email protected]>

* Melhora mensagens de erro

Signed-off-by: DaviMarinho <[email protected]>

* Adiciona botão para ativar conta no login

Signed-off-by: DaviMarinho <[email protected]>

* Organiza pastas

Signed-off-by: DaviMarinho <[email protected]>

* Atualiza gitignore

Signed-off-by: DaviMarinho <[email protected]>

* Adiciona testes unitários no login

Signed-off-by: DaviMarinho <[email protected]>

* Adiciona nome correto a função

Signed-off-by: DaviMarinho <[email protected]>

* Corrige deleção de usuário

Signed-off-by: DaviMarinho <[email protected]>

* Corrigindo detalhes

Signed-off-by: DaviMarinho <[email protected]>

---------

Signed-off-by: DaviMarinho <[email protected]>
  • Loading branch information
DaviMarinho authored Nov 16, 2023
1 parent de09b83 commit 35ec49b
Show file tree
Hide file tree
Showing 30 changed files with 293 additions and 112 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ testem.log
Thumbs.db

./github
/src/app/environment
/src/app/environment
/src/app/secret
/src/app/app.constant.ts
3 changes: 2 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"src/_redirects"
],
"styles": [
"src/styles.css"
"src/styles.css",
"src/assets/theme/theme.css"
],
"scripts": []
},
Expand Down
13 changes: 7 additions & 6 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ import { ActiveAccountComponent } from './pages/active-account/active-account.co
import { ProfileComponent } from './pages/profile/profile.component';
import { CheckCodeRestPasswordComponent } from './pages/check-code-rest-password/check-code-rest-password.component';
import { ResetPasswordComponent } from './pages/reset-password/reset-password.component';
import { AuthGuard } from './services/auth.guard';
import { AuthGuard } from './guard/auth.guard';
import { EditUserComponent } from './pages/edit-user/edit-user.component';
import { SuggestAgendaComponent } from './pages/suggest-agenda/suggest-agenda.component';
import { ParticipateComponent } from './pages/participate/participate.component';
import { WithTokenGuard } from './guard/with-token.guard';

const routes: Routes = [
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'loginsocial', component: LoginSocialComponent },
{ path: 'login', component: LoginComponent, canActivate: [WithTokenGuard], },
{ path: 'register', component: RegisterComponent, canActivate: [WithTokenGuard], },
{ path: 'loginsocial', component: LoginSocialComponent, canActivate: [WithTokenGuard], },
{ path: 'sendCodeResetPassword', component: CheckCodeRestPasswordComponent, canActivate: [WithTokenGuard], },
{ path: 'changePassword', component: ResetPasswordComponent, canActivate: [WithTokenGuard], },
{ path: 'videos', component: VideoComponent },
{ path: 'video/:idVideo', component: VideoViewerComponent },
{ path: 'activeAccount', component: ActiveAccountComponent },
{ path: 'sendCodeResetPassword', component: CheckCodeRestPasswordComponent },
{ path: 'changePassword', component: ResetPasswordComponent },
{ path: 'suggestAgenda', component: SuggestAgendaComponent },
{ path: 'participate', component: ParticipateComponent },
{ path: 'profile', component: ProfileComponent, canActivate: [AuthGuard], },
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<router-outlet></router-outlet>
</app-background>
<p-toast key="myToast"></p-toast>
<p-confirmDialog key="myDialog"></p-confirmDialog>
<p-confirmDialog acceptLabel="Sim" rejectLabel="Não" key="myDialog"></p-confirmDialog>
10 changes: 6 additions & 4 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { OAuthModule, OAuthStorage } from 'angular-oauth2-oidc';
import { InputTextModule } from 'primeng/inputtext';
import { DropdownModule } from 'primeng/dropdown';
import { ButtonModule } from 'primeng/button';

// Declaration
import { NgModule } from '@angular/core';
Expand All @@ -24,10 +25,10 @@ import { LoginSocialComponent } from './pages/login-social/login-social.componen
import { ActiveAccountComponent } from './pages/active-account/active-account.component';
import { HomePageComponent } from './pages/home-page/home-page.component';
import { ProfileComponent } from './pages/profile/profile.component';
import { UserTokenInterceptor } from './services/user-token-interceptor.service';
import { UserTokenInterceptor } from './interceptor/user-token-interceptor.service';
import { ResetPasswordComponent } from './pages/reset-password/reset-password.component';
import { CheckCodeRestPasswordComponent } from './pages/check-code-rest-password/check-code-rest-password.component';
import { AuthGuard } from './services/auth.guard';
import { AuthGuard } from './guard/auth.guard';
import { AuthService } from './services/auth.service';
import { EditUserComponent } from './pages/edit-user/edit-user.component';
import { VideoCommentComponent } from './components/video-comment/video-comment.component';
Expand All @@ -46,7 +47,8 @@ import { MessageService } from 'primeng/api';
BrowserAnimationsModule,
OAuthModule.forRoot(),
InputTextModule,
DropdownModule
DropdownModule,
ButtonModule,
],
declarations: [
AppComponent,
Expand Down Expand Up @@ -77,7 +79,7 @@ import { MessageService } from 'primeng/api';
},
{ provide: OAuthStorage, useValue: localStorage },
MessageService,
ConfirmationService,
ConfirmationService
],
bootstrap: [AppComponent],
})
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// auth.guard.ts
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { AuthService } from './auth.service';
import { AuthService } from '../services/auth.service';

@Injectable({
providedIn: 'root',
Expand Down
16 changes: 16 additions & 0 deletions src/app/guard/with-token.guard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { WithTokenGuard } from './with-token.guard';

describe('WithTokenGuard', () => {
let guard: WithTokenGuard;

beforeEach(() => {
TestBed.configureTestingModule({});
guard = TestBed.inject(WithTokenGuard);
});

it('should be created', () => {
expect(guard).toBeTruthy();
});
});
19 changes: 19 additions & 0 deletions src/app/guard/with-token.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { AuthService } from '../services/auth.service';

@Injectable({
providedIn: 'root'
})
export class WithTokenGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) {}

canActivate(): boolean {
if (!this.authService.isAuthenticated()) {
return true;
} else {
this.router.navigate(['/videos']);
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TestBed } from '@angular/core/testing';
import { UserTokenInterceptor } from './user-token-interceptor.service';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { UserService } from './user.service';
import { UserService } from '../services/user.service';
import { HTTP_INTERCEPTORS } from '@angular/common/http';


Expand Down
14 changes: 9 additions & 5 deletions src/app/pages/active-account/active-account.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ export class ActiveAccountComponent implements OnInit {
if (this.userForm.valid) {
this.authService.activeAccount(this.userForm.value).subscribe({
next: (data) => {
console.log(data);
if (data.status === "error") {
this.alertService.showMessage("error", "Erro", data.message);
this.navigator("/login");
} else {
this.alertService.showMessage("success", "Sucesso", "Email ativado com sucesso!");
this.navigator("/login");
}
this.navigator("/login");
},
error: (error) => {
console.error(error);
console.log(error);
this.alertService.showMessage("error", "Erro", "Seu email ou código estão inválidos, preencha os campos corretamente.");
},
});
} else {
Expand All @@ -48,12 +50,14 @@ export class ActiveAccountComponent implements OnInit {

resendCode() {
if (this.userForm.value.email) {
console.log(this.userForm.value.email);
this.authService.resendCode(this.userForm.value.email).subscribe({
next: (data) => {
console.log(data);
this.alertService.showMessage("success", "Sucesso", "Email reenviado com sucesso!");
},
error: (error) => {
console.error(error);
console.log(error);
this.alertService.showMessage("error", "Erro", error.error.detail);
},
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<form [formGroup]="userForm" class="text-center">
<div class="mb-4">
<input
pInputText
class="w-64 h-8 border rounded-lg border-gray-300 pl-4 md:w-96 md:h-10"
type="email"
formControlName="email"
Expand All @@ -12,6 +13,7 @@
</div>
<div *ngIf="activeCode" class="mb-4">
<input
pInputText
class="w-64 h-8 border rounded-lg border-gray-300 pl-4 md:w-96 md:h-10"
type="text"
formControlName="code"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ export class CheckCodeRestPasswordComponent {
}

sendEmail() {
console.log(this.userForm.value);
console.log({email: this.userForm.value.email});

if (this.userForm.value.email) {
this.authService.sendEmailPassword({email: this.userForm.value.email}).subscribe({
next: (data) => {
console.log(data);
this.activeCode = true
this.alertService.showMessage("success", "Sucesso", "Email enviado para realizar a troca de senha.");
this.activeCode = true;
},
error: (error) => {
console.error(error);
this.alertService.showMessage("error", "Erro", "Email inválido!");
},
});
} else {
Expand All @@ -53,11 +50,11 @@ export class CheckCodeRestPasswordComponent {
if (this.userForm.valid) {
this.authService.verifyCodePassword(this.userForm.value).subscribe({
next: (data) => {
console.log(data);
this.alertService.showMessage("success", "Sucesso", "Código válido!");
this.navigator('/changePassword');
},
error: (error) => {
console.error(error);
this.alertService.showMessage("error", "Erro", error.error.detail);
},
});
} else {
Expand Down
14 changes: 6 additions & 8 deletions src/app/pages/edit-user/edit-user.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<div class="flex justify-center items-center h-4/5">
<form [formGroup]="userForm" (submit)="updateUser()" class="text-center">
<div class="mb-4">
Expand All @@ -8,13 +7,12 @@
<input pInputText class="w-64 h-8 border rounded-lg border-gray-300 pl-4" type="email" formControlName="email" name="email" placeholder="E-mail" required>
</div>
<div class="mb-4">
<select class="w-64 h-8 border rounded-lg border-gray-300 pl-3" formControlName="connection" name="connection" placeholder="Vinculo" required>
<option value="ALUNO">Aluno</option>
<option value="PROFESSOR">Professor</option>
<option value="COMUNIDADE-ACADEMICA">Comunidade Acadêmica</option>
<option value="EXTERNO">Externo</option>
</select>
<p-dropdown [style]="{width: '16rem',
height: '2.25rem',
textAlign: 'justify',
alignItems: 'center',
display: 'flex'}" [options]="vinculo" optionLabel="name" formControlName="connection" [showClear]="true" placeholder="Vinculo"></p-dropdown>
</div>
<button class="w-24 h-8 bg-blue-brand rounded-lg justify-center my-8 text-white" type="submit">Cadastrar</button>
<button class="w-24 h-8 bg-blue-brand rounded-lg justify-center my-8 text-white" type="submit">Editar</button>
</form>
</div>
85 changes: 71 additions & 14 deletions src/app/pages/edit-user/edit-user.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,106 @@ import { UserService } from 'src/app/services/user.service';
@Component({
selector: 'app-edit-user',
templateUrl: './edit-user.component.html',
styleUrls: ['./edit-user.component.css']
styleUrls: ['./edit-user.component.css'],
})
export class EditUserComponent implements OnInit {
userForm!: FormGroup;
userId: any;
userData: any
userData: any;
vinculo: any = {};

constructor(
private router: Router,
private fb: FormBuilder,
private userService: UserService,
private route: ActivatedRoute,
private alertService: AlertService,
private alertService: AlertService
) {}

ngOnInit(): void {
const userId = this.route.snapshot.params['id'];

console.log(userId);
this.userId = userId;

this.userForm = this.fb.group(
{
name: ['', [Validators.required]],
email: ['', [Validators.email, Validators.required]],
connection: ['', [Validators.required]],
this.getUser();
this.getVinculo();
this.initializeForm();
}

getUser() {
this.userService.getUser(this.userId).subscribe({
next: (data) => {
this.userData = data;
if (this.userData) {
this.initializeForm();
}
},
error: (error) => {
this.alertService.showMessage('error', 'Erro', error.error.detail);
},
});
}

initializeForm() {
this.userForm = this.fb.group({
name: [this.userData ? this.userData.name : '', [Validators.required]],
email: [
this.userData ? this.userData.email : '',
[Validators.email, Validators.required],
],
connection: [
this.userData ? this.userData.connection : '',
[Validators.required],
],
});

if (this.userData && this.userData.connection) {
this.userForm.get('connection')?.setValue(this.userData.connection);
}
}

getVinculo() {
this.userService.getVinculo().subscribe({
next: (data) => {
this.vinculo = data.map((name: any) => {
return {
name: name,
};
});
},
error: (error) => {
this.alertService.showMessage('error', 'Erro', error.error.detail);
},
);
});
}

updateUser() {
if (this.userForm.valid) {
this.userService.updateUser(this.userId, this.userForm.value).subscribe({
if (this.userForm && this.userForm.valid) {
const data = {
...this.userForm.value,
connection: this.userForm.value.connection.name,
};
this.userService.updateUser(this.userId, data).subscribe({
next: (data) => {
console.log(data);
this.alertService.showMessage("success", "Sucesso", "Usuário cadastrado com sucesso!");
this.alertService.showMessage(
'success',
'Sucesso',
'Usuário atualizado com sucesso!'
);
this.navigator('/profile');
},
error: (error) => {
console.error(error);
this.alertService.showMessage('error', 'Erro', error.error.detail);
},
});
} else {
this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!");
this.alertService.showMessage(
'info',
'Alerta',
'Preencha todos os campos corretamente!'
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/login-social/login-social.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<button class="facebook-button"><span>Continuar com o Facebook</span></button>
<button class="email-button"><span>Continuar com e-mail</span></button>
<a href="" class="cadastro">Cadastra-se</a>


</div>

Loading

0 comments on commit 35ec49b

Please sign in to comment.