Skip to content
Snippets Groups Projects
Select Git revision
  • c2d49d8f38261a60b1818e6280dd1021cce560e8
  • main default protected
2 results

login.service.ts

Blame
  • Forked from an inaccessible project.
    login.service.ts 1.37 KiB
    import { Injectable } from '@angular/core';
    import * as CryptoJS from 'crypto-js';
    import {FormControl, FormGroup, Validators} from "@angular/forms";
    
    export enum ErrorLogin {
      PassConfirm ,
      UserNameExist,
      UserNotExist ,
      UserPassword
    }
    @Injectable({
      providedIn: 'root'
    })
    export class LoginService {
      private _actualError!: ErrorLogin;
    
    
      get actualError():ErrorLogin{
        return this._actualError
      }
    
    
      set actualError(value: ErrorLogin){
        this._actualError=value;
      }
      constructor() { }
    
      hashPassword(password: string): string {
        const hash = CryptoJS.SHA256(password);
        return hash.toString(CryptoJS.enc.Base64);
      }
    
      formDataCreate():FormGroup{
        return new FormGroup({
          username: new FormControl(null, {
            updateOn: 'change',
            validators: [Validators.required],
          }),
          firstname: new FormControl(null, {
            updateOn: 'change',
            validators: [Validators.required],
          }),
          lastname: new FormControl(null, {
            updateOn: 'change',
            validators: [Validators.required],
          }),
          email: new FormControl(null, {
            updateOn: 'change',
            validators: [Validators.required],
          }),
          password: new FormControl(null, {
            updateOn: 'change',
            validators: [Validators.required],
          }),
          accountType: new FormControl("User", {
            updateOn: 'change'
          })
        });
      }
    }