├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── browserslist ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.json ├── karma.conf.js ├── package.json ├── src ├── app │ ├── admin │ │ ├── admin-dashboard │ │ │ ├── admin-dashboard.component.html │ │ │ ├── admin-dashboard.component.scss │ │ │ ├── admin-dashboard.component.spec.ts │ │ │ └── admin-dashboard.component.ts │ │ ├── admin-routing.module.ts │ │ ├── admin.component.html │ │ ├── admin.component.scss │ │ ├── admin.component.spec.ts │ │ ├── admin.component.ts │ │ └── admin.module.ts │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.scss │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── auth.guard.spec.ts │ ├── auth.guard.ts │ ├── auth.service.spec.ts │ ├── auth.service.ts │ ├── book │ │ ├── book.component.html │ │ ├── book.component.scss │ │ ├── book.component.spec.ts │ │ ├── book.component.ts │ │ ├── book.module.ts │ │ ├── book.service.spec.ts │ │ ├── book.service.ts │ │ └── book.ts │ ├── cookie.ts │ ├── login │ │ ├── login.component.html │ │ ├── login.component.scss │ │ ├── login.component.spec.ts │ │ └── login.component.ts │ ├── page-not-found │ │ ├── page-not-found.component.html │ │ ├── page-not-found.component.scss │ │ ├── page-not-found.component.spec.ts │ │ └── page-not-found.component.ts │ ├── register │ │ ├── register.component.html │ │ ├── register.component.scss │ │ ├── register.component.spec.ts │ │ └── register.component.ts │ └── user.ts ├── assets │ └── .gitkeep ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.scss └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json ├── tslint.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AngularLaravel 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.0.0-rc.3. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | 29 | # angular-laravel 30 | - First clone via `git bash` or download. 31 | - Go to your root folder and run this command to install packages. 32 | ``` 33 | yarn 34 | ``` 35 | - Download [laravel-api](https://github.com/eliyas5044/laravel-api), which i used as a RESTful api and follow the instructions to run your api. 36 | - You may change the `api` url in `environment` file. 37 | - Run your `angular` app by this command 38 | ``` 39 | yarn start 40 | ``` 41 | - You have to **login** or **register** to view all **books** 42 | - The *book* url is `http://localhost:4200/admin/book` 43 | 44 | ## Enjoy! 45 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular-laravel": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/angular-laravel", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "aot": true, 26 | "assets": [ 27 | "src/favicon.ico", 28 | "src/assets" 29 | ], 30 | "styles": [ 31 | "src/styles.scss" 32 | ], 33 | "scripts": [] 34 | }, 35 | "configurations": { 36 | "production": { 37 | "fileReplacements": [ 38 | { 39 | "replace": "src/environments/environment.ts", 40 | "with": "src/environments/environment.prod.ts" 41 | } 42 | ], 43 | "optimization": true, 44 | "outputHashing": "all", 45 | "sourceMap": false, 46 | "extractCss": true, 47 | "namedChunks": false, 48 | "extractLicenses": true, 49 | "vendorChunk": false, 50 | "buildOptimizer": true, 51 | "budgets": [ 52 | { 53 | "type": "initial", 54 | "maximumWarning": "2mb", 55 | "maximumError": "5mb" 56 | }, 57 | { 58 | "type": "anyComponentStyle", 59 | "maximumWarning": "6kb", 60 | "maximumError": "10kb" 61 | } 62 | ] 63 | } 64 | } 65 | }, 66 | "serve": { 67 | "builder": "@angular-devkit/build-angular:dev-server", 68 | "options": { 69 | "browserTarget": "angular-laravel:build" 70 | }, 71 | "configurations": { 72 | "production": { 73 | "browserTarget": "angular-laravel:build:production" 74 | } 75 | } 76 | }, 77 | "extract-i18n": { 78 | "builder": "@angular-devkit/build-angular:extract-i18n", 79 | "options": { 80 | "browserTarget": "angular-laravel:build" 81 | } 82 | }, 83 | "test": { 84 | "builder": "@angular-devkit/build-angular:karma", 85 | "options": { 86 | "main": "src/test.ts", 87 | "polyfills": "src/polyfills.ts", 88 | "tsConfig": "tsconfig.spec.json", 89 | "karmaConfig": "karma.conf.js", 90 | "assets": [ 91 | "src/favicon.ico", 92 | "src/assets" 93 | ], 94 | "styles": [ 95 | "src/styles.scss" 96 | ], 97 | "scripts": [] 98 | } 99 | }, 100 | "lint": { 101 | "builder": "@angular-devkit/build-angular:tslint", 102 | "options": { 103 | "tsConfig": [ 104 | "tsconfig.app.json", 105 | "tsconfig.spec.json", 106 | "e2e/tsconfig.json" 107 | ], 108 | "exclude": [ 109 | "**/node_modules/**" 110 | ] 111 | } 112 | }, 113 | "e2e": { 114 | "builder": "@angular-devkit/build-angular:protractor", 115 | "options": { 116 | "protractorConfig": "e2e/protractor.conf.js", 117 | "devServerTarget": "angular-laravel:serve" 118 | }, 119 | "configurations": { 120 | "production": { 121 | "devServerTarget": "angular-laravel:serve:production" 122 | } 123 | } 124 | } 125 | } 126 | } 127 | }, 128 | "defaultProject": "angular-laravel", 129 | "cli": { 130 | "analytics": "0970e103-3972-4e99-a3b6-aadefb8547f0" 131 | } 132 | } -------------------------------------------------------------------------------- /browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('angular-laravel app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/angular-laravel'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-laravel", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~9.0.0-rc.3", 15 | "@angular/common": "~9.0.0-rc.3", 16 | "@angular/compiler": "~9.0.0-rc.3", 17 | "@angular/core": "~9.0.0-rc.3", 18 | "@angular/forms": "~9.0.0-rc.3", 19 | "@angular/platform-browser": "~9.0.0-rc.3", 20 | "@angular/platform-browser-dynamic": "~9.0.0-rc.3", 21 | "@angular/router": "~9.0.0-rc.3", 22 | "rxjs": "~6.5.3", 23 | "tslib": "^1.10.0", 24 | "zone.js": "~0.10.2" 25 | }, 26 | "devDependencies": { 27 | "@angular-devkit/build-angular": "~0.900.0-rc.3", 28 | "@angular/cli": "~9.0.0-rc.3", 29 | "@angular/compiler-cli": "~9.0.0-rc.3", 30 | "@angular/language-service": "~9.0.0-rc.3", 31 | "@types/node": "^12.11.1", 32 | "@types/jasmine": "~3.4.0", 33 | "@types/jasminewd2": "~2.0.3", 34 | "codelyzer": "^5.1.2", 35 | "jasmine-core": "~3.5.0", 36 | "jasmine-spec-reporter": "~4.2.1", 37 | "karma": "~4.3.0", 38 | "karma-chrome-launcher": "~3.1.0", 39 | "karma-coverage-istanbul-reporter": "~2.1.0", 40 | "karma-jasmine": "~2.0.1", 41 | "karma-jasmine-html-reporter": "^1.4.2", 42 | "protractor": "~5.4.2", 43 | "ts-node": "~8.3.0", 44 | "tslint": "~5.18.0", 45 | "typescript": "~3.6.4" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/app/admin/admin-dashboard/admin-dashboard.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Dashboard

