Skip to content

Commit

Permalink
Merge pull request #158 from wantero/master
Browse files Browse the repository at this point in the history
Esqueci minha senha e data de escolha
  • Loading branch information
ErisvaldoCorreia authored Dec 15, 2018
2 parents d862498 + cfa3d04 commit 404bece
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { PanelComponent } from './components/panel/panel.component';
import { AccountComponent } from './components/account/account.component';
import { ChangePasswordComponent } from './components/change-password/change-password.component';
import { ResetPasswordComponent } from './components/reset-password/reset-password.component';
import { ForgotPasswordComponent } from './components/forgot-password/forgot-password.component';
import { RequestedsComponent } from './components/book/requesteds/requesteds.component';
import { DonationsComponent } from './components/book/donations/donations.component';
import { ContactUsComponent } from './components/contact-us/contact-us.component';
Expand Down Expand Up @@ -72,6 +73,7 @@ import { ConfirmationDialogService } from './core/services/confirmation-dialog/c
AccountComponent,
ChangePasswordComponent,
ResetPasswordComponent,
ForgotPasswordComponent,
DonateComponent,
ContactUsComponent,
RequestComponent,
Expand Down
6 changes: 3 additions & 3 deletions src/app/components/book/details/details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class DetailsComponent implements OnInit {
private _scBook: BookService,
private _scUser: UserService,
private _activatedRoute: ActivatedRoute,
private router: Router,
private _router: Router,
private _modalService: NgbModal) {

if (this._scUser.getLoggedUserFromLocalStorage()) {
Expand Down Expand Up @@ -100,11 +100,11 @@ export class DetailsComponent implements OnInit {
});

modalRef.componentInstance.bookId = this.bookInfo.id;
modalRef.componentInstance.creationDate = this.bookInfo.creationDate;
modalRef.componentInstance.chooseDate = this.bookInfo.chooseDate;
}

onLoginBook() {
this.router.navigate(['/login'], { queryParams: { returnUrl: this._activatedRoute.snapshot.url.join('/') } });
this._router.navigate(['/login'], { queryParams: { returnUrl: this._activatedRoute.snapshot.url.join('/') } });
}

onConvertImageToBase64(event: any) {
Expand Down
4 changes: 3 additions & 1 deletion src/app/components/book/list/list.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ListComponent } from './list.component';

import { AppConfigModule } from '../../../app-config.module';
import { AlertService } from '../../../core/services/alert/alert.service';
import { ConfirmationDialogService } from '../../../core/services/confirmation-dialog/confirmation-dialog.service';

describe('ListComponent', () => {
let component: ListComponent;
Expand All @@ -28,7 +29,8 @@ describe('ListComponent', () => {
ReactiveFormsModule
],
providers: [
AlertService
AlertService,
ConfirmationDialogService
]
})
.compileComponents();
Expand Down
6 changes: 3 additions & 3 deletions src/app/components/book/request/request.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { AlertService } from '../../../core/services/alert/alert.service';
})
export class RequestComponent implements OnInit {
@Input() bookId;
@Input() creationDate;
@Input() chooseDate;
donateUsers: LocalDataSource;
settings: any;
isLoading: Boolean = true;
Expand Down Expand Up @@ -58,8 +58,8 @@ export class RequestComponent implements OnInit {
this.addressLine02 = updateUserVM.address.neighborhood + ' - ' + updateUserVM.address.city + ' - ' + updateUserVM.address.state;
this.addressLine03 = 'CEP: ' + updateUserVM.address.postalCode + ' - ' + updateUserVM.address.country;

this.finishDate = new Date(this.creationDate);
this.finishDate.setDate(this.finishDate.getDate() + 5);
this.finishDate = new Date(this.chooseDate);
this.finishDate.setDate(this.finishDate.getDate());
});
}

Expand Down
14 changes: 14 additions & 0 deletions src/app/components/forgot-password/forgot-password.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
form i.fa {
position: absolute;
top: 8px;
left: 15px;
color: #2098D1;
font-size: 22px;
z-index: 99;
}

.form-control {
position: relative;
padding-left: 45px !important;

}
56 changes: 56 additions & 0 deletions src/app/components/forgot-password/forgot-password.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<form [formGroup]="formGroup" class="container form-horizontal" (ngSubmit)="changePassword()">
<input formControlName="hashCodePassword" type="hidden" class="form-control">
<h1 class="text-center display-4">Redefinir Senha</h1>
<div class="form-row">
<div class="col">

