Guest User

Untitled

a guest
Jun 24th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.03 KB | None | 0 0
  1. export class User{
  2.  
  3. id:number;
  4. username:string;
  5. password:string;
  6. prenom:string;
  7. nom:string;
  8. tel:string;
  9. cin:string ;
  10.  
  11. setId(value: number) {
  12. this.id = value;
  13. }
  14.  
  15. setUsername(value: string) {
  16. this.username = value;
  17. }
  18.  
  19. setPassword(value: string) {
  20. this.password = value;
  21. }
  22.  
  23. setPrenom(value: string) {
  24. this.prenom = value;
  25. }
  26.  
  27. setNom(value: string) {
  28. this.nom = value;
  29. }
  30.  
  31. setTel(value: string) {
  32. this.tel = value;
  33. }
  34.  
  35. setCin(value: string) {
  36. this.cin = value;
  37. }
  38.  
  39.  
  40.  
  41. }
  42.  
  43. import { Component, OnInit } from '@angular/core';
  44. import * as _swal from 'sweetalert';
  45. import { SweetAlert } from 'sweetalert/typings/core';
  46. import {AbstractControl, FormBuilder, FormGroup, Validators} from '@angular/forms';
  47. import {ActivatedRoute, Router} from '@angular/router';
  48. import {User} from '../Admin/Models/User';
  49. import {Devloppeur} from '../Admin/Models/Devloppeur';
  50. import {DevloppeurService} from '../../../service/devloppeur.service';
  51. import {ClientService} from '../../../service/client.service';
  52. import {AuthenticationService} from '../../../service/authentication.service';
  53. const swal: SweetAlert = _swal as any;
  54.  
  55. function passwordMatch(control: AbstractControl):{[key: string]: boolean}{
  56.  
  57. const password = control.get('password');
  58. const Confirmationpassword = control.get('Confirmationpassword');
  59.  
  60. if( !password || !Confirmationpassword) {
  61. return null; }
  62.  
  63. if(password.value === Confirmationpassword.value){
  64. return null;
  65. }
  66.  
  67. return {
  68. mismatch:true
  69. }
  70.  
  71. }
  72.  
  73. @Component({
  74. selector: 'app-parametres',
  75. templateUrl: './parametres.component.html',
  76. styleUrls: ['./parametres.component.scss']
  77. })
  78. export class ParametresComponent implements OnInit {
  79.  
  80. form: FormGroup;
  81. user:User = new User();
  82. id:number;
  83. constructor(private formBuilder: FormBuilder,
  84. public router:Router,
  85. private authService:AuthenticationService,
  86. public activatedRoute:ActivatedRoute,
  87. private devService:DevloppeurService,
  88. private clientServ:ClientService) { }
  89.  
  90. ngOnInit() {
  91. this.id = this.authService.getAuthenticatedUserId();
  92. this.getUserInfo();
  93.  
  94. this.form = this.formBuilder.group({
  95. prenom: [''] ,
  96. nom: [''],
  97. tel: ['', Validators.required],
  98. cin: [''],
  99. username : [''],
  100. passwordG: this.formBuilder.group({
  101. password: ['',[Validators.required,Validators.minLength(9)]],
  102. Confirmationpassword : ['',[Validators.required,Validators.minLength(9)]]
  103.  
  104. }, {validator: passwordMatch})
  105.  
  106. });
  107. }
  108.  
  109. getUserInfo(){
  110. this.clientServ.getUser(this.id)
  111. .subscribe((data:any)=>{
  112. this.user = data;
  113. },err=>{
  114. console.log('there is an error lady ! ');
  115. })
  116.  
  117. }
  118.  
  119.  
  120. SaveEditUser(){
  121. this.user.setPassword(this.form.value.passwordG.password);
  122. this.user.setTel(this.form.value.tel);
  123.  
  124.  
  125. this.devService.saveUser(this.user)
  126. .subscribe((data:User)=>{
  127. swal("operation réussi !", "Great edited with success !", "success");
  128. this.router.navigate([ '/profil' ], { relativeTo: this.activatedRoute });
  129. },err=>{
  130. console.log(err);
  131. })
  132. }
  133.  
  134.  
  135. }
  136.  
  137. <div >
  138. <div class="col-sm-10">
  139. <div class="card">
  140. <div class="card-header">
  141. <strong>Modifier mon profil</strong>
  142. </div>
  143.  
  144. <form [formGroup]="form" (ngSubmit)="SaveEditUser()">
  145.  
  146. <div class="card-body">
  147. <div class="form-group">
  148. <label for="company">Prenom</label>
  149. <input type="text" class="form-control" id="company" disabled [(ngModel)]="user.prenom" formControlName="prenom"/>
  150. </div>
  151. <div class="form-group">
  152. <label for="vat">Nom</label>
  153. <input type="text" class="form-control" id="vat" disabled [(ngModel)]="user.nom" formControlName="nom" />
  154. </div>
  155. <div class="form-group">
  156. <label for="vat">Tel</label>
  157. <input type="number" class="form-control" id="vat" [(ngModel)]="user.tel" formControlName="tel" />
  158. </div>
  159. <div class="form-group">
  160. <label for="vat">Cin</label>
  161. <input type="text" class="form-control" id="vat" disabled [(ngModel)]="user.cin" formControlName="cin" />
  162. </div>
  163. <div class="form-group">
  164. <label for="vat">Email</label>
  165. <input type="text" class="form-control" id="vat" disabled [(ngModel)]="user.username" formControlName="username" />
  166. <div class="error" *ngIf="form.controls['username'].invalid && form.controls['username'].errors.required && (form.controls['username'].dirty || form.controls['username'].touched)">Please enter an email</div>
  167. <div class="error" *ngIf="form.controls['username'].invalid && form.controls['username'].errors.email && (form.controls['username'].dirty || form.controls['username'].touched)">Please enter a valid email</div>
  168. <div class="error" *ngIf="form.controls['username'].invalid && form.controls['username'].errors.emailTaken">This email has been taken, please use another one.</div>
  169. </div>
  170.  
  171.  
  172. <div formGroupName = "passwordG">
  173.  
  174. <div class="form-group">
  175. <label for="vat">Password</label>
  176. <input type="password" class="form-control" id="vat" formControlName="password" />
  177. </div>
  178.  
  179. <div class="form-group">
  180. <label for="vat">Confirmation Password</label>
  181. <input type="password" class="form-control" id="vat" formControlName="Confirmationpassword" />
  182. </div>
  183.  
  184.  
  185. <div *ngIf="(form.controls['passwordG'].invalid && form.controls['passwordG'].touched)" class="col-sm-3 text-danger">
  186.  
  187. <ng-container *ngIf="form.controls['passwordG'].errors?.mismatch;
  188. then first else second"> </ng-container>
  189.  
  190. <ng-template #first>
  191. Password do not match </ng-template>
  192.  
  193. <ng-template #second>
  194. Password needs to be more than 8 characters
  195. </ng-template>
  196. </div>
  197.  
  198. </div>
  199.  
  200. </div>
  201. <div class="card-footer">
  202. <button type="submit" class="btn btn-sm btn-primary" [disabled] = "!form.valid"><i class="fa fa-dot-circle-o"></i>Enregistrer Les modifications</button>
  203. </div>
  204. </form>
  205. </div>
  206. </div><!--/.col-->
  207. </div>
  208.  
  209. ParametresComponent.html:8 ERROR TypeError: this.user.setPassword is not a function
  210. at ParametresComponent.SaveEditUser (parametres.component.ts:79)
  211. at Object.eval [as handleEvent] (ParametresComponent.html:8)
  212. at handleEvent (core.js:13530)
  213. at callWithDebugContext (core.js:15039)
  214. at Object.debugHandleEvent [as handleEvent] (core.js:14626)
  215. at dispatchEvent (core.js:9945)
  216. at eval (core.js:12284)
  217. at SafeSubscriber.schedulerFn [as _next] (core.js)
Add Comment
Please, Sign In to add comment