4 |

This is the sample dashboard, you can find all books in book tab.

5 |
6 |
7 |
8 |

Your Information

9 |
    10 |
  • Name: {{user.name}}
  • 11 |
  • Email: {{user.email}}
  • 12 |
13 |
14 |
15 | -------------------------------------------------------------------------------- /src/app/admin/admin-dashboard/admin-dashboard.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliyas5044/angular-laravel/73dde72d0420069325275a6e5b6d196e78549572/src/app/admin/admin-dashboard/admin-dashboard.component.scss -------------------------------------------------------------------------------- /src/app/admin/admin-dashboard/admin-dashboard.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AdminDashboardComponent } from './admin-dashboard.component'; 4 | 5 | describe('AdminDashboardComponent', () => { 6 | let component: AdminDashboardComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AdminDashboardComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AdminDashboardComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/admin/admin-dashboard/admin-dashboard.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { User } from '../../user'; 3 | import { AuthService } from '../../auth.service'; 4 | 5 | @Component({ 6 | selector: 'app-admin-dashboard', 7 | templateUrl: './admin-dashboard.component.html', 8 | styleUrls: ['./admin-dashboard.component.scss'] 9 | }) 10 | export class AdminDashboardComponent implements OnInit { 11 | user: User; 12 | 13 | constructor(private authService: AuthService) { 14 | } 15 | 16 | ngOnInit() { 17 | this.authService.userObject.subscribe(res => this.user = res); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/app/admin/admin-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { AdminComponent } from './admin.component'; 4 | import { AdminDashboardComponent } from './admin-dashboard/admin-dashboard.component'; 5 | import { BookComponent } from '../book/book.component'; 6 | import { AuthGuard } from '../auth.guard'; 7 | 8 | const adminRoutes: Routes = [ 9 | { 10 | path: '', 11 | component: AdminComponent, 12 | canActivate: [AuthGuard], 13 | children: [ 14 | { 15 | path: 'book', 16 | component: BookComponent 17 | }, 18 | { 19 | path: '', 20 | component: AdminDashboardComponent 21 | } 22 | ] 23 | } 24 | ]; 25 | 26 | @NgModule({ 27 | imports: [ 28 | RouterModule.forChild(adminRoutes) 29 | ], 30 | exports: [ 31 | RouterModule 32 | ] 33 | }) 34 | export class AdminRoutingModule { 35 | } 36 | -------------------------------------------------------------------------------- /src/app/admin/admin.component.html: -------------------------------------------------------------------------------- 1 | 24 | 25 |
26 | 27 |
28 | 29 | -------------------------------------------------------------------------------- /src/app/admin/admin.component.scss: -------------------------------------------------------------------------------- 1 | ul { 2 | .nav-item { 3 | margin-left: 5px; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/app/admin/admin.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AdminComponent } from './admin.component'; 4 | 5 | describe('AdminComponent', () => { 6 | let component: AdminComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AdminComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AdminComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/admin/admin.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { AuthService } from '../auth.service'; 3 | import { Router } from '@angular/router'; 4 | import { deleteCookie } from '../cookie'; 5 | import { User } from '../user'; 6 | 7 | @Component({ 8 | selector: 'app-admin', 9 | templateUrl: './admin.component.html', 10 | styleUrls: ['./admin.component.scss'] 11 | }) 12 | export class AdminComponent implements OnInit { 13 | isLoggedIn = false; 14 | private token: string; 15 | 16 | constructor(private authService: AuthService, 17 | private router: Router) { 18 | } 19 | 20 | ngOnInit() { 21 | this.authService.token.subscribe(res => this.token = res); 22 | this.authService.isUserLoggedIn.subscribe(res => this.isLoggedIn = res); 23 | } 24 | 25 | logout() { 26 | this.authService.logout(this.token).subscribe(res => { 27 | deleteCookie('token'); 28 | deleteCookie('user'); 29 | this.authService.token.next(null); 30 | this.authService.userObject.next(new User()); 31 | this.authService.isUserLoggedIn.next(false); 32 | this.router.navigateByUrl('login'); 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/app/admin/admin.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { BookModule } from '../book/book.module'; 4 | import { AdminRoutingModule } from './admin-routing.module'; 5 | import { AdminComponent } from './admin.component'; 6 | import { AdminDashboardComponent } from './admin-dashboard/admin-dashboard.component'; 7 | 8 | @NgModule({ 9 | imports: [ 10 | CommonModule, 11 | BookModule, 12 | AdminRoutingModule 13 | ], 14 | declarations: [AdminComponent, AdminDashboardComponent] 15 | }) 16 | export class AdminModule { 17 | } 18 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { LoginComponent } from './login/login.component'; 4 | import { RegisterComponent } from './register/register.component'; 5 | import { PageNotFoundComponent } from './page-not-found/page-not-found.component'; 6 | 7 | 8 | const routes: Routes = [ 9 | { 10 | path: 'login', 11 | component: LoginComponent 12 | }, 13 | { 14 | path: '', 15 | redirectTo: '/login', 16 | pathMatch: 'full' 17 | }, 18 | { 19 | path: 'register', 20 | component: RegisterComponent 21 | }, 22 | { 23 | path: 'admin', 24 | loadChildren: () => import('src/app/admin/admin.module').then(module => module.AdminModule) 25 | }, 26 | { 27 | path: '**', 28 | component: PageNotFoundComponent 29 | } 30 | ]; 31 | 32 | @NgModule({ 33 | imports: [RouterModule.forRoot(routes)], 34 | exports: [RouterModule] 35 | }) 36 | export class AppRoutingModule { } 37 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliyas5044/angular-laravel/73dde72d0420069325275a6e5b6d196e78549572/src/app/app.component.scss -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'angular-laravel'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('angular-laravel'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('angular-laravel app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.scss'] 7 | }) 8 | export class AppComponent { 9 | title = 'angular-laravel'; 10 | } 11 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { HttpClientModule } from '@angular/common/http'; 4 | import { ReactiveFormsModule } from '@angular/forms'; 5 | 6 | import { AppRoutingModule } from './app-routing.module'; 7 | import { AppComponent } from './app.component'; 8 | import { LoginComponent } from './login/login.component'; 9 | import { RegisterComponent } from './register/register.component'; 10 | import { PageNotFoundComponent } from './page-not-found/page-not-found.component'; 11 | 12 | @NgModule({ 13 | declarations: [ 14 | AppComponent, 15 | LoginComponent, 16 | RegisterComponent, 17 | PageNotFoundComponent 18 | ], 19 | imports: [ 20 | BrowserModule, 21 | HttpClientModule, 22 | ReactiveFormsModule, 23 | AppRoutingModule 24 | ], 25 | providers: [], 26 | bootstrap: [AppComponent] 27 | }) 28 | export class AppModule { } 29 | -------------------------------------------------------------------------------- /src/app/auth.guard.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { AuthGuard } from './auth.guard'; 4 | 5 | describe('AuthGuard', () => { 6 | let guard: AuthGuard; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | guard = TestBed.inject(AuthGuard); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(guard).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/app/auth.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router'; 3 | import { Observable } from 'rxjs'; 4 | import { AuthService } from './auth.service'; 5 | 6 | @Injectable({ 7 | providedIn: 'root' 8 | }) 9 | export class AuthGuard implements CanActivate { 10 | private isLoggedIn = false; 11 | 12 | constructor( 13 | private authService: AuthService, 14 | private router: Router) { 15 | this.authService.isUserLoggedIn.subscribe(res => this.isLoggedIn = res); 16 | } 17 | 18 | canActivate( 19 | next: ActivatedRouteSnapshot, 20 | state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { 21 | 22 | return this.checkLogin(state.url); 23 | } 24 | 25 | checkLogin(url: string): boolean { 26 | if (this.isLoggedIn) { 27 | return true; 28 | } 29 | 30 | // Store the attempted URL for redirecting 31 | this.authService.redirectUrl = url; 32 | 33 | // Navigate to the login page with extras 34 | this.router.navigate(['/login']); 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/app/auth.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { AuthService } from './auth.service'; 4 | 5 | describe('AuthService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [AuthService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([AuthService], (service: AuthService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 3 | import { BehaviorSubject, Observable } from 'rxjs'; 4 | import { environment } from '../environments/environment'; 5 | import { User } from './user'; 6 | import { deleteCookie, getCookie } from './cookie'; 7 | 8 | @Injectable({ 9 | providedIn: 'root', 10 | }) 11 | export class AuthService { 12 | isUserLoggedIn: BehaviorSubject = new BehaviorSubject(false); 13 | token: BehaviorSubject = new BehaviorSubject(null); 14 | userObject: BehaviorSubject = new BehaviorSubject(new User()); 15 | // store the URL so we can redirect after logging in 16 | redirectUrl = 'admin'; 17 | 18 | constructor(private http: HttpClient) { 19 | const token = getCookie('token'); 20 | const user = JSON.parse(getCookie('user')); 21 | if (token != null) { 22 | this.isUserLoggedIn.next(true); 23 | this.token.next(token); 24 | this.userObject.next(user); 25 | } 26 | } 27 | 28 | login(data: any): Observable { 29 | const url = `${environment.API_URL}/login`; 30 | return this.http.post(url, data); 31 | } 32 | 33 | register(data: any): Observable { 34 | const url = `${environment.API_URL}/register`; 35 | return this.http.post(url, data); 36 | } 37 | 38 | logout(token: string): Observable { 39 | const url = `${environment.API_URL}/logout`; 40 | return this.http.get(url, { 41 | headers: new HttpHeaders().set('Authorization', 'Bearer ' + token), 42 | }); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/app/book/book.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

5 | Books 6 |

7 |
8 |

{{ error }}

9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |

{{book.description}}

17 |
{{book.author}}
18 |
19 |
20 |
21 |
22 |
23 | -------------------------------------------------------------------------------- /src/app/book/book.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliyas5044/angular-laravel/73dde72d0420069325275a6e5b6d196e78549572/src/app/book/book.component.scss -------------------------------------------------------------------------------- /src/app/book/book.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { BookComponent } from './book.component'; 4 | 5 | describe('BookComponent', () => { 6 | let component: BookComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ BookComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(BookComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/book/book.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { HttpErrorResponse } from '@angular/common/http'; 3 | import { BookService } from './book.service'; 4 | import { Book } from './book'; 5 | 6 | @Component({ 7 | selector: 'app-book', 8 | templateUrl: './book.component.html', 9 | styleUrls: ['./book.component.scss'] 10 | }) 11 | export class BookComponent implements OnInit { 12 | books: Book[] = []; 13 | dataInvalid = false; 14 | formErrors = []; 15 | formSubmitting = false; 16 | 17 | constructor(private bookService: BookService) { 18 | } 19 | 20 | ngOnInit() { 21 | this.bookService.getBooks() 22 | .subscribe(data => { 23 | this.books = data['data']; 24 | }, (err: HttpErrorResponse) => { 25 | this.dataInvalid = true; 26 | this.formSubmitting = false; 27 | if (err.error instanceof Error) { 28 | // A client-side or network error occurred. Handle it accordingly. 29 | this.formErrors.push(err.error.message); 30 | } else { 31 | // The backend returned an unsuccessful response code. 32 | // The response body may contain clues as to what went wrong, 33 | if (err.status === 0) { 34 | this.formErrors.push('please check your backend server.'); 35 | } else { 36 | const errors = JSON.parse(err.error); 37 | const items = []; 38 | for (const key in errors) { 39 | if (errors.hasOwnProperty(key)) { 40 | items.push(errors[key]); 41 | } 42 | } 43 | for (const k in items[1]) { 44 | if (items[1].hasOwnProperty(k)) { 45 | this.formErrors.push(items[1][k][0]); 46 | } 47 | } 48 | } 49 | } 50 | }); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/app/book/book.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { BookComponent } from './book.component'; 4 | import { BookService } from './book.service'; 5 | 6 | @NgModule({ 7 | imports: [ 8 | CommonModule 9 | ], 10 | declarations: [BookComponent], 11 | providers: [BookService] 12 | }) 13 | export class BookModule { 14 | } 15 | -------------------------------------------------------------------------------- /src/app/book/book.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { BookService } from './book.service'; 4 | 5 | describe('BookService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [BookService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([BookService], (service: BookService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /src/app/book/book.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 3 | import { Observable } from 'rxjs'; 4 | import { AuthService } from '../auth.service'; 5 | import { environment } from '../../environments/environment'; 6 | import { Book } from './book'; 7 | 8 | @Injectable() 9 | export class BookService { 10 | private token: string; 11 | 12 | constructor(private http: HttpClient, 13 | private authService: AuthService) { 14 | this.authService.token.subscribe(res => this.token = res); 15 | } 16 | 17 | getBooks(): Observable { 18 | const url = `${environment.API_URL}/book`; 19 | return this.http.get(url, { 20 | headers: new HttpHeaders({Authorization: 'Bearer ' + this.token}) 21 | }); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/app/book/book.ts: -------------------------------------------------------------------------------- 1 | export class Book { 2 | id: 0; 3 | author: ''; 4 | description: ''; 5 | } 6 | -------------------------------------------------------------------------------- /src/app/cookie.ts: -------------------------------------------------------------------------------- 1 | // set cookie 2 | export const setCookie = (name, value, minutes) => { 3 | let expires = ''; 4 | if (minutes) { 5 | const date = new Date(); 6 | date.setTime(date.getTime() + (minutes * 60 * 1000)); 7 | expires = '; expires=' + date.toUTCString(); 8 | } 9 | document.cookie = name + '=' + (value || '') + expires + '; path=/'; 10 | }; 11 | // get cookie 12 | export const getCookie = (name) => { 13 | const nameEQ = name + '='; 14 | const ca = document.cookie.split(';'); 15 | for (let i = 0; i < ca.length; i++) { 16 | let c = ca[i]; 17 | while (c.charAt(0) === ' ') { 18 | c = c.substring(1, c.length); 19 | } 20 | if (c.indexOf(nameEQ) === 0) { 21 | return c.substring(nameEQ.length, c.length); 22 | } 23 | } 24 | return null; 25 | }; 26 | // delete cookie 27 | export const deleteCookie = (name) => { 28 | document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; 29 | }; 30 | -------------------------------------------------------------------------------- /src/app/login/login.component.html: -------------------------------------------------------------------------------- 1 |
2 | 39 |

Don't have account? please register here

40 |
41 | -------------------------------------------------------------------------------- /src/app/login/login.component.scss: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 40px; 3 | padding-bottom: 40px; 4 | background-color: #eee; 5 | } 6 | 7 | .form-signin { 8 | max-width: 330px; 9 | padding: 15px; 10 | margin: 0 auto; 11 | } 12 | .form-signin .form-signin-heading, 13 | .form-signin .checkbox { 14 | margin-bottom: 10px; 15 | } 16 | .form-signin .checkbox { 17 | font-weight: normal; 18 | } 19 | .form-signin .form-control { 20 | position: relative; 21 | height: auto; 22 | -webkit-box-sizing: border-box; 23 | box-sizing: border-box; 24 | padding: 10px; 25 | font-size: 16px; 26 | } 27 | .form-signin .form-control:focus { 28 | z-index: 2; 29 | } 30 | .form-signin input[type="email"] { 31 | margin-bottom: -1px; 32 | border-bottom-right-radius: 0; 33 | border-bottom-left-radius: 0; 34 | } 35 | .form-signin input[type="password"] { 36 | margin-bottom: 10px; 37 | border-top-left-radius: 0; 38 | border-top-right-radius: 0; 39 | } -------------------------------------------------------------------------------- /src/app/login/login.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LoginComponent } from './login.component'; 4 | 5 | describe('LoginComponent', () => { 6 | let component: LoginComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LoginComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LoginComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/login/login.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | import { FormBuilder, FormGroup, Validators } from '@angular/forms'; 4 | import { HttpErrorResponse } from '@angular/common/http'; 5 | import { AuthService } from '../auth.service'; 6 | import { User } from '../user'; 7 | import { setCookie } from '../cookie'; 8 | 9 | const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/; 10 | 11 | @Component({ 12 | selector: 'app-login', 13 | templateUrl: './login.component.html', 14 | styleUrls: ['./login.component.scss'] 15 | }) 16 | export class LoginComponent implements OnInit { 17 | isLoggedIn = false; 18 | loginForm: FormGroup; 19 | user: User; 20 | dataInvalid = false; 21 | formErrors = []; 22 | formSubmitting = false; 23 | 24 | constructor(public authService: AuthService, 25 | public router: Router, 26 | private fb: FormBuilder) { 27 | } 28 | 29 | 30 | ngOnInit() { 31 | this.loginForm = this.fb.group({ 32 | email: ['', [Validators.required, Validators.pattern(EMAIL_REGEX)]], 33 | password: ['', Validators.required] 34 | }); 35 | this.authService.isUserLoggedIn.subscribe(res => this.isLoggedIn = res); 36 | if (this.isLoggedIn) { 37 | // Get the redirect URL from our auth service 38 | // If no redirect has been set, use the default 39 | const redirect = this.authService.redirectUrl ? this.authService.redirectUrl : 'admin'; 40 | // Redirect the user 41 | this.router.navigate([redirect]); 42 | } 43 | } 44 | 45 | get email() { 46 | return this.loginForm.get('email'); 47 | } 48 | 49 | get password() { 50 | return this.loginForm.get('password'); 51 | } 52 | 53 | login() { 54 | this.formErrors = []; 55 | this.formSubmitting = true; 56 | this.authService.login(this.loginForm.value).subscribe((res) => { 57 | this.formSubmitting = false; 58 | // set token and user cookie 59 | setCookie('token', res.token, res.expires); 60 | setCookie('user', JSON.stringify(res.user), res.expires); 61 | // set token and user 62 | this.authService.token.next(res.token); 63 | this.authService.userObject.next(res.user); 64 | this.authService.isUserLoggedIn.next(true); 65 | // Get the redirect URL from our auth service 66 | // If no redirect has been set, use the default 67 | const redirect = this.authService.redirectUrl ? this.authService.redirectUrl : 'admin'; 68 | // Redirect the user 69 | this.router.navigate([redirect]); 70 | }, (err: HttpErrorResponse) => { 71 | this.dataInvalid = true; 72 | this.formSubmitting = false; 73 | if (err.error instanceof Error) { 74 | // A client-side or network error occurred. Handle it accordingly. 75 | this.formErrors.push(err.error.message); 76 | } else { 77 | // The backend returned an unsuccessful response code. 78 | // The response body may contain clues as to what went wrong, 79 | if (err.status === 0) { 80 | this.formErrors.push('please check your backend server.'); 81 | } else { 82 | const errors = JSON.parse(err.error); 83 | const items = []; 84 | for (const key in errors) { 85 | if (errors.hasOwnProperty(key)) { 86 | items.push(errors[key]); 87 | } 88 | } 89 | for (const k in items[1]) { 90 | if (items[1].hasOwnProperty(k)) { 91 | this.formErrors.push(items[1][k][0]); 92 | } 93 | } 94 | } 95 | } 96 | }); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/app/page-not-found/page-not-found.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Whoops! Page not found.

3 |
4 |

5 | Home 6 |

7 |
8 | -------------------------------------------------------------------------------- /src/app/page-not-found/page-not-found.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliyas5044/angular-laravel/73dde72d0420069325275a6e5b6d196e78549572/src/app/page-not-found/page-not-found.component.scss -------------------------------------------------------------------------------- /src/app/page-not-found/page-not-found.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PageNotFoundComponent } from './page-not-found.component'; 4 | 5 | describe('PageNotFoundComponent', () => { 6 | let component: PageNotFoundComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PageNotFoundComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PageNotFoundComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/page-not-found/page-not-found.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-page-not-found', 5 | templateUrl: './page-not-found.component.html', 6 | styleUrls: ['./page-not-found.component.scss'] 7 | }) 8 | export class PageNotFoundComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/register/register.component.html: -------------------------------------------------------------------------------- 1 |
2 | 45 |

Already have account? please login here

46 | 47 |
48 | -------------------------------------------------------------------------------- /src/app/register/register.component.scss: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 40px; 3 | padding-bottom: 40px; 4 | background-color: #eee; 5 | } 6 | 7 | .form-signin { 8 | max-width: 330px; 9 | padding: 15px; 10 | margin: 0 auto; 11 | } 12 | .form-signin .form-signin-heading, 13 | .form-signin .checkbox { 14 | margin-bottom: 10px; 15 | } 16 | .form-signin .checkbox { 17 | font-weight: normal; 18 | } 19 | .form-signin .form-control { 20 | position: relative; 21 | height: auto; 22 | -webkit-box-sizing: border-box; 23 | box-sizing: border-box; 24 | padding: 10px; 25 | font-size: 16px; 26 | } 27 | .form-signin .form-control:focus { 28 | z-index: 2; 29 | } 30 | -------------------------------------------------------------------------------- /src/app/register/register.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { RegisterComponent } from './register.component'; 4 | 5 | describe('RegisterComponent', () => { 6 | let component: RegisterComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ RegisterComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(RegisterComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/register/register.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormBuilder, FormGroup, Validators } from '@angular/forms'; 3 | import { Router } from '@angular/router'; 4 | import { HttpErrorResponse } from '@angular/common/http'; 5 | import { AuthService } from '../auth.service'; 6 | import { User } from '../user'; 7 | import { setCookie } from '../cookie'; 8 | 9 | const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/; 10 | 11 | @Component({ 12 | selector: 'app-register', 13 | templateUrl: './register.component.html', 14 | styleUrls: ['./register.component.scss'] 15 | }) 16 | export class RegisterComponent implements OnInit { 17 | 18 | registerForm: FormGroup; 19 | user: User; 20 | dataInvalid = false; 21 | formErrors = []; 22 | formSubmitting = false; 23 | 24 | constructor(public authService: AuthService, 25 | public router: Router, 26 | private fb: FormBuilder) { 27 | } 28 | 29 | 30 | ngOnInit() { 31 | this.registerForm = this.fb.group({ 32 | name: ['', Validators.required], 33 | email: ['', [Validators.required, Validators.pattern(EMAIL_REGEX)]], 34 | password: ['', [Validators.required, Validators.minLength(6)]] 35 | }); 36 | } 37 | 38 | get name() { 39 | return this.registerForm.get('name'); 40 | } 41 | 42 | get email() { 43 | return this.registerForm.get('email'); 44 | } 45 | 46 | get password() { 47 | return this.registerForm.get('password'); 48 | } 49 | 50 | register() { 51 | this.formErrors = []; 52 | this.formSubmitting = true; 53 | this.authService.register(this.registerForm.value).subscribe((res) => { 54 | this.formSubmitting = false; 55 | // set token and user cookie 56 | setCookie('token', res.token, res.expires); 57 | setCookie('user', JSON.stringify(res.user), res.expires); 58 | // set token and user 59 | this.authService.token.next(res.token); 60 | this.authService.userObject.next(res.user); 61 | this.authService.isUserLoggedIn.next(true); 62 | // Get the redirect URL from our auth service 63 | // If no redirect has been set, use the default 64 | const redirect = this.authService.redirectUrl ? this.authService.redirectUrl : 'admin'; 65 | // Redirect the user 66 | this.router.navigate([redirect]); 67 | }, (err: HttpErrorResponse) => { 68 | this.dataInvalid = true; 69 | this.formSubmitting = false; 70 | if (err.error instanceof Error) { 71 | // A client-side or network error occurred. Handle it accordingly. 72 | this.formErrors.push(err.error.message); 73 | } else { 74 | // The backend returned an unsuccessful response code. 75 | // The response body may contain clues as to what went wrong, 76 | if (err.status === 0) { 77 | this.formErrors.push('please check your backend server.'); 78 | } else { 79 | const errors = JSON.parse(err.error); 80 | const items = []; 81 | for (const key in errors) { 82 | if (errors.hasOwnProperty(key)) { 83 | items.push(errors[key]); 84 | } 85 | } 86 | for (const k in items[1]) { 87 | if (items[1].hasOwnProperty(k)) { 88 | this.formErrors.push(items[1][k][0]); 89 | } 90 | } 91 | } 92 | } 93 | }); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/app/user.ts: -------------------------------------------------------------------------------- 1 | export class User { 2 | id: number; 3 | name: string; 4 | email: string; 5 | } 6 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliyas5044/angular-laravel/73dde72d0420069325275a6e5b6d196e78549572/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | API_URL: 'http://localhost:8000/api' 4 | }; 5 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false, 7 | API_URL: 'http://localhost:8000/api' 8 | }; 9 | 10 | /* 11 | * For easier debugging in development mode, you can import the following file 12 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 13 | * 14 | * This import should be commented out in production mode because it will have a negative impact 15 | * on performance if an error is thrown. 16 | */ 17 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 18 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliyas5044/angular-laravel/73dde72d0420069325275a6e5b6d196e78549572/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularLaravel 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | body { 3 | min-height: 75rem; 4 | padding-top: 4.5rem; 5 | } -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | }, 22 | "angularCompilerOptions": { 23 | "fullTemplateTypeCheck": true, 24 | "strictInjectionParameters": true 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warning" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [ 13 | true, 14 | "attribute", 15 | "app", 16 | "camelCase" 17 | ], 18 | "component-selector": [ 19 | true, 20 | "element", 21 | "app", 22 | "kebab-case" 23 | ], 24 | "import-blacklist": [ 25 | true, 26 | "rxjs/Rx" 27 | ], 28 | "interface-name": false, 29 | "max-classes-per-file": false, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-consecutive-blank-lines": false, 47 | "no-console": [ 48 | true, 49 | "debug", 50 | "info", 51 | "time", 52 | "timeEnd", 53 | "trace" 54 | ], 55 | "no-empty": false, 56 | "no-inferrable-types": [ 57 | true, 58 | "ignore-params" 59 | ], 60 | "no-non-null-assertion": true, 61 | "no-redundant-jsdoc": true, 62 | "no-switch-case-fall-through": true, 63 | "no-var-requires": false, 64 | "object-literal-key-quotes": [ 65 | true, 66 | "as-needed" 67 | ], 68 | "object-literal-sort-keys": false, 69 | "ordered-imports": false, 70 | "quotemark": [ 71 | true, 72 | "single" 73 | ], 74 | "trailing-comma": false, 75 | "no-conflicting-lifecycle": true, 76 | "no-host-metadata-property": true, 77 | "no-input-rename": true, 78 | "no-inputs-metadata-property": true, 79 | "no-output-native": true, 80 | "no-output-on-prefix": true, 81 | "no-output-rename": true, 82 | "no-outputs-metadata-property": true, 83 | "template-banana-in-box": true, 84 | "template-no-negated-async": true, 85 | "use-lifecycle-interface": true, 86 | "use-pipe-transform-interface": true 87 | }, 88 | "rulesDirectory": [ 89 | "codelyzer" 90 | ] 91 | } --------------------------------------------------------------------------------