<div class="form-group col-md-6 offset-md-3 mb-2">
<label class="col-form-label" for="newPassword">Nova Senha</label>
<div class="input-group">
<input formControlName="newPassword" type="password" class="form-control">
<div class="input-group-addon append">
<i class="fa fa-unlock-alt"></i>
</div>
</div>

<div *ngIf="formGroup.controls['newPassword'].touched && !formGroup.controls['newPassword'].valid">
<small class="form-text text-danger" *ngIf="formGroup.controls['newPassword'].hasError('required')">
Nova senha obrigatória.
</small>
<small class="form-text text-danger" *ngIf="formGroup.controls['newPassword'].hasError('pattern')">
A senha não atende os requisitos. Mínimo oito caracteres, um caractere especial
(&#64;&#36;&#33;&#37;&#42;&#63;&#38;&#35;&#46;&#44;&#45;&#95;&#58;&#59;), um caractere numérico e uma letra
em maiúsculo.
</small>
</div>
</div>

<div class="form-group col-md-6 offset-md-3 mb-2">
<label class="col-form-label" for="confirmPassword">Confirmar Nova Senha</label>
<div class="input-group">
<input formControlName="confirmPassword" type="password" class="form-control">
<div class="input-group-addon append">
<i class="fa fa-unlock-alt"></i>
</div>
</div>

<div *ngIf="formGroup.controls['confirmPassword'].touched && !formGroup.controls['confirmPassword'].valid">
<small class="form-text text-danger" *ngIf="formGroup.controls['confirmPassword'].hasError('required')">
Confirmação de senha obrigatória.
</small>
<small class="form-text text-danger" *ngIf="formGroup.controls['confirmPassword'].hasError('MatchPassword') ">
A confirmação de senha não confere com a nova senha informada.
</small>
</div>
</div>

<div class="form-group col-md-6 offset-md-3">
<div class="text-center">
<input type="submit" class="btn btn-primary" value="Redefinir" style="padding-left: 50px; padding-right: 50px"
[disabled]="!formGroup.valid">
<a [routerLink]="['/login']" class="btn btn-link">Cancelar</a>
</div>
</div>
</div>
</div>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClient, HttpHandler } from '@angular/common/http';

import { ForgotPasswordComponent } from './forgot-password.component';

import { AppConfigModule } from '../../app-config.module';
import { UserService } from '../../core/services/user/user.service';
import { AlertService } from '../../core/services/alert/alert.service';

describe('ForgotPasswordComponent', () => {
let component: ForgotPasswordComponent;
let fixture: ComponentFixture<ForgotPasswordComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ForgotPasswordComponent
],
imports: [
FormsModule,
ReactiveFormsModule,
RouterTestingModule,
AppConfigModule
],
providers: [
UserService,
HttpClient,
HttpHandler,
AlertService
]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ForgotPasswordComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
69 changes: 69 additions & 0 deletions src/app/components/forgot-password/forgot-password.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators, FormArray, FormControl } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';

import { UserService } from '../../core/services/user/user.service';
import { AlertService } from '../../core/services/alert/alert.service';
import { PasswordValidation } from '../../core/utils/passwordValidation';
import * as AppConst from '../../core/utils/app.const';

