Skip to content

Instantly share code, notes, and snippets.

Elmar Putz elmarputz

  • Studio Mitte Digital Media GmbH
  • Linz, Austria
View GitHub Profile
View interceptor
import {Injectable} from "@angular/core";
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http";
import {Observable} from 'rxjs';
export class TokenInterceptorService implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
request = request.clone({
View auth service
import {Injectable} from '@angular/core';
import {isNullOrUndefined} from "util";
import {HttpClient} from "@angular/common/http";
import * as decode from 'jwt-decode';
import {retry} from 'rxjs/operators';
//npm install --save-dev jwt-decode
interface User {
result: {
View login
<div *ngIf="!isLoggedIn()">
<form class="ui large form" [formGroup]="loginForm" (ngSubmit)="login()">
<div class="field">
<input type="email" id="username" formControlName="username">
<div *ngIf="loginForm.get('username').invalid &&
(loginForm.get('username').dirty || loginForm.get('username').touched) &&
loginForm.get('username').hasError('required')" class="ui negative message">
View gist:daace6e4f48cfa7c30d2fced9ba9f2d1
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.0.0",
"barryvdh/laravel-cors": "^0.11.3",
"fideloper/proxy": "~3.3",
View gist:f35e76efbfff385f737b93abc511f645
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use JWTAuth;
use JWTAuthException;
use App\User;
class ApiAuthController extends Controller
View gist:f006397aac64bf591b05a77e521b5c22
export class ErrorMessage {
public forControl: string,
public forValidator: string,
public text: string
) { }
export const BookFormErrorMessages = [
new ErrorMessage('title', 'required', 'Ein Buchtitel muss angegeben werden'),
new ErrorMessage('isbn', 'required', 'Es muss eine ISBN angegeben werden'),
View bookform.ts
import { ActivatedRoute, Router } from '@angular/router';
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, FormArray, Validators } from '@angular/forms';
import { BookFormErrorMessages } from './book-form-error-messages';
import {BookFactory} from "../shared/book-factory";
import {BookStoreService} from "../shared/book-store.service";
import {Book, Image} from "../shared/book";
View gist:bd0cb2d81545be2285cd917cde95afdc
<form class="ui large form" [formGroup]="bookForm" (ngSubmit)="submitForm()">
<input type="hidden" name="id">
<div class="field">
<input formControlName="title">
<div *ngIf="errors.title" class="ui negative message"> {{ errors.title }} </div>
<div class="field">
View book-factory.ts
import { Book } from './book';
export class BookFactory {
static empty(): Book {
return new Book(null, '', '', [], new Date(),0, '', 0, [{id: 0, url: '', title: ''}], '');
static fromObject(rawBook: any): Book {
return new Book(
View gist:fa882a84cb1b87fc1c8aeb4b76f9597e
import { NgModule } from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import { BookDetailsComponent } from './book-details/book-details.component';
import { BookListComponent } from './book-list/book-list.component';
import { HomeComponent } from './home/home.component';
const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
You can’t perform that action at this time.