├── src
├── assets
│ ├── .gitkeep
│ └── pictures
│ │ ├── google.icon
│ │ ├── header.png
│ │ └── cosmic_js_logo.jpg
├── app
│ ├── app.component.css
│ ├── app.component.html
│ ├── components
│ │ ├── footer
│ │ │ ├── footer.component.css
│ │ │ ├── footer.component.html
│ │ │ ├── footer.component.ts
│ │ │ └── footer.component.spec.ts
│ │ ├── header
│ │ │ ├── header.component.html
│ │ │ ├── header.component.ts
│ │ │ ├── header.component.css
│ │ │ └── header.component.spec.ts
│ │ ├── register
│ │ │ ├── register.component.css
│ │ │ ├── register.component.spec.ts
│ │ │ ├── register.component.ts
│ │ │ └── register.component.html
│ │ ├── dashboard
│ │ │ ├── dashboard.component.css
│ │ │ ├── dashboard.component.spec.ts
│ │ │ ├── dashboard.component.html
│ │ │ └── dashboard.component.ts
│ │ └── authentication
│ │ │ ├── authentication.component.css
│ │ │ ├── authentication.component.spec.ts
│ │ │ ├── authentication.component.html
│ │ │ └── authentication.component.ts
│ ├── models
│ │ └── user.model.ts
│ ├── app.component.ts
│ ├── app-routing.module.spec.ts
│ ├── services
│ │ ├── apicall.service.spec.ts
│ │ └── apicall.service.ts
│ ├── app-routing.module.ts
│ ├── app.component.spec.ts
│ └── app.module.ts
├── favicon.ico
├── styles.css
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── config
│ ├── cosmic.prod.ts
│ └── cosmic.config.ts
├── tsconfig.app.json
├── tsconfig.spec.json
├── tslint.json
├── browserslist
├── main.ts
├── index.html
├── test.ts
├── karma.conf.js
└── polyfills.ts
├── app.js
├── e2e
├── src
│ ├── app.po.ts
│ └── app.e2e-spec.ts
├── tsconfig.e2e.json
└── protractor.conf.js
├── .editorconfig
├── tsconfig.json
├── .gitignore
├── prepare.js
├── bucket.json
├── package.json
├── README.md
├── tslint.json
└── angular.json
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/app.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosmicjs/angular-auth/master/src/favicon.ico
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/app/components/footer/footer.component.css:
--------------------------------------------------------------------------------
1 | .center
2 | {
3 | margin-top: 4em;
4 | text-align: center
5 | }
--------------------------------------------------------------------------------
/src/assets/pictures/google.icon:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosmicjs/angular-auth/master/src/assets/pictures/google.icon
--------------------------------------------------------------------------------
/src/assets/pictures/header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosmicjs/angular-auth/master/src/assets/pictures/header.png
--------------------------------------------------------------------------------
/src/assets/pictures/cosmic_js_logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosmicjs/angular-auth/master/src/assets/pictures/cosmic_js_logo.jpg
--------------------------------------------------------------------------------
/src/app/components/header/header.component.html:
--------------------------------------------------------------------------------
1 |
2 |
Angular Auth Powered by Cosmic JS
3 |
--------------------------------------------------------------------------------
/src/app/components/footer/footer.component.html:
--------------------------------------------------------------------------------
1 |
2 | Proudly Powered by Cosmic JS
3 |
4 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | const express = require('express')
2 | const app = express()
3 |
4 | app.use(express.static('./dist/ngAuth'));
5 |
6 | app.listen(process.env.PORT || 5000, function () {
7 | });
8 |
--------------------------------------------------------------------------------
/src/config/cosmic.prod.ts:
--------------------------------------------------------------------------------
1 |
2 | export const config = {
3 | production: true,
4 | read_key: '',
5 | write_key: '',
6 | bucket_slug: 'auth-test',
7 | URL: 'https://api.cosmicjs.com/v1/',
8 | };
9 |
--------------------------------------------------------------------------------
/src/config/cosmic.config.ts:
--------------------------------------------------------------------------------
1 |
2 | export const config = {
3 | production: false,
4 | read_key: '',
5 | write_key: '',
6 | bucket_slug: 'auth-test',
7 | URL: 'https://api.cosmicjs.com/v1/',
8 | };
9 |
--------------------------------------------------------------------------------
/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "types": []
6 | },
7 | "exclude": [
8 | "src/test.ts",
9 | "**/*.spec.ts"
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/src/app/models/user.model.ts:
--------------------------------------------------------------------------------
1 | export class userModel {
2 |
3 | _id: string;
4 | fullName: string;
5 | email: string;
6 | password: string;
7 | confirmPassword: string;
8 | gender: string;
9 | mobile: string;
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo() {
5 | return browser.get('/');
6 | }
7 |
8 | getParagraphText() {
9 | return element(by.css('app-root h1')).getText();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/e2e/tsconfig.e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | }
13 | }
--------------------------------------------------------------------------------
/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.css']
7 | })
8 | export class AppComponent {
9 | title = 'Angular Auth Powered by Cosmic JS';
10 | }
11 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://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 |
--------------------------------------------------------------------------------
/src/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 | "test.ts",
12 | "polyfills.ts"
13 | ],
14 | "include": [
15 | "**/*.spec.ts",
16 | "**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/src/app/components/footer/footer.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-footer',
5 | templateUrl: './footer.component.html',
6 | styleUrls: ['./footer.component.css']
7 | })
8 | export class FooterComponent implements OnInit {
9 |
10 | constructor() { }
11 |
12 | ngOnInit() {
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/app/components/header/header.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-header',
5 | templateUrl: './header.component.html',
6 | styleUrls: ['./header.component.css']
7 | })
8 | export class HeaderComponent implements OnInit {
9 |
10 | constructor() { }
11 |
12 | ngOnInit() {
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 |
3 | describe('workspace-project App', () => {
4 | let page: AppPage;
5 |
6 | beforeEach(() => {
7 | page = new AppPage();
8 | });
9 |
10 | it('should display welcome message', () => {
11 | page.navigateTo();
12 | expect(page.getParagraphText()).toEqual('Welcome to ngAuth!');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/src/app/app-routing.module.spec.ts:
--------------------------------------------------------------------------------
1 | import { AppRoutingModule } from './app-routing.module';
2 |
3 | describe('AppRoutingModule', () => {
4 | let appRoutingModule: AppRoutingModule;
5 |
6 | beforeEach(() => {
7 | appRoutingModule = new AppRoutingModule();
8 | });
9 |
10 | it('should create an instance', () => {
11 | expect(appRoutingModule).toBeTruthy();
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/src/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tslint.json",
3 | "rules": {
4 | "directive-selector": [
5 | true,
6 | "attribute",
7 | "app",
8 | "camelCase"
9 | ],
10 | "component-selector": [
11 | true,
12 | "element",
13 | "app",
14 | "kebab-case"
15 | ]
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/browserslist:
--------------------------------------------------------------------------------
1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 | # For IE 9-11 support, please uncomment the last line of the file and adjust as needed
5 | > 0.5%
6 | last 2 versions
7 | Firefox ESR
8 | not dead
9 | # IE 9-11
--------------------------------------------------------------------------------
/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.log(err));
13 |
--------------------------------------------------------------------------------
/src/app/components/header/header.component.css:
--------------------------------------------------------------------------------
1 | .jumbotron {
2 | background: url(/assets/pictures/header.png) no-repeat center top;
3 | background-size:cover;
4 | border-radius: 0;
5 | margin-bottom:0;
6 | background-color: rgb(121, 212, 235)
7 | }
8 | .jumbotron h1 {
9 | font-size: 3.5rem;
10 | font-weight: 300;
11 | line-height: 1.2;
12 | color: #fff;
13 | font-weight: bold;
14 | }
15 | .center{text-align: center}
--------------------------------------------------------------------------------
/src/app/services/apicall.service.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, inject } from '@angular/core/testing';
2 |
3 | import { ApicallService } from './apicall.service';
4 |
5 | describe('ApicallService', () => {
6 | beforeEach(() => {
7 | TestBed.configureTestingModule({
8 | providers: [ApicallService]
9 | });
10 | });
11 |
12 | it('should be created', inject([ApicallService], (service: ApicallService) => {
13 | expect(service).toBeTruthy();
14 | }));
15 | });
16 |
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Angular Auth App with Cosmic JS
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "baseUrl": "./",
5 | "outDir": "./dist/out-tsc",
6 | "sourceMap": true,
7 | "declaration": false,
8 | "module": "es2015",
9 | "moduleResolution": "node",
10 | "emitDecoratorMetadata": true,
11 | "experimentalDecorators": true,
12 | "target": "es5",
13 | "typeRoots": [
14 | "node_modules/@types"
15 | ],
16 | "lib": [
17 | "es2017",
18 | "dom"
19 | ]
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/app/components/register/register.component.css:
--------------------------------------------------------------------------------
1 | .margin-tp
2 | {
3 | margin-top: 2em;
4 | margin-bottom: 2em
5 | }
6 | /* color of register button text */
7 | a:not([href]):not([tabindex]) {
8 | color: white;
9 | text-decoration: none;
10 | }
11 |
12 | /* *, ::after, ::before {
13 | } */
14 |
15 | .help-block
16 | {
17 | color: red
18 | }
19 | .btn-back
20 | {
21 | background-color:rgb(31, 121, 31) ;
22 |
23 | }
24 |
25 | /* card background */
26 | .card-back
27 | {
28 | background-color: rgb(31, 121, 31);
29 | color: white;
30 | }
--------------------------------------------------------------------------------
/src/app/components/dashboard/dashboard.component.css:
--------------------------------------------------------------------------------
1 | .margin-tp
2 | {
3 | margin-top: 2em
4 | }
5 |
6 | .float-right
7 | {
8 | float:right;
9 | }
10 |
11 | .table td, .table th {
12 | border: none;
13 | }
14 |
15 | table.table.table-condensed {
16 | border: 1px solid black;
17 | }
18 |
19 | .table-schceme
20 | {
21 | background:rgb(31, 121, 31); color: white
22 | }
23 | .btn-back
24 | {
25 | background-color:rgb(31, 121, 31) ;
26 |
27 | }
28 |
29 | .img-responsive {
30 | margin: 0 auto;
31 | }
32 |
33 | img {
34 | vertical-align: unset;
35 | border-style: none;
36 | }
37 | .image-size
38 | {
39 | height: 96px;
40 | width: 96px;
41 | }
--------------------------------------------------------------------------------
/.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 |
8 | # dependencies
9 | /node_modules
10 |
11 | # IDEs and editors
12 | /.idea
13 | .project
14 | .classpath
15 | .c9/
16 | *.launch
17 | .settings/
18 | *.sublime-workspace
19 |
20 | # IDE - VSCode
21 | .vscode/*
22 | !.vscode/settings.json
23 | !.vscode/tasks.json
24 | !.vscode/launch.json
25 | !.vscode/extensions.json
26 |
27 | # misc
28 | /.sass-cache
29 | /connect.lock
30 | /coverage
31 | /libpeerconnection.log
32 | npm-debug.log
33 | yarn-error.log
34 | testem.log
35 | /typings
36 |
37 | # System Files
38 | .DS_Store
39 | Thumbs.db
40 |
--------------------------------------------------------------------------------
/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 | };
8 |
9 | /*
10 | * In development mode, to ignore zone related error stack frames such as
11 | * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can
12 | * import the following file, but please comment it out in production mode
13 | * because it will have performance impact when throw error
14 | */
15 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
16 |
--------------------------------------------------------------------------------
/src/app/components/authentication/authentication.component.css:
--------------------------------------------------------------------------------
1 | .margin-tp
2 | {
3 | margin-top: 2em;
4 | margin-bottom: 2em
5 | }
6 | /* color of register button text */
7 | a:not([href]):not([tabindex]) {
8 | color: white;
9 | text-decoration: none;
10 | }
11 |
12 | /* *, ::after, ::before {
13 | } */
14 |
15 | .help-block
16 | {
17 | color: red
18 | }
19 | .btn-back
20 | {
21 | background-color:rgb(31, 121, 31) ;
22 |
23 | }
24 |
25 | /* card background */
26 | .card-back
27 | {
28 | background-color: rgb(31, 121, 31);
29 | color: white;
30 | }
31 |
32 | .btn-google
33 | {
34 | background-color: rgb(41, 38, 207);
35 |
36 | }
37 |
38 | .google-button
39 | {
40 | cursor: pointer;
41 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/src/app/components/footer/footer.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { FooterComponent } from './footer.component';
4 |
5 | describe('FooterComponent', () => {
6 | let component: FooterComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ FooterComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(FooterComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/src/app/components/header/header.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { HeaderComponent } from './header.component';
4 |
5 | describe('HeaderComponent', () => {
6 | let component: HeaderComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ HeaderComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(HeaderComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/src/app/components/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/components/dashboard/dashboard.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { DashboardComponent } from './dashboard.component';
4 |
5 | describe('DashboardComponent', () => {
6 | let component: DashboardComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ DashboardComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(DashboardComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/src/app/components/dashboard/dashboard.component.html:
--------------------------------------------------------------------------------
1 |
2 |

3 | {{name}}
4 |
5 |
6 |
7 |
Welcome {{name}}
8 |
9 |
10 |
11 | | Name | {{name}} |
12 |
13 |
14 | | Email | {{email}} |
15 |
16 |
17 | | Mobile | {{mobile}} |
18 |
19 |
20 | | Gender | {{gender}} |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/app/components/authentication/authentication.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { AuthenticationComponent } from './authentication.component';
4 |
5 | describe('AuthenticationComponent', () => {
6 | let component: AuthenticationComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ AuthenticationComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(AuthenticationComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/e2e/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './src/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: require('path').join(__dirname, './tsconfig.e2e.json')
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
--------------------------------------------------------------------------------
/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 | import { RouterModule, Routes } from '@angular/router';
4 | import { AuthenticationComponent } from './components/authentication/authentication.component';
5 | import { DashboardComponent } from './components/dashboard/dashboard.component';
6 | import { RegisterComponent } from './components/register/register.component';
7 |
8 |
9 |
10 | const routes: Routes = [
11 | { path: '', component: AuthenticationComponent },
12 | { path: 'dashboard', component: DashboardComponent },
13 | { path: 'register', component: RegisterComponent }
14 | ];
15 |
16 | @NgModule({
17 | imports: [
18 | CommonModule,
19 | RouterModule.forRoot(routes),
20 | ],
21 | exports: [ RouterModule ],
22 | declarations: []
23 | })
24 | export class AppRoutingModule { }
25 |
--------------------------------------------------------------------------------
/src/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'),
20 | reports: ['html', 'lcovonly'],
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 | });
31 | };
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { AppComponent } from './app.component';
3 | describe('AppComponent', () => {
4 | beforeEach(async(() => {
5 | TestBed.configureTestingModule({
6 | declarations: [
7 | AppComponent
8 | ],
9 | }).compileComponents();
10 | }));
11 | it('should create the app', async(() => {
12 | const fixture = TestBed.createComponent(AppComponent);
13 | const app = fixture.debugElement.componentInstance;
14 | expect(app).toBeTruthy();
15 | }));
16 | it(`should have as title 'ngAuth'`, async(() => {
17 | const fixture = TestBed.createComponent(AppComponent);
18 | const app = fixture.debugElement.componentInstance;
19 | expect(app.title).toEqual('ngAuth');
20 | }));
21 | it('should render title in a h1 tag', async(() => {
22 | const fixture = TestBed.createComponent(AppComponent);
23 | fixture.detectChanges();
24 | const compiled = fixture.debugElement.nativeElement;
25 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to ngAuth!');
26 | }));
27 | });
28 |
--------------------------------------------------------------------------------
/prepare.js:
--------------------------------------------------------------------------------
1 | var fs = require('fs');
2 |
3 | var prod_str = `
4 | export const config = {
5 | production: true,
6 | read_key: '${process.env.COSMIC_READ_KEY ? process.env.COSMIC_READ_KEY : ''}',
7 | write_key: '${process.env.COSMIC_WRITE_KEY ? process.env.COSMIC_WRITE_KEY : ''}',
8 | bucket_slug: '${process.env.COSMIC_BUCKET}',
9 | URL: 'https://api.cosmicjs.com/v1/',
10 | };
11 | `;
12 | fs.writeFile("./src/config/cosmic.prod.ts", prod_str, function(err) {
13 | if(err) {
14 | return console.log(err);
15 | }
16 | console.log("The production config was saved!");
17 | });
18 | var dev_str = `
19 | export const config = {
20 | production: false,
21 | read_key: '${process.env.COSMIC_READ_KEY ? process.env.COSMIC_READ_KEY : ''}',
22 | write_key: '${process.env.COSMIC_WRITE_KEY ? process.env.COSMIC_WRITE_KEY : ''}',
23 | bucket_slug: '${process.env.COSMIC_BUCKET}',
24 | URL: 'https://api.cosmicjs.com/v1/',
25 | };
26 | `;
27 | fs.writeFile("./src/config/cosmic.config.ts", dev_str, function(err) {
28 | if(err) {
29 | return console.log(err);
30 | }
31 | console.log("The dev config was saved!");
32 | });
--------------------------------------------------------------------------------
/bucket.json:
--------------------------------------------------------------------------------
1 | {
2 | "bucket": {
3 | "_id": "5c37a3026bcb7526c0bddd0b",
4 | "slug": "angular-auth",
5 | "title": "Angular Auth",
6 | "object_types": [
7 | {
8 | "title": "users",
9 | "slug": "users",
10 | "singular": "user",
11 | "metafields": [],
12 | "preview_link": "",
13 | "priority_locale": null
14 | },
15 | {
16 | "title": "googleusers",
17 | "slug": "googleusers",
18 | "singular": "googleuser",
19 | "metafields": [],
20 | "preview_link": "",
21 | "priority_locale": null
22 | }
23 | ],
24 | "links": [],
25 | "objects": [],
26 | "media": [
27 | {
28 | "_id": "5c37aa9d6bcb7526c0bddd2b",
29 | "name": "1af246a0-1516-11e9-aaba-93c9f494a70a-angular.svg",
30 | "original_name": "angular.svg",
31 | "size": 510,
32 | "type": "image/svg+xml",
33 | "bucket": "5c37a3026bcb7526c0bddd0b",
34 | "created": "2019-01-10T20:27:09.740Z",
35 | "location": "https://s3-us-west-2.amazonaws.com/cosmicjs",
36 | "folder": null,
37 | "url": "https://s3-us-west-2.amazonaws.com/cosmicjs/1af246a0-1516-11e9-aaba-93c9f494a70a-angular.svg",
38 | "imgix_url": "https://cosmic-s3.imgix.net/1af246a0-1516-11e9-aaba-93c9f494a70a-angular.svg"
39 | }
40 | ],
41 | "media_folders": [],
42 | "extensions": [],
43 | "thumbnail": "1af246a0-1516-11e9-aaba-93c9f494a70a-angular.svg"
44 | }
45 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ng-auth",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "node app.js",
7 | "build": "node prepare.js; ng build",
8 | "test": "ng test",
9 | "lint": "ng lint",
10 | "e2e": "ng e2e",
11 | "postinstall": "node prepare.js; ng build --aot --prod"
12 | },
13 | "keywords": [
14 | "example",
15 | "heroku"
16 | ],
17 | "engines": {
18 | "node": "8.12.0",
19 | "npm": "6.4.1"
20 | },
21 | "private": true,
22 | "dependencies": {
23 | "@angular/animations": "^6.1.0",
24 | "@angular/common": "^6.1.0",
25 | "@angular/compiler": "^6.1.0",
26 | "@angular/core": "^6.1.0",
27 | "@angular/forms": "^6.1.0",
28 | "@angular/http": "^6.1.0",
29 | "@angular/platform-browser": "^6.1.0",
30 | "@angular/platform-browser-dynamic": "^6.1.0",
31 | "@angular/router": "^6.1.0",
32 | "angular-6-social-login-v2": "^1.0.5",
33 | "babel-preset-env": "^1.7.0",
34 | "core-js": "^2.5.4",
35 | "express": "^4.16.4",
36 | "fs": "0.0.1-security",
37 | "js-base64": "^2.5.0",
38 | "ngx-bootstrap": "^3.1.3",
39 | "ngx-loading": "^3.0.1",
40 | "rxjs": "^6.0.0",
41 | "zone.js": "~0.8.26"
42 | },
43 | "devDependencies": {
44 | "@angular-devkit/build-angular": "~0.7.0",
45 | "@angular/cli": "~6.1.1",
46 | "@angular/compiler-cli": "^6.1.0",
47 | "@angular/language-service": "^6.1.0",
48 | "@types/jasmine": "~2.8.6",
49 | "@types/jasminewd2": "~2.0.3",
50 | "@types/node": "~8.9.4",
51 | "codelyzer": "~4.2.1",
52 | "jasmine-core": "~2.99.1",
53 | "jasmine-spec-reporter": "~4.2.1",
54 | "karma": "~1.7.1",
55 | "karma-chrome-launcher": "~2.2.0",
56 | "karma-coverage-istanbul-reporter": "~2.0.0",
57 | "karma-jasmine": "~1.1.1",
58 | "karma-jasmine-html-reporter": "^0.2.2",
59 | "protractor": "~5.3.0",
60 | "ts-node": "~5.0.1",
61 | "tslint": "~5.9.1",
62 | "typescript": "~2.7.2"
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { BrowserModule } from '@angular/platform-browser';
2 | import { NgModule } from '@angular/core';
3 | // import { RouterModule, Routes } from '@angular/router';
4 | import { AppComponent } from './app.component';
5 | import { AuthenticationComponent } from './components/authentication/authentication.component';
6 | import { AppRoutingModule } from './/app-routing.module';
7 | import { HttpClientModule } from '@angular/common/http';
8 | import { HttpClient} from '@angular/common/http';
9 | import { HttpModule } from '@angular/http';
10 | import { ReactiveFormsModule } from '@angular/forms';
11 | import { HeaderComponent } from './components/header/header.component';
12 | import { FooterComponent } from './components/footer/footer.component';
13 | import { DashboardComponent } from './components/dashboard/dashboard.component';
14 | import { RegisterComponent } from './components/register/register.component';
15 | import { NgxLoadingModule } from 'ngx-loading';
16 | import {
17 | SocialLoginModule,
18 | AuthServiceConfig,
19 | GoogleLoginProvider,
20 | } from "angular-6-social-login-v2";
21 |
22 | export function getAuthServiceConfigs() {
23 | let config = new AuthServiceConfig(
24 | [
25 |
26 | {
27 | id: GoogleLoginProvider.PROVIDER_ID,
28 | provider: new GoogleLoginProvider("1072643061885-sq92dlsc260pd7atlujial8svojgr905.apps.googleusercontent.com")
29 | }
30 |
31 | ]
32 | );
33 | return config;
34 | }
35 |
36 | @NgModule({
37 | declarations: [
38 | AppComponent,
39 | AuthenticationComponent,
40 | HeaderComponent,
41 | FooterComponent,
42 | DashboardComponent,
43 | RegisterComponent
44 | ],
45 | imports: [
46 | BrowserModule,
47 | AppRoutingModule,
48 | HttpClientModule,
49 | HttpModule,
50 | ReactiveFormsModule,
51 | SocialLoginModule,
52 | NgxLoadingModule.forRoot({})
53 |
54 | ],
55 | providers: [HttpClient,
56 | {
57 | provide: AuthServiceConfig,
58 | useFactory: getAuthServiceConfigs
59 | }
60 | ],
61 | bootstrap: [AppComponent]
62 | })
63 | export class AppModule { }
64 |
--------------------------------------------------------------------------------
/src/app/components/dashboard/dashboard.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { Router } from '@angular/router';
3 |
4 | @Component({
5 | selector: 'app-dashboard',
6 | templateUrl: './dashboard.component.html',
7 | styleUrls: ['./dashboard.component.css']
8 | })
9 | export class DashboardComponent implements OnInit {
10 | currentUser: any;
11 | name: any;
12 | email: any;
13 | gender: any;
14 | mobile: any;
15 | image: any;
16 |
17 | constructor(
18 | private router: Router,
19 | ) { }
20 |
21 | //get details of logged in user
22 | userDetails()
23 | {
24 | if(localStorage.getItem('currentUser'))
25 | {
26 | this.name = JSON.parse(this.currentUser).objects[0].metafields[0].value;
27 | this.email = JSON.parse(this.currentUser).objects[0].metafields[1].value;
28 | this.gender = JSON.parse(this.currentUser).objects[0].metafields[3].value;
29 | this.mobile = JSON.parse(this.currentUser).objects[0].metafields[4].value;
30 | this.image = "./../../../assets/pictures/cosmic_js_logo.jpg"
31 | }
32 | else if(localStorage.getItem('googleUser'))
33 | {
34 | console.log(JSON.parse(localStorage.getItem('googleUser')))
35 | this.name = JSON.parse(localStorage.getItem('googleUser')).objects[0].metafields[0].value;
36 | this.email = JSON.parse(localStorage.getItem('googleUser')).objects[0].metafields[1].value;
37 | this.gender = JSON.parse(localStorage.getItem('googleUser')).objects[0].metafields[3].value;
38 | this.mobile = JSON.parse(localStorage.getItem('googleUser')).objects[0].metafields[4].value;
39 | this.image = JSON.parse(localStorage.getItem('googleUser')).objects[0].metafields[5].value;
40 | }
41 |
42 | }
43 |
44 | //logging user out
45 | logout()
46 | {
47 | if(this.currentUser)
48 | {
49 | localStorage.removeItem('currentUser');
50 | this.router.navigate([''])
51 | }
52 | else if(localStorage.getItem('googleUser'))
53 | {
54 | localStorage.removeItem('googleUser');
55 | this.router.navigate([''])
56 | }
57 | }
58 |
59 |
60 | ngOnInit() {
61 | this.currentUser = localStorage.getItem('currentUser');
62 | if(!localStorage.getItem('currentUser') && !localStorage.getItem('googleUser'))
63 | {
64 | this.router.navigate([''])
65 | }
66 | this.userDetails();
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Angular Auth
4 | Authentication app powered by Angular and [Cosmic JS](https://cosmicjs.com). [Read about how it was built](https://cosmicjs.com/articles/how-to-build-an-authentication-app-using-angular-6-and-cosmic-js-jqe0nsg0).
5 |
6 | ### [View the demo](https://cosmicjs.com/apps/angular-authentication-app)
7 |
8 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 6.1.1.
9 |
10 | # Get Started
11 |
12 | ## Running server:
13 |
14 | ```
15 | git clone https://github.com/a9kitkumar/angular_cosmicjs_auth
16 | cd angular_cosmicjs_auth
17 | npm install
18 | COSMIC_BUCKET=your-bucket-slug COSMIC_READ_KEY=your-read-key COSMIC_WRITE_KEY=your-write-key npm run build
19 | npm start
20 | ```
21 |
22 | ## Development server
23 |
24 | 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.
25 |
26 | ## Screenshots
27 |
28 |
29 |
30 | ## Code scaffolding
31 |
32 | 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`.
33 |
34 | ## Build
35 |
36 | 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.
37 |
38 | ## Running unit tests
39 |
40 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
41 |
42 | ## Running end-to-end tests
43 |
44 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
45 |
46 | ## Further help
47 |
48 | 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).
49 |
50 | ## Import Bucket
51 | ```
52 | You can download bucket.json file from this repo and import it to your Cosmic JS bucket. Follow the following steps:
53 | Login to Cosmic JS account
54 | Select your default bucket
55 | Goto Settings > Import/Export and click "Add import file", then choose downloaded "bucket.json" file
56 |
57 | ```
58 |
--------------------------------------------------------------------------------
/src/app/components/authentication/authentication.component.html:
--------------------------------------------------------------------------------
1 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/src/app/services/apicall.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { config } from './../../config/cosmic.config';
3 | import { Http } from '@angular/http';
4 | import { userModel } from './../models/user.model';
5 |
6 | @Injectable({
7 | providedIn: 'root'
8 | })
9 | export class ApicallService {
10 |
11 | constructor(private _http: Http) { }
12 |
13 | //logging user in
14 | login(userModel: userModel) {
15 | return this._http.get(config.URL + config.bucket_slug + "/object-type/users/search", {
16 |
17 | params: {
18 | metafield_key: 'email',
19 | metafield_value: userModel.email,
20 | limit: 1,
21 | read_key: config.read_key
22 | }
23 | })
24 | }
25 |
26 | //register user with email
27 | register(data: userModel) {
28 | console.log(data.password);
29 | return this._http.post(config.URL + config.bucket_slug + "/add-object/", {
30 | title: data.fullName, slug: data.fullName + data.email, type_slug: 'users', write_key: config.write_key,
31 |
32 | metafields: [
33 | {
34 | key: "fullName",
35 | type: "text",
36 | value: data.fullName
37 | },
38 | {
39 | key: "email",
40 | type: "text",
41 | value: data.email
42 | },
43 | {
44 | key: "password",
45 | type: "text",
46 | value: data.password
47 | },
48 | {
49 | key: "gender",
50 | type: "text",
51 | value: data.gender
52 | },
53 | {
54 | key: "mobile",
55 | type: "text",
56 | value: data.mobile
57 | },
58 |
59 | ]
60 | })
61 | }
62 |
63 | //check presence of Google user in Cosmic JS database
64 | checkGoogleUser(data) {
65 | console.log(data.email)
66 | return this._http.get(config.URL + config.bucket_slug + "/object-type/googleusers/search", {
67 |
68 | params: {
69 | metafield_key: 'email',
70 | metafield_value: data.email,
71 | limit: 1,
72 | read_key: config.read_key
73 | }
74 | })
75 | }
76 |
77 | //register with Google
78 | googleRegister(data) {
79 | // console.log(data);
80 | return this._http.post(config.URL + config.bucket_slug + "/add-object/", {
81 | title: data.name, slug: data.name + data.email, type_slug: 'googleusers', write_key: config.write_key,
82 |
83 | metafields: [
84 | {
85 | key: "fullName",
86 | type: "text",
87 | value: data.name
88 | },
89 | {
90 | key: "email",
91 | type: "text",
92 | value: data.email
93 | },
94 | {
95 | key: "password",
96 | type: "text",
97 | value: 'N/A'
98 | },
99 | {
100 | key: "gender",
101 | type: "text",
102 | value: "N/A"
103 | },
104 | {
105 | key: "mobile",
106 | type: "text",
107 | value: "N/A"
108 | },
109 | {
110 | key: "image",
111 | type: "text",
112 | value: data.image
113 | },
114 |
115 | ]
116 | })
117 | }
118 |
119 | }
120 |
--------------------------------------------------------------------------------
/src/app/components/register/register.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';
3 | import { userModel } from './../../models/user.model';
4 | import { Router } from '@angular/router';
5 | import { ApicallService } from './../../services/apicall.service';
6 | import { Base64 } from 'js-base64';
7 |
8 | @Component({
9 | selector: 'app-register',
10 | templateUrl: './register.component.html',
11 | styleUrls: ['./register.component.css']
12 | })
13 | export class RegisterComponent implements OnInit {
14 | registerForm: FormGroup; //declare the reactive forms group for register
15 | passwordMatched: boolean = false;
16 | userModel = new userModel();
17 | selectedGender: any;
18 | returnedData: any;
19 | message: any;
20 | loading = "";
21 |
22 | constructor(
23 | private fb: FormBuilder,
24 | private userService: ApicallService,
25 | private router: Router
26 | )
27 | {
28 | this.registerForm = this.fb.group({
29 | 'fullName': ['', Validators.required],
30 | 'password': ['', [Validators.pattern('^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,}$'), Validators.required]],
31 | 'confirmPassword': ['', Validators.required],
32 | 'email': ['',[Validators.email, Validators.required ]],
33 | 'mobile': ['',[Validators.minLength(10), Validators.required ]]
34 |
35 | });
36 | }
37 |
38 | //method to register the user
39 | register()
40 | {
41 | this.loading = "loading...";
42 | const data = this.registerForm.value;
43 | data.gender = this.selectedGender;
44 | data.password = Base64.encode(data.password);
45 | this.userService.login(data)
46 | .subscribe(res => {
47 | this.loading = "";
48 | this.returnedData = res;
49 | var jsondata = JSON.parse(this.returnedData._body);
50 | console.log(jsondata);
51 | if (jsondata.message == "No objects returned.") {
52 | this.userService.register(data)
53 | .subscribe(res => {
54 | console.log(res);
55 | this.message = "Registered successfully, login now";
56 | })
57 | }
58 | else {
59 | this.message = "Email already exists";
60 | }
61 | })
62 | }
63 |
64 | //selected value of gender
65 | gender(value)
66 | {
67 | this.selectedGender = value;
68 | }
69 |
70 | //check the password and confirm password before submit
71 | checkPasswordMatch(password)
72 | {
73 | if(password == this.userModel.confirmPassword)
74 | {
75 | this.passwordMatched = true;
76 | }
77 | else
78 | {
79 | this.passwordMatched = false;
80 | }
81 | }
82 |
83 | checkConfirmPasswordMatch(confirmedPassword)
84 | {
85 | if(confirmedPassword == this.userModel.password)
86 | {
87 | this.passwordMatched = true;
88 | }
89 | else
90 | {
91 | this.passwordMatched = false;
92 | }
93 | }
94 |
95 | //call login page
96 | loginCall()
97 | {
98 | this.router.navigate([''])
99 | }
100 |
101 | ngOnInit() {
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "arrow-return-shorthand": true,
7 | "callable-types": true,
8 | "class-name": true,
9 | "comment-format": [
10 | true,
11 | "check-space"
12 | ],
13 | "curly": true,
14 | "deprecation": {
15 | "severity": "warn"
16 | },
17 | "eofline": true,
18 | "forin": true,
19 | "import-blacklist": [
20 | true,
21 | "rxjs/Rx"
22 | ],
23 | "import-spacing": true,
24 | "indent": [
25 | true,
26 | "spaces"
27 | ],
28 | "interface-over-type-literal": true,
29 | "label-position": true,
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-arg": true,
47 | "no-bitwise": true,
48 | "no-console": [
49 | true,
50 | "debug",
51 | "info",
52 | "time",
53 | "timeEnd",
54 | "trace"
55 | ],
56 | "no-construct": true,
57 | "no-debugger": true,
58 | "no-duplicate-super": true,
59 | "no-empty": false,
60 | "no-empty-interface": true,
61 | "no-eval": true,
62 | "no-inferrable-types": [
63 | true,
64 | "ignore-params"
65 | ],
66 | "no-misused-new": true,
67 | "no-non-null-assertion": true,
68 | "no-shadowed-variable": true,
69 | "no-string-literal": false,
70 | "no-string-throw": true,
71 | "no-switch-case-fall-through": true,
72 | "no-trailing-whitespace": true,
73 | "no-unnecessary-initializer": true,
74 | "no-unused-expression": true,
75 | "no-use-before-declare": true,
76 | "no-var-keyword": true,
77 | "object-literal-sort-keys": false,
78 | "one-line": [
79 | true,
80 | "check-open-brace",
81 | "check-catch",
82 | "check-else",
83 | "check-whitespace"
84 | ],
85 | "prefer-const": true,
86 | "quotemark": [
87 | true,
88 | "single"
89 | ],
90 | "radix": true,
91 | "semicolon": [
92 | true,
93 | "always"
94 | ],
95 | "triple-equals": [
96 | true,
97 | "allow-null-check"
98 | ],
99 | "typedef-whitespace": [
100 | true,
101 | {
102 | "call-signature": "nospace",
103 | "index-signature": "nospace",
104 | "parameter": "nospace",
105 | "property-declaration": "nospace",
106 | "variable-declaration": "nospace"
107 | }
108 | ],
109 | "unified-signatures": true,
110 | "variable-name": false,
111 | "whitespace": [
112 | true,
113 | "check-branch",
114 | "check-decl",
115 | "check-operator",
116 | "check-separator",
117 | "check-type"
118 | ],
119 | "no-output-on-prefix": true,
120 | "use-input-property-decorator": true,
121 | "use-output-property-decorator": true,
122 | "use-host-property-decorator": true,
123 | "no-input-rename": true,
124 | "no-output-rename": true,
125 | "use-life-cycle-interface": true,
126 | "use-pipe-transform-interface": true,
127 | "component-class-suffix": true,
128 | "directive-class-suffix": true
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/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/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
38 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
39 |
40 | /** IE10 and IE11 requires the following for the Reflect API. */
41 | // import 'core-js/es6/reflect';
42 |
43 |
44 | /** Evergreen browsers require these. **/
45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
46 | import 'core-js/es7/reflect';
47 |
48 |
49 | /**
50 | * Web Animations `@angular/platform-browser/animations`
51 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
52 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
53 | **/
54 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
55 |
56 | /**
57 | * By default, zone.js will patch all possible macroTask and DomEvents
58 | * user can disable parts of macroTask/DomEvents patch by setting following flags
59 | */
60 |
61 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
62 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
63 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
64 |
65 | /*
66 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
67 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
68 | */
69 | // (window as any).__Zone_enable_cross_context_check = true;
70 |
71 | /***************************************************************************************************
72 | * Zone JS is required by default for Angular itself.
73 | */
74 | import 'zone.js/dist/zone'; // Included with Angular CLI.
75 |
76 |
77 |
78 | /***************************************************************************************************
79 | * APPLICATION IMPORTS
80 | */
81 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "ngAuth": {
7 | "root": "",
8 | "sourceRoot": "src",
9 | "projectType": "application",
10 | "prefix": "app",
11 | "schematics": {},
12 | "architect": {
13 | "build": {
14 | "builder": "@angular-devkit/build-angular:browser",
15 | "options": {
16 | "outputPath": "dist/ngAuth",
17 | "index": "src/index.html",
18 | "main": "src/main.ts",
19 | "polyfills": "src/polyfills.ts",
20 | "tsConfig": "src/tsconfig.app.json",
21 | "assets": [
22 | "src/favicon.ico",
23 | "src/assets"
24 | ],
25 | "styles": [
26 | "src/styles.css"
27 | ],
28 | "scripts": []
29 | },
30 | "configurations": {
31 | "production": {
32 | "fileReplacements": [
33 | {
34 | "replace": "src/environments/environment.ts",
35 | "with": "src/environments/environment.prod.ts"
36 | }
37 | ],
38 | "optimization": true,
39 | "outputHashing": "all",
40 | "sourceMap": false,
41 | "extractCss": true,
42 | "namedChunks": false,
43 | "aot": true,
44 | "extractLicenses": true,
45 | "vendorChunk": false,
46 | "buildOptimizer": true
47 | }
48 | }
49 | },
50 | "serve": {
51 | "builder": "@angular-devkit/build-angular:dev-server",
52 | "options": {
53 | "browserTarget": "ngAuth:build"
54 | },
55 | "configurations": {
56 | "production": {
57 | "browserTarget": "ngAuth:build:production"
58 | }
59 | }
60 | },
61 | "extract-i18n": {
62 | "builder": "@angular-devkit/build-angular:extract-i18n",
63 | "options": {
64 | "browserTarget": "ngAuth:build"
65 | }
66 | },
67 | "test": {
68 | "builder": "@angular-devkit/build-angular:karma",
69 | "options": {
70 | "main": "src/test.ts",
71 | "polyfills": "src/polyfills.ts",
72 | "tsConfig": "src/tsconfig.spec.json",
73 | "karmaConfig": "src/karma.conf.js",
74 | "styles": [
75 | "src/styles.css"
76 | ],
77 | "scripts": [],
78 | "assets": [
79 | "src/favicon.ico",
80 | "src/assets"
81 | ]
82 | }
83 | },
84 | "lint": {
85 | "builder": "@angular-devkit/build-angular:tslint",
86 | "options": {
87 | "tsConfig": [
88 | "src/tsconfig.app.json",
89 | "src/tsconfig.spec.json"
90 | ],
91 | "exclude": [
92 | "**/node_modules/**"
93 | ]
94 | }
95 | }
96 | }
97 | },
98 | "ngAuth-e2e": {
99 | "root": "e2e/",
100 | "projectType": "application",
101 | "architect": {
102 | "e2e": {
103 | "builder": "@angular-devkit/build-angular:protractor",
104 | "options": {
105 | "protractorConfig": "e2e/protractor.conf.js",
106 | "devServerTarget": "ngAuth:serve"
107 | },
108 | "configurations": {
109 | "production": {
110 | "devServerTarget": "ngAuth:serve:production"
111 | }
112 | }
113 | },
114 | "lint": {
115 | "builder": "@angular-devkit/build-angular:tslint",
116 | "options": {
117 | "tsConfig": "e2e/tsconfig.e2e.json",
118 | "exclude": [
119 | "**/node_modules/**"
120 | ]
121 | }
122 | }
123 | }
124 | }
125 | },
126 | "defaultProject": "ngAuth"
127 | }
--------------------------------------------------------------------------------
/src/app/components/authentication/authentication.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { Http } from '@angular/http';
3 | import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';
4 | import { ApicallService } from './../../services/apicall.service';
5 | import { Router } from '@angular/router';
6 | import {
7 | AuthService,
8 | GoogleLoginProvider,
9 | } from 'angular-6-social-login-v2';
10 | import { Base64 } from 'js-base64';
11 |
12 | @Component({
13 | selector: 'app-authentication',
14 | templateUrl: './authentication.component.html',
15 | styleUrls: ['./authentication.component.css']
16 | })
17 | export class AuthenticationComponent implements OnInit {
18 | loginForm: FormGroup; //declare the reactive forms group for login
19 | registerDiv = false; //keep the register div hidden untill called
20 | loginDiv = true; //keep the login div visible by default
21 | returnedData: any;
22 | message: any;
23 | loading = "";
24 | googleData: any;
25 | returnedData2: any;
26 | finalData: any;
27 |
28 | constructor(
29 | private _http: Http,
30 | private fb: FormBuilder,
31 | private userService: ApicallService,
32 | private router: Router,
33 | private socialAuthService: AuthService
34 | )
35 | {
36 | this.loginForm = this.fb.group({
37 | 'email': ['',[Validators.email, Validators.required ]],
38 | 'password': ['', Validators.required],
39 | });
40 | }
41 |
42 | //login function
43 | login()
44 | {
45 | this.loading = "loading...";
46 | const credentials = this.loginForm.value;
47 | credentials.password = Base64.encode(credentials.password)
48 | this.userService.login(credentials)
49 | .subscribe((result)=>{
50 | this.loading = "";
51 | this.returnedData = result;
52 | var jsondata = JSON.parse(this.returnedData._body);
53 | if (jsondata.message == "No objects returned.") {
54 | this.message = "Email or password don't matched";
55 | return;
56 | }
57 | else if(credentials.password == jsondata.objects[0].metadata.password )
58 | {
59 | localStorage.setItem('currentUser', JSON.stringify(jsondata));
60 | this.router.navigate(['dashboard']);
61 | }
62 | else
63 | {
64 | this.message = "Password is wrong!!";
65 | }
66 | })
67 | }
68 |
69 | //register call
70 | registerCall()
71 | {
72 | this.router.navigate(['register'])
73 | }
74 |
75 | //login with Google
76 | public socialSignIn(socialPlatform : string) {
77 | let socialPlatformProvider;
78 | if(socialPlatform == "google"){
79 | socialPlatformProvider = GoogleLoginProvider.PROVIDER_ID;
80 | }
81 | this.socialAuthService.signIn(socialPlatformProvider).then(
82 | (userData) => {
83 | console.log(socialPlatform+" sign in data : " , userData);
84 |
85 | //check Google account previously logged in any time?
86 | this.loading = "loading...";
87 | this.userService.checkGoogleUser(userData)
88 | .subscribe((res)=>{
89 |
90 | this.returnedData = res;
91 | var jsondata = JSON.parse(this.returnedData._body);
92 | console.log(jsondata);
93 | if (jsondata.message == "No objects returned.") {
94 |
95 | //if google user is new
96 | this.userService.googleRegister(userData)
97 | .subscribe((result)=>
98 | {
99 | this.userService.checkGoogleUser(userData) //get user's details to store in local storage
100 | .subscribe((res)=>{
101 | this.loading = "";
102 | this.finalData = res;
103 | var jsondata = JSON.parse(this.finalData._body);
104 | localStorage.setItem('googleUser', JSON.stringify(jsondata));
105 | this.router.navigate(['dashboard']);
106 | })
107 | })
108 | }
109 | else {
110 | this.loading = "";
111 | localStorage.setItem('googleUser', JSON.stringify(jsondata));
112 | this.router.navigate(['dashboard']);
113 | }
114 | })
115 | }
116 | );
117 | }
118 |
119 |
120 | ngOnInit() {
121 | if(localStorage.getItem('currentUser') || localStorage.getItem('googleUser') )
122 | {
123 | this.router.navigate(['dashboard'])
124 | }
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/src/app/components/register/register.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
{{loading}}
{{message}}
91 |
92 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------