@Component({
selector: 'app-forgot-password',
templateUrl: './forgot-password.component.html',
styleUrls: ['./forgot-password.component.css']
})
export class ForgotPasswordComponent implements OnInit {

formGroup: FormGroup;

constructor(
private _activatedRoute: ActivatedRoute,
private _router: Router,
private _formBuilder: FormBuilder,
private _scUser: UserService,
private _scAlert: AlertService
) {
this.formGroup = _formBuilder.group({
hashCodePassword: ['', Validators.required],
newPassword: ['', [Validators.required, Validators.pattern(AppConst.passwordPattern)]],
confirmPassword: ['', [Validators.required]]
}, {
validator: PasswordValidation.MatchPassword
});
}

ngOnInit() {
let hashCodePassword = '';
this._activatedRoute.params.subscribe((param) => {
hashCodePassword = param.hashCodePassword;

const changeUserPasswordByHashCodeVM = {
hashCodePassword: hashCodePassword,
newPassword: '',
confirmPassword: ''
};

this.formGroup.setValue(changeUserPasswordByHashCodeVM);
});

}

changePassword() {
if (this.formGroup.valid) {
this._scUser.changeUserPasswordByHashCode(this.formGroup.value).subscribe(
data => {
if (data.success || data.authenticated) {
this._scAlert.success('Senha atualizada com sucesso', true);
this._router.navigate(['/login']);
} else {
this._scAlert.error(data.messages[0]);
}
},
error => {
this._scAlert.error(error);
}
);
}
}

}
4 changes: 2 additions & 2 deletions src/app/components/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ <h1 class="text-center display-4">Login</h1>
[disabled]="!formGroup.valid">
</div>
<div class="text-center">
<p><a [routerLink]="['/register']" class="btn btn-link">Criar Conta</a></p> <!--remover o fechamento do paragrafo após -->
<!-- ou <a [routerLink]="['/reset-password']" class="btn btn-link">Resetar Senha</a></p> -->
<p><a [routerLink]="['/register']" class="btn btn-link">Criar Conta</a>
ou <a [routerLink]="['/reset-password']" class="btn btn-link">Redefinir Senha</a></p>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<form [formGroup]="formGroup" class="container form-horizontal" (ngSubmit)="resetPassword()">
<h1 class="text-center display-4">Resetar Senha</h1>
<h1 class="text-center display-4">Redefinir Senha</h1>
<div class="form-row">
<div class="col">
<div class="form-group col-md-6 offset-md-3 mb-2">
Expand All @@ -23,7 +23,7 @@ <h1 class="text-center display-4">Resetar Senha</h1>

<div class="form-group col-md-6 offset-md-3">
<div class="text-center">
<input type="submit" class="btn btn-primary" value="Resetar" style="padding-left: 50px; padding-right: 50px"
<input type="submit" class="btn btn-primary" value="Redefinir" style="padding-left: 50px; padding-right: 50px"
[disabled]="!formGroup.valid">
<a [routerLink]="['/panel']" class="btn btn-link">Cancelar</a>
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/app/core/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { QuemSomosComponent } from '../components/quem-somos/quem-somos.componen
import { ApoieProjetoComponent } from '../components/apoie-projeto/apoie-projeto.component';
import { ChangePasswordComponent } from '../components/change-password/change-password.component';
import { ResetPasswordComponent } from '../components/reset-password/reset-password.component';
import { ForgotPasswordComponent } from '../components/forgot-password/forgot-password.component';
import { ContactUsComponent } from '../components/contact-us/contact-us.component';
import { RequestedsComponent } from '../components/book/requesteds/requesteds.component';
import { DonationsComponent } from '../components/book/donations/donations.component';
Expand Down Expand Up @@ -93,6 +94,10 @@ const routes: Routes = [
path: 'reset-password',
component: ResetPasswordComponent
},
{
path: 'ForgotPassword/:hashCodePassword',
component: ForgotPasswordComponent
},
{
path: 'contact-us',
component: ContactUsComponent,
Expand Down
4 changes: 4 additions & 0 deletions src/app/core/models/ChangeUserPasswordByHashCodeVM.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class ChangeUserPasswordByHashCodeVM {
hashCodePassword: string;
newPassword: string;
}
3 changes: 3 additions & 0 deletions src/app/core/models/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ export class Book {
freightOption: string;
category: Category;
creationDate: Date;
chooseDate: Date;
synopsis: string;
}

// - TODO: Adequar o model para ficar igual ao do Backend
5 changes: 5 additions & 0 deletions src/app/core/services/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { map } from 'rxjs/operators';
import { User } from '../../models/user';
import { UpdateUserVM } from '../../models/updateUserVM';
import { ChangePasswordUserVM } from '../../models/ChangePasswordUserVM';
import { ChangeUserPasswordByHashCodeVM } from '../../models/ChangeUserPasswordByHashCodeVM';
import { Profile } from '../../models/profile';

import { APP_CONFIG, AppConfig } from '../../../app-config.module';
Expand Down Expand Up @@ -50,6 +51,10 @@ export class UserService {
return this._http.post<any>(`${this.config.apiEndpoint}/Account/ForgotMyPassword/` + email, null);
}

changeUserPasswordByHashCode(changeUserPasswordByHashCodeVM: ChangeUserPasswordByHashCodeVM) {
return this._http.put<any>(`${this.config.apiEndpoint}/Account/ChangeUserPasswordByHashCode/`, changeUserPasswordByHashCodeVM);
}

delete(id: number) {
// return this._http.delete(`${this.config.apiEndpoint}/users/` + id);
}
Expand Down

0 comments on commit 404bece

Please sign in to comment.