Skip to content

Instantly share code, notes, and snippets.

Avatar

SUNIL KUMAR B sunilkumarmedium

  • BENGALURU, INDIA
  • Joined Oct 28, 2020
View GitHub Profile
View auth.guard.ts
import { Injectable } from '@angular/core';
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { AuthenticationService } from '../_services/authentication/authentication.service';
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
View global-error.service.ts
import { ErrorHandler, Injectable, Injector } from '@angular/core';
import { ToastService } from '../toast/toast.service';
@Injectable({
providedIn: 'root'
})
export class GlobalErrorService implements ErrorHandler{
constructor(
private injector: Injector
View jwt.inteceptor.ts
import { AuthenticationService } from './../_services/authentication/authentication.service';
import { environment } from './../../environments/environment';
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpInterceptor
} from '@angular/common/http';
import { Observable } from 'rxjs';
View authentication.service.ts
import { environment } from './../../../environments/environment';
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { User } from 'src/app/_models/user.model';
import { ApiResponse } from '../../_models/api-response';
@Injectable({
View user.model.ts
export interface User {
id: string| undefined;
username: string| undefined;
firstname: string| undefined;
lastname: string| undefined;
status: string | undefined;
createddate: any;
token: string | undefined;
refreshToken: string | undefined;
}
View login.component.ts
import { AuthenticationService } from './../../../_services/authentication/authentication.service';
import { ActivatedRoute, Router } from '@angular/router';
import { Component, OnInit, Injector } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { first } from 'rxjs/operators';
import { ToastService } from 'src/app/_services/toast/toast.service';
import { HttpErrorResponse } from '@angular/common/http';
@Component({
templateUrl: './login.component.html',
View login.component.html
<div class="card shadow p-3 mb-5 bg-white rounded card-top">
<h4 class="card-header">Login</h4>
<div class="card-body">
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="username">Username</label>
<input type="text" formControlName="username" class="form-control" [ngClass]="{ 'is-invalid': submitted && formControls.username.errors }" />
<div *ngIf="submitted && formControls.username.errors" class="invalid-feedback">
View CreateUserCommandValidator.cs
namespace CleanArchitectureApp.Application.Features.Users.Commands
{
public class CreateUserCommandValidator : AbstractValidator<CreateUserCommand>
{
private readonly IUserRepositoryAsync userRepository;
public CreateUserCommandValidator(IUserRepositoryAsync userRepository)
{
this.userRepository = userRepository;
View UserMap.cs
namespace CleanArchitectureApp.Infrastructure.Persistence.Repositories
{
public partial class UserMap : ClassMapping<Domain.User>
{
public UserMap()
{
Schema("dbo");
Table("Users");
Lazy(true);
Id(x => x.UserId, map =>
View User.cs
namespace CleanArchitectureApp.Domain
{
public class User : AuditableBaseEntity
{
public User()
{
UserTokens = new List<UserToken>();
}
public virtual Guid UserId { get; set; }
You can’t perform that action at this time.