Login, Reegister and Contribute page done by suren

This commit is contained in:
sriram-at-840620226347 2019-09-25 10:49:32 +05:30
parent 0f49cee348
commit 477e11004c
18 changed files with 632 additions and 244 deletions

View File

@ -2,9 +2,9 @@ import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterModule } from '@angular/router';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
// import { HttpModule, Http } from '@angular/';
import { HttpClientModule, HttpClient} from '@angular/common/http';
import { HttpClientModule, HttpClient, HTTP_INTERCEPTORS} from '@angular/common/http';
import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';
import { PERFECT_SCROLLBAR_CONFIG } from 'ngx-perfect-scrollbar';
@ -46,6 +46,9 @@ import { ProjectsComponent } from './components/projects/projects.component';
import { PaymentComponent } from './components/payment/payment.component';
import { PaymentConfirmationComponent } from './components/payment-confirmation/payment-confirmation.component';
import { MyAccountComponent } from './components/my-account/my-account.component';
import { TokenInterceptorService } from './shared/guards/token-interceptor.service';
import { AuthGuardService } from './shared/guards/auth-guard.service';
import { MatTableDataSource, MatTableModule } from '@angular/material';
// import { AddEventModule } from './add-event.module';
export function HttpLoaderFactory(http: HttpClient) {
@ -86,6 +89,7 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
MatListModule,
MatMenuModule,
MatToolbarModule,
ReactiveFormsModule,
MatTabsModule,
NgxDatatableModule,
MatCheckboxModule,
@ -93,6 +97,7 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
SlickCarouselModule,
MatSelectModule,
MatCardModule,
MatTableModule,
DemoMaterialModule,
HttpClientModule,
TranslateModule.forRoot({
@ -112,7 +117,11 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
{
provide: PERFECT_SCROLLBAR_CONFIG,
useValue: DEFAULT_PERFECT_SCROLLBAR_CONFIG
}
},{
provide:HTTP_INTERCEPTORS,
useClass: TokenInterceptorService,
multi: true
},AuthGuardService,
],
entryComponents: [],
bootstrap: [AppComponent]

View File

@ -2,163 +2,134 @@
<!--starts-->
<div fxLayout fxLayout="row" fxLayout.xs="column" fxLayoutGap.xs="0">
<!-- <div fxFlex.xs="100" fxFlex.sm="100" fxFlex.md="40" fxFlex.lg="1000" fxFlex.xl="40"> -->
<mat-card class="p-2" fxFlex="60%" fxFlex.xs="100" fxFlex.sm="100">
<mat-card-title><h5 class="mt-0">Be a Champion of Change </h5></mat-card-title>
<mat-card class="p-2" fxFlex="70%" fxFlex.xs="100" fxFlex.sm="100">
<mat-card-title class="mb-1"><h5 class="mt-0">Be a Champion of Change </h5></mat-card-title>
<hr>
<form method="post">
<div fxLayout="row" fxLayoutAlign="start center" class="mb-2 pt-1">
<form [formGroup]="Contribute">
<div fxLayout="row" fxLayoutAlign="start center" class="mb-2 pt-1">
<mat-form-field dividerColor="primary" class="ml-xs mr-xs" style="width: 100%;">
<mat-select placeholder="Select District" [(ngModel)]="currentDrink" [required]="isRequired" [disabled]="isDisabled" #drinkControl="ngModel">
<mat-option *ngFor="let item of districtList" [value]="item.id" >
{{ item.value }}
<mat-select placeholder="Select District" formControlName="district_id" [required]="isRequired" [disabled]="isDisabled">
<mat-option *ngFor="let item of district" [value]="item.district_id" >
{{ item.district_name }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field dividerColor="accent" class="ml-xs mr-xs" style="width: 100%;">
<mat-select placeholder="Select Schools" [(ngModel)]="currentDrink" [required]="isRequired" [disabled]="isDisabled" #drinkControl="ngModel">
<mat-option *ngFor="let item of schoolList" [value]="item.id" >
{{ item.value }}
<mat-select placeholder="Select Schools" formControlName="schoold_id" [required]="isRequired" [disabled]="isDisabled">
<mat-option *ngFor="let item of school" [value]="item.school_id" >
{{ item.school_name }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field dividerColor="warn" class="ml-xs mr-xs" style="width: 100%;">
<mat-select placeholder="Select Category" [(ngModel)]="currentDrink" [required]="isRequired" [disabled]="isDisabled" #drinkControl="ngModel">
<mat-option *ngFor="let item of categoryList" [value]="item.id" >
{{ item.value }}
<mat-select placeholder="Select Category" formControlName="cad_id" [required]="isRequired" [disabled]="isDisabled">
<mat-option *ngFor="let item of category" [value]="item.cad_id" >
{{ item.cat_name }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<table class="shop-table table-responsive" cellspacing="0">
<thead>
<tr>
<!-- <th class="product-remove">&nbsp;</th> -->
<th class="product-thumbnail">&nbsp;</th>
<th class="product-name">Requirement</th>
<th class="product-price">Quantity</th>
<th class="product-quantity">Sponsor</th>
<!-- <th class="product-subtotal"></th> -->
</tr>
</thead>
<tbody>
<tr class="cart_item">
<!-- <td class="product-remove">
<a href="#" class="remove" title="Remove this item">×</a> </td> -->
<td class="product-thumbnail">
<a href="#"><img src="assets/images/csr-img/donate.jpg" alt="" width="100"></a>
</td>
<td class="product-name">Student Benches required at Govt Girls School, Panruti, Villupuram Dt.</td>
<td class="product-price">
<span class=" amount">30</span>
</td>
<td class="product-quantity" data-title="Quantity">
<div class="quantity buttons_added">
<input step="1" min="0" max="" value="3" title="Qty" class="text" size="4" type="number">
</div>
</td>
<!-- <td class="product-subtotal" data-title="Total">
<span class="price-amount"><span>&#8377;</span>69.00</span>
</td> -->
</tr>
<tr class="cart_item">
<!-- <td class="product-remove">
<a href="#" class="remove" title="Remove this item">×</a> </td> -->
<td class="product-thumbnail">
<a href="#"><img src="assets/images/csr-img/img1.jpeg" alt="" width="100"></a>
</td>
<td class="product-name">
<a href="#">Desktop Computers require for GGHSS,Palacode</a> </td>
<td class="product-price">
<span class=" amount">15</span>
</td>
<td class="product-quantity" data-title="Quantity">
<div class="quantity buttons_added">
<input step="1" min="0" max="" value="3" title="Qty" class="text" size="4" type="number">
</div>
</td>
<!-- <td class="product-subtotal" data-title="Total">
<span class="price-amount"><span>&#8377;</span>69.00</span>
</td> -->
</tr>
<tr class="cart_item">
<!-- <td class="product-remove">
<a href="#" class="remove" title="Remove this item">×</a> </td> -->
<td class="product-thumbnail">
<a href="#"><img src="assets/images/csr-img/img2.jpeg" alt="" width="100"></a>
</td>
<td class="product-name">
<a href="#">Smartboard required for CPS Kannammapey</a> </td>
<td class="product-price">
<span class=" amount">5</span>
</td>
<td class="product-quantity" data-title="Quantity">
<div class="quantity buttons_added">
<input step="1" min="0" max="" value="3" title="Qty" class="text" size="4" type="number">
</div>
</td>
<!-- <td class="product-subtotal" data-title="Total">
<span class="price-amount"><span>&#8377;</span>69.00</span>
</td> -->
</tr>
<tr class="cart_item">
<!-- <td class="product-remove">
<a href="#" class="remove" title="Remove this item">×</a> </td> -->
<td class="product-thumbnail">
<a href="#"><img src="assets/images/csr-img/img3.jpg" alt="" width="100"></a>
</td>
<td class="product-name">
<a href="#">R.O Purifier required for 500 students in GHS, Periamedu</a> </td>
<td class="product-price">
<span class=" amount">2</span>
</td>
<td class="product-quantity" data-title="Quantity">
<div class="quantity buttons_added">
<input step="1" min="0" max="" value="3" title="Qty" class="text" size="4" type="number">
</div>
</td>
<!-- <td class="product-subtotal" data-title="Total">
<span class="price-amount"><span>&#8377;</span>69.00</span>
</td> -->
</tr>
<!-- <tr>
<td colspan="4" style="text-align: right;">
<strong><span>Total</span></strong>
</td>
<td class="product-subtotal" data-title="Total">
<strong><span class="amount"><span class="currency-symbol">&#8377;</span>167.00</span></strong>
</td>
</tr> -->
</tbody>
</table>
<div class="pt-1" style="text-align: right;">
<button mat-raised-button color="primary" class="mr-1 mb-1">Will Contribute the above in kind</button>
<button [routerLink]="['../payment']" mat-raised-button style="background-color:rgb(69, 189, 189);color:white" >Proceed for Payment</button>
</div>
</form>
<!-- <div class="clearfix order-total">
<div class="calculated-shipping">
<h4>Cart Totals</h4>
<table class="table-responsive" cellspacing="0">
<tr class="cart-subtotal">
<th>Subtotal</th>
<td><span class="amount"><span class="currency-symbol">&#8377;</span>167.00</span>
</td>
</tr>
<tr class="order-total">
<th>Total</th>
<td><strong><span class="amount"><span class="currency-symbol">&#8377;</span>167.00</span></strong> </td>
</tr>
</table>
<div class="order-checkout">
<button mat-raised-button color="primary" class="mr-1">Checkout</button>
</div>
</div>
</div> -->
<mat-form-field dividerColor="warn" class="ml-xs mr-xs" style="width: 100%;">
<mat-select placeholder="Material Name" formControlName="mat_id" [required]="isRequired" [disabled]="isDisabled">
<mat-option *ngFor="let item of material_category" [value]="item.mat_id" >
{{ item.material_name }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div fxLayout fxLayout="row" style="text-align: right;">
<div class="" fxFlex="100%" fxFlex.xs="100" fxFlex.sm="100">
<button mat-raised-button color="primary" (click)="getSchoolReqList()">Submit</button>
</div>
</div>
</form>
<!--*********************-->
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
</mat-form-field>
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<!-- Requirement Column -->
<ng-container matColumnDef="Image" >
<th style="width: 15% !important;" mat-header-cell *matHeaderCellDef mat-sort-header>Image</th>
<td style="width: 15% !important;" mat-cell *matCellDef="let row" class="product-thumbnail"><a href="#"><img src="{{row.img_url}}" alt="School Img" width="70"></a></td>
</ng-container>
<!-- Requirement Column -->
<ng-container matColumnDef="Description">
<th style="width: 50% !important;" mat-header-cell *matHeaderCellDef mat-sort-header>Description</th>
<td style="width: 50% !important;" mat-cell *matCellDef="let row">{{row.material_name}} required at {{row.school_name}}, {{row.block_name}} Block, {{row.district_name}} District.</td>
</ng-container>
<!-- Quantity Column -->
<ng-container matColumnDef="Requirement Qty">
<th style="width: 10% !important;" mat-header-cell *matHeaderCellDef mat-sort-header> Requirement Qty </th>
<td style="width: 10% !important;" mat-cell *matCellDef="let row"> {{row.qty}}</td>
</ng-container>
<!-- Sponsor Column -->
<ng-container matColumnDef="Sponsor">
<th style="width: 10% !important;" mat-header-cell *matHeaderCellDef mat-sort-header> Sponsor </th>
<td style="width: 10% !important;" mat-cell *matCellDef="let row;let i = index"> <input step="1" min="0" max="" title="Qty" class="text" size="2" type="number" (change)="somethingChanged($event.target.value,i,row.cost_per_unit)" style="width: 100% !important;border: none;border-bottom: 1px solid black;"> </td>
</ng-container>
<!-- price Column -->
<ng-container matColumnDef="Cost Per Unit">
<th style="width: 10% !important;" mat-header-cell *matHeaderCellDef mat-sort-header> Cost Per Unit </th>
<td style="width: 10% !important;" mat-cell *matCellDef="let row;"> {{row.cost_per_unit === null?0:row.cost_per_unit}} </td>
<!-- <td mat-footer-cell *matFooterCellDef> Total </td> -->
</ng-container>
<!-- Total Column -->
<ng-container matColumnDef="Total">
<th style="width: 15% !important;" mat-header-cell *matHeaderCellDef mat-sort-header> Total </th>
<td style="width: 15% !important;" mat-cell *matCellDef="let row ;let i=index">{{Total[i]}} </td>
<!-- <td mat-footer-cell *matFooterCellDef> {{somethingChanged()}} </td> -->
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
<!-- <tr mat-footer-row *matFooterRowDef="tableColumns"></tr> -->
</table>
<div class="clearfix order-total" style="padding-bottom: 0px !important;">
<div class="calculated-shipping" style="text-align: -webkit-right !important;">
<table class="table-responsive" cellspacing="0" style="width: 50% !important;">
<tr class="order-total" style="text-align: right;">
<td style="font-weight: bold;">Total</td>
<td> <strong><span class="amount"><span class="currency-symbol">&#8377;</span>{{somethingChanged()}}</span></strong></td>
</tr>
</table>
</div>
</div>
<mat-paginator [pageSize]="pageSize" [pageSizeOptions]="[5, 10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
<div class="pt-1 pr-1" style="text-align: right;">
<button mat-raised-button color="primary" class="mr-1 mb-1">Will Contribute the above in kind</button>
<button [routerLink]="['../payment']" mat-raised-button style="background-color:rgb(69, 189, 189);color:white" >Proceed for Payment</button>
</div>
</div>
<!--*********************-->
<!-- <div class="clearfix order-total">
<div class="calculated-shipping">
<h4>Cart Totals</h4>
<table class="table-responsive" cellspacing="0">
<tr class="order-total">
<th>Total</th>
<td><strong><span class="amount"><span class="currency-symbol">&#8377;</span>{{somethingChanged()}}</span></strong> </td>
</tr>
</table>
<div class="order-checkout">
<button mat-raised-button color="primary" class="mr-1 mb-1">Will Contribute the above in kind</button>
<button [routerLink]="['../payment']" mat-raised-button style="background-color:rgb(69, 189, 189);color:white" >Proceed for Payment</button>
</div>
</div>
</div> -->
</mat-card>
<!-- <div fxFlex.xs="100" fxFlex.sm="100" fxFlex.md="40" fxFlex.lg="20" fxFlex.xl="40"> -->
<mat-card class="support_mat" fxFlex="40%" fxFlex.xs="100" fxFlex.sm="100px">
<mat-card class="support_mat" fxFlex="30%" fxFlex.xs="100" fxFlex.sm="100px">
<mat-card-header>
<mat-card-title>
<h5>Or Contribute to General Development Fund</h5>

View File

@ -1,4 +1,18 @@
.calculated-shipping[_ngcontent-gen-c13]{
padding: 0px !important;
}
table {
width: 100%;
}
.mat-form-field {
font-size: 14px;
width: 100%;
}
td, th {
width: 25%;
}
table.shop-table {
// border-collapse: separate;
border-spacing: 0;

View File

@ -1,4 +1,10 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, ViewChild } from '@angular/core';
import { environment } from '../../../environments/environment';
import { ApiService } from '../../shared/api.service';
import { FormGroup, FormBuilder, FormControl, Validators, } from '@angular/forms';
import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material';
@Component({
selector: 'app-contribute',
@ -6,87 +12,143 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./contribute.component.scss']
})
export class ContributeComponent implements OnInit {
isRequired = false;
isDisabled = false;
currentDrink: string;
drinks = [{
value: 'coke-0',
viewValue: 'Coke'
}, {
value: 'sprite-1',
viewValue: 'Sprite'
}, {
value: 'water-2',
viewValue: 'Water'
}, {
value: 'pepper-3',
viewValue: 'Dr. Pepper'
}, {
value: 'coffee-4',
viewValue: 'Coffee'
}, {
value: 'tea-5',
viewValue: 'Tea'
}, {
value: 'juice-6',
viewValue: 'Orange juice'
}, {
value: 'wine-7',
viewValue: 'Wine'
}, {
value: 'milk-8',
viewValue: 'Milk'
}];
districtList=[{
id:"1",
value:"Chennai"
},{
id:"2",
value:"Vellore"
},{
id:"3",
value:"Thiruvannamalai"
},{
id:"4",
value:"Kanchipuram"
},{
id:"5",
value:"Nagapattinam"
},]
schoolList=[{
id:"1",
value:"Govt High School"
},
{
id:"2",
value:"Govt Primary School"
}]
categoryList=[{
id:"1",
value:"Building"
},
{
id:"2",
value:"Furnitures"
},
{
id:"2",
value:"Students kit"
}]
constructor() { }
displayedColumns: string[] = ['Image', 'Description', 'Requirement Qty', 'Sponsor', 'Cost Per Unit', 'Total'];
dataSource:any = new MatTableDataSource();
dataLength :number;
@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
@ViewChild(MatSort, {static: true}) sort: MatSort;
pageSize = 5;
Contribute: FormGroup;
material_category: any = [];
district: any = [];
school: any = [];
category: any = [];
Total: any = [];
ngOnInit() {
constructor(public restApi:ApiService,public fb:FormBuilder) {
// Create 100 users
}
// ngOnInit() {
// this.dataSource.paginator = this.paginator;
// this.dataSource.sort = this.sort;
// }
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
if (this.dataSource.paginator) {
this.dataSource.paginator.firstPage();
}
}
ngOnInit() {
// this.getSchoolReqList();
this.initForm();
this.getSchoolReqList();
this.getSchoolReqList2();
}
initForm()
{
this.Contribute = this.fb.group(
{
schoold_id: new FormControl(''),
district_id: new FormControl(''),
cad_id: new FormControl(''),
mat_id: new FormControl('')
})
}
getSchoolReqList()
{
let url = `${environment.apiUrl}${'getSchoolReqList'}`;
let data = this.Contribute.value;
this.restApi.post(url,data).subscribe(schDet=>
{
if(schDet.dataStatus==true)
{
this.dataLength = schDet.records.length;
this.dataSource.data = schDet.records;
// console.log(this.material_category);
// this.dataSource.data = schDet.records.map((val, i)=>{
// val['SerialNo'] = i + 2;
// return val;
// })
// console.log(this.dataSource.data);
}
})
}
somethingChanged(e,i,item){
// console.log(e,i,item);
this.Total[i] = e*item;
// console.log(this.Total);
return ( this.Total.reduce((acc, value) => acc + value, 0));
}
getSchoolReqList2()
{
let url = `${environment.apiUrl}${'getSchoolReqList'}`;
let data = this.Contribute.value;
this.restApi.post(url,data).subscribe(schDet=>
{
if(schDet.dataStatus==true)
{
this.material_category = schDet.records.map(item=>({mat_id:item.mat_id,material_name:item.material_name}));
this.material_category = this.material_category.filter((test, index, array) =>
index === array.findIndex((findTest) =>
findTest.material_name === test.material_name
)
);
this.district = schDet.records.map(item=>({district_id:item.district_id,district_name:item.district_name}));
this.district = this.district.filter((test, index, array) =>
index === array.findIndex((findTest) =>
findTest.district_name === test.district_name
)
);
this.school = schDet.records.map(item=>({school_id:item.school_id,school_name:item.school_name}));
this.school = this.school.filter((test, index, array) =>
index === array.findIndex((findTest) =>
findTest.school_name === test.school_name
)
);
this.category = schDet.records.map(item=>({cad_id:item.cad_id,cat_name:item.cat_name}));
this.category = this.category.filter((test, index, array) =>
index === array.findIndex((findTest) =>
findTest.cat_name === test.cat_name
)
);
// console.log('mat'+JSON.stringify(this.material_category ));
// console.log('dis'+JSON.stringify(this.district ));
// console.log('sch'+JSON.stringify(this.school ));
}
})
// console.log('mat'+this.material_category);
}
ngAfterViewInit() {
// Hack: Scrolls to top of Page after page view initialized
let top = document.getElementById('top');
console.log("d",top);
// console.log("d",top);
if (top !== null) {
top.scrollIntoView();
top = null;
}
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
}

View File

@ -1,7 +1,7 @@
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { CommonModule } from '@angular/common';
import { MatIconModule, MatCardModule, MatButtonModule, MatListModule, MatProgressBarModule, MatMenuModule, MatFormField, MatFormFieldModule, MatInputModule, MatButtonToggleModule, MatTabsModule,MatSelectModule, MatRadioModule } from '@angular/material';
import { MatIconModule, MatCardModule, MatButtonModule, MatListModule, MatProgressBarModule, MatMenuModule, MatFormField, MatFormFieldModule, MatInputModule, MatButtonToggleModule, MatTabsModule,MatSelectModule, MatRadioModule, MatTableDataSource, MatTableModule } from '@angular/material';
import { FlexLayoutModule } from '@angular/flex-layout';
import { ChartsModule } from 'ng2-charts/ng2-charts';
@ -18,12 +18,14 @@ import { ProjectDetailComponent } from 'app/components/project-detail/project-de
import {FooterComponent} from 'app/components/footer/footer.component'
import { SlickCarouselModule } from 'ngx-slick-carousel';
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(DashboardRoutes),
MatIconModule,
MatCardModule,
ReactiveFormsModule,
MatButtonModule,
MatListModule,
MatProgressBarModule,
@ -32,6 +34,7 @@ import { SlickCarouselModule } from 'ngx-slick-carousel';
MatRadioModule,
SlickCarouselModule,
ChartsModule,
MatTableModule,
// NgxChartsModule,
NgxDatatableModule,
FlexLayoutModule,

View File

@ -6,15 +6,15 @@
<div>
<h2 class="base-border">Login Form</h2>
<p>Enter Your Login Details</p>
<form #form="ngForm" (ngSubmit)="login()">
<form [formGroup]="loginForm">
<div fxLayout="column" fxLayoutAlign="start stretch">
<mat-form-field style="width: 100%">
<input matInput placeholder="E-Mail" type="text" name="email" required [(ngModel)]="email">
<input matInput placeholder="E-Mail" type="text" name="email" required formControlName="email">
</mat-form-field>
<mat-form-field style="width: 100%" class="mb-1">
<input matInput placeholder="Password" type="password" name="password" required [(ngModel)]="password">
<input matInput placeholder="Password" type="password" name="password" required formControlName="password">
</mat-form-field>
<button class="mat-green" mat-raised-button>SIGN IN</button>
<button class="mat-green" mat-raised-button (click)="csrUserLogin()">SIGN IN</button>
<p class="mat-text-warn mb-0">Forgot password?</p>
<p class="mb-0">Don't have an account? <a [routerLink]="['../register']" class="mat-text-primary">Register Here</a></p>
</div>

View File

@ -1,5 +1,8 @@
import { Component, OnInit ,ViewEncapsulation } from '@angular/core';
import {Router} from "@angular/router";
import { FormControl, FormBuilder } from '@angular/forms';
import { environment } from 'environments/environment';
import { ApiService } from 'app/shared/api.service';
@Component({
selector: 'ms-login-session',
@ -11,11 +14,58 @@ export class LoginComponent {
email: string;
password: string;
loginForm: any;
constructor(
private router: Router
) { }
constructor(public restApi:ApiService,public fb:FormBuilder,public router:Router) { }
ngOnInit() {
// this.getSchoolReqList();
this.initForm();
}
initForm()
{
this.loginForm = this.fb.group(
{
email: new FormControl(''),
password: new FormControl(''),
})
}
csrUserLogin()
{
// console.log(this.loginForm.value);return false;
let url = `${environment.apiUrl}${'csrUserLogin'}`;
let data = this.loginForm.value;
this.restApi.post(url,data).subscribe(schDet=>
{
// this.load.loadedDismiss();
// console.log(schDet);return false;
// if(schDet.dataStatus==true)
// {
// this.setTokenData(schDet.records);
this.restApi.setToken(schDet.token);
this.router.navigate(['/home']);
// window.localStorage.setItem('token','abcd');
// }else
// {
// // this.toast.apptoast(res.message,'danger');
// window.localStorage.clear();
// return false;
// }
})
}
// setTokenData(records: any) {
// throw new Error("Method not implemented.");
// }
login() {
this.router.navigate(['/']);
}

View File

@ -7,40 +7,43 @@
<div>
<h2 class="base-border">Register as a new user</h2>
<p>We would need some of your information to facilitate your contributions and keep you updated on the progress of the projects or new projects</p>
<form #form="ngForm">
<form [formGroup]="go_reg">
<div fxLayout="column" fxLayoutAlign="start stretch">
<mat-form-field style="width: 100%">
<input matInput placeholder="Name" type="text" name="name" required>
<input matInput placeholder="Name" type="text" name="name" formControlName="name" required>
</mat-form-field>
<mat-form-field style="width: 100%">
<input matInput placeholder="E Mail" type="email" name="email" required>
<input matInput placeholder="E Mail" type="email" name="email" formControlName="email" required>
</mat-form-field>
<mat-form-field style="width: 100%">
<input matInput placeholder="Phone Number" type="number" name="pnum" required>
<input matInput placeholder="Phone Number" type="number" name="mobile" formControlName="mobile" required>
</mat-form-field>
<div fxLayout="row" fxLayoutAlign="start center" class="mb-2">
<mat-form-field style="width: 100%">
<input matInput placeholder="Password" type="password" name="password" formControlName="password" required>
</mat-form-field>
<!-- <div fxLayout="row" fxLayoutAlign="start center" class="mb-2">
<mat-form-field dividerColor="primary" class="ml-xs mr-xs" style="width: 25%;">
<input matInput placeholder="Phone OTP" type="number" name="pOTP" required>
<input matInput placeholder="Phone OTP" type="number" name="pOTP" formControlName="pOTP" required>
</mat-form-field>
<mat-form-field dividerColor="accent" class="ml-xs mr-xs" style="width: 25%;">
<input matInput placeholder="Email OTP" type="emailOTP" name="emailOTP" required>
<input matInput placeholder="Email OTP" type="emailOTP" name="emailOTP" formControlName="emailOTP" required>
</mat-form-field>
<button class="mat-green" mat-raised-button>Verify</button>
</div>
<button class="mat-green" mat-raised-button>Verify</button>
</div> -->
</div>
<hr>
<div fxLayout="column" fxLayoutAlign="start stretch">
<div fxLayout="column" fxLayoutAlign="start stretch" formGroupName="org_info">
<mat-form-field style="width: 100%">
<input matInput placeholder="Organisation Name" type="text" name="OrganisationName" required>
<input matInput placeholder="Organisation Name" type="text" name="orgname" formControlName="orgname" required>
</mat-form-field>
<mat-form-field style="width: 100%;">
<textarea matInput placeholder="Register Address" name="radress" required></textarea>
<textarea matInput placeholder="Register Address" name="org_address" formControlName="org_address" required></textarea>
</mat-form-field>
<mat-form-field style="width: 100%">
<input matInput placeholder="Pan of the Organisation" type="panOrganisation" name="panOrganisation" required>
<input matInput placeholder="Pan of the Organisation" type="number" name="org_pan" formControlName="org_pan" required>
</mat-form-field>
<button class="mat-red" mat-raised-button>Register</button>
<button class="mat-red" mat-raised-button (click)="csrUserRegistration()">Register</button>
</div>
<!-- <div>
<p>Sign Up Using</p> <a href="#" class="shared-icon mr-1 mat-blue"><i class="fa fa-facebook fa-lg mr-1"></i> Facebook</a><a href="#" class="shared-icon mat-red"><i class="fa fa-google fa-lg mr-1"></i>Google</a>

View File

@ -1,5 +1,8 @@
import { Component, OnInit,ViewEncapsulation } from '@angular/core';
import {Router} from "@angular/router";
import { environment } from '../../../environments/environment';
import { ApiService } from '../../shared/api.service';
import { FormBuilder, FormControl } from '@angular/forms';
@Component({
selector: 'ms-register-session',
@ -13,11 +16,46 @@ export class RegisterComponent {
email: string;
password: string;
passwordConfirm: string;
go_reg: any;
constructor(
private router: Router
) { }
constructor(public restApi:ApiService,public fb:FormBuilder,public router:Router) { }
ngOnInit() {
// this.getSchoolReqList();
this.initForm();
}
initForm()
{
this.go_reg = this.fb.group(
{
id: new FormControl(''),
name: new FormControl(''),
email: new FormControl(''),
mobile: new FormControl(''),
password: new FormControl(''),
org_info: this.fb.group({
orgname: new FormControl(''),
org_address: new FormControl(''),
org_pan: new FormControl('')
}),
"created_by":"1",
"updated_by":"1"
})
}
csrUserRegistration()
{
// console.log(this.go_reg.value);return false;
let url = `${environment.apiUrl}${'csrUserRegistration'}`;
let data = this.go_reg.value;
this.restApi.post(url,data).subscribe(schDet=>
{
this.router.navigate(['/authentication/login']);
})
}
register() {
this.router.navigate(['/']);
}

View File

@ -8,7 +8,7 @@ import {
MatButtonModule,
MatProgressBarModule,
MatToolbarModule } from '@angular/material';
import { FormsModule } from '@angular/forms';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatIconModule} from '@angular/material';
import { FlexLayoutModule } from '@angular/flex-layout';
import { LoginComponent } from './login/login.component';
@ -29,6 +29,7 @@ import { SessionRoutes } from './session.routing';
MatInputModule,
MatRadioModule,
MatButtonModule,
ReactiveFormsModule,
MatProgressBarModule,
MatToolbarModule,
FlexLayoutModule

View File

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { ApiService } from './api.service';
describe('ApiService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: ApiService = TestBed.get(ApiService);
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,119 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../environments/environment';
import { Observable,from,of, BehaviorSubject } from 'rxjs';
import { delay } from 'rxjs/internal/operators';
import 'rxjs/Rx';
import 'rxjs/add/operator/toPromise';
// Api Url Enviroment
const apiUrl = environment.apiUrl;
@Injectable({
providedIn: 'root'
})
export class ApiService {
expToken = new BehaviorSubject(false);
constructor(public http:HttpClient) {
this.Token();
}
//POST
post(url:any,data:any): Observable<any>
{
return this.http.post(url,data).map(res=>
{
console.log("Api Call Success `"+url+"`");
return res;
});
}
//GET
get(url)
{
return this.http.get(url).map(res=>
{
console.log("Api Call Success `"+url+"`");
return res;
});
}
//PUT
//DELETE
//JWT Token Decode
jwtDecode(t) {
let token = {};
token['raw'] = t;
token['header'] = JSON.parse(window.atob(t.split('.')[0]));
token['payload'] = JSON.parse(window.atob(t.split('.')[1]));
return (token);
}
private extractData(response: Response) {
console.log(response);
let body = response.json();
return body || {};
}
private handleError(error: Response) {
console.log( 'Error in api service call :' + JSON.stringify( error));
console.log( 'Error in api service call :' + error.status);
// console.log("dataUrl in error post call::"+dataurl);
// console.log(dataurl.substring(dataurl.lastIndexOf("/")+1, dataurl.length));
return Observable.of(error);
// return Observable.throw(error);
}
setToken(token)
{
// console.log(token);
window.localStorage.setItem('token',token);
}
Token()
{
let currToken = window.localStorage.getItem('token');
// console.log(currToken);
if(currToken !=null)
{
this.expToken.next(true);
}else
{
this.expToken.next(false);
}
// console.log(this.expToken);
return currToken;
}
isToken()
{
return this.expToken.value;
}
}

View File

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { AuthGuardService } from './auth-guard.service';
describe('AuthGuardService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: AuthGuardService = TestBed.get(AuthGuardService);
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,22 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild } from '@angular/router';
import { Router } from '@angular/router';
import { ApiService } from '../api.service';
@Injectable({
providedIn: 'root'
})
export class AuthGuardService implements CanActivate{
constructor(public router:Router,public api:ApiService) {
}
canActivate(): boolean {
return this.api.isToken();
}
}

View File

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { TokenInterceptorService } from './token-interceptor.service';
describe('TokenInterceptorService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: TokenInterceptorService = TestBed.get(TokenInterceptorService);
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,58 @@
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpInterceptor,
HttpHeaders
} from '@angular/common/http';
// import { AuthGuard } from './auth.guard';
import { Observable, of} from 'rxjs';
// import { Router } from '@angular/router';
import { catchError, map, tap } from 'rxjs/operators';
import { HttpErrorResponse } from "@angular/common/http";
@Injectable({
providedIn: 'root'
})
export class TokenInterceptorService implements HttpInterceptor {
constructor() { }
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
//TODO Get the auth token from the service.
//TODO replace const authToken = this.auth.getAuthorizationToken();
let token = window.localStorage.getItem('token') || null;
let authReq;
if(token ==null){
authReq = req.clone({
setHeaders: {'Content-Type':'application/json','Authorization':'csr_dev'}
});
}else
{
authReq = req.clone({
setHeaders: {'Token':token,'Authorization':'csr_dev'}
});
}
return next.handle(authReq);
}
private handleError<T> (operation = 'operation', result?: T) {
return (error: any): Observable<T> => {
if(error instanceof HttpErrorResponse){
console.error("Error: " + error.status);
if(error.status == 401){
localStorage.clear();
// this.router.navigate(['/authentication/login']);
}
return of(result as T);
}
};
}
}

View File

@ -1,3 +1,4 @@
export const environment = {
production: true
production: true,
apiUrl:'https://lms.venbainfotech.com/csr/api/',
};

View File

@ -4,5 +4,6 @@
// The list of which env maps to which file can be found in `angular-cli.json`.
export const environment = {
production: false
production: false,
apiUrl:'https://lms.venbainfotech.com/csr/api/',
};