login
This commit is contained in:
@@ -1,60 +1,32 @@
|
||||
|
||||
|
||||
<form novalidate (ngSubmit)="onSubmit(form.value)" [formGroup]="form" >
|
||||
<div class="lrContainer">
|
||||
<mat-card class="lrCard">
|
||||
<mat-card-header>
|
||||
<mat-card-title>
|
||||
<h2>Login</h2>
|
||||
</mat-card-title>
|
||||
</mat-card-header>
|
||||
<div class="lrContainer">
|
||||
<mat-card class="lrCard">
|
||||
|
||||
<mat-card-header>
|
||||
<mat-card-title>
|
||||
<h2>Login</h2>
|
||||
</mat-card-title>
|
||||
</mat-card-header>
|
||||
|
||||
<mat-form-field class="fullWidth">
|
||||
<input matInput placeholder="Username"
|
||||
[formControlName]="'userName'"
|
||||
[id]="'userName'"
|
||||
[type]="'text'"
|
||||
[name]="'userName'">
|
||||
</mat-form-field>
|
||||
<mat-form-field class="fullWidth">
|
||||
<input matInput placeholder="Username"
|
||||
[formControlName]="'userName'"
|
||||
[id]="'userName'"
|
||||
[type]="'text'"
|
||||
[name]="'userName'">
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field class="fullWidth">
|
||||
<input matInput placeholder="Password"
|
||||
[formControlName]="'password'"
|
||||
[id]="'password'"
|
||||
[type]="'password'"
|
||||
[name]="'password'">
|
||||
</mat-form-field>
|
||||
<mat-form-field class="fullWidth">
|
||||
<input matInput placeholder="Password"
|
||||
[formControlName]="'password'"
|
||||
[id]="'password'"
|
||||
[type]="'password'"
|
||||
[name]="'password'">
|
||||
</mat-form-field>
|
||||
|
||||
<button type="submit" mat-raised-button color="primary" [disabled]="!form.valid">Login</button>
|
||||
<button mat-button [routerLink]="['/register']" >Register</button>
|
||||
<button type="submit" mat-raised-button color="primary" [disabled]="!form.valid">Login</button>
|
||||
<button mat-button [routerLink]="['/register']" >Register</button>
|
||||
|
||||
</mat-card>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
<h2>Login</h2>
|
||||
<form name="form" (ngSubmit)="f.form.valid && login()" #f="ngForm" novalidate>
|
||||
<div class="form-group" [ngClass]="{ 'has-error': f.submitted && !username.valid }">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" class="form-control" name="username" [(ngModel)]="model.username" #username="ngModel" required />
|
||||
<div *ngIf="f.submitted && !username.valid" class="help-block">Username is required</div>
|
||||
</div>
|
||||
<div class="form-group" [ngClass]="{ 'has-error': f.submitted && !password.valid }">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" class="form-control" name="password" [(ngModel)]="model.password" #password="ngModel" required />
|
||||
<div *ngIf="f.submitted && !password.valid" class="help-block">Password is required</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button [disabled]="loading" class="btn btn-primary">Login</button>
|
||||
<img *ngIf="loading" src="data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA==" />
|
||||
<a [routerLink]="['/register']" class="btn btn-link">Register</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
-->
|
||||
</mat-card>
|
||||
</div>
|
||||
</form>
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';
|
||||
import { RegistrationService } from '../registration.service';
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -16,8 +17,9 @@ export class LoginComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router
|
||||
) { }
|
||||
private router: Router,
|
||||
private registrationService: RegistrationService
|
||||
) { }
|
||||
|
||||
ngOnInit() {
|
||||
// reset login status
|
||||
@@ -51,6 +53,20 @@ export class LoginComponent implements OnInit {
|
||||
return formValidators;
|
||||
}
|
||||
|
||||
|
||||
onSubmit( form ){
|
||||
this.registrationService.loginUser( form ).subscribe( data => {
|
||||
//this.router.navigate([this.returnUrl]);
|
||||
console.log( "valid" );
|
||||
},
|
||||
error => {
|
||||
console.log( "you suck, no long for you!" );
|
||||
//this.alertService.error(error);
|
||||
//this.loading = false;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
login() {
|
||||
/*
|
||||
this.loading = true;
|
||||
|
||||
@@ -21,7 +21,8 @@ export class RegisterComponent implements OnInit {
|
||||
private registrationService: RegistrationService,
|
||||
private usernameValidator: UsernameValidator,
|
||||
private emailValidator: EmailValidator,
|
||||
public formBuilder: FormBuilder
|
||||
public formBuilder: FormBuilder,
|
||||
public router : Router
|
||||
|
||||
){ }
|
||||
|
||||
@@ -67,8 +68,7 @@ export class RegisterComponent implements OnInit {
|
||||
|
||||
onSubmit( form ){
|
||||
this.registrationService.createNewUser( form ).subscribe( data => {
|
||||
console.log(data);
|
||||
//this.router.navigateByUrl("/login");
|
||||
this.router.navigateByUrl("/login");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -12,9 +12,8 @@ const httpOptions = {
|
||||
export class RegistrationService {
|
||||
|
||||
APIURL = "http://192.241.155.78/api.php";
|
||||
registrationUrl = "http://192.241.155.78/registrationCreation.php";
|
||||
|
||||
/* Needed for post, could be moved to local method variable */
|
||||
registrationUrl = "http://192.241.155.78/interfaceServices/registrationInterface.php/users/";
|
||||
login Url = "http://192.241.155.78/interfaceServices/loginInterface.php/users/";
|
||||
params;
|
||||
|
||||
constructor(
|
||||
@@ -41,15 +40,26 @@ export class RegistrationService {
|
||||
|
||||
createNewUser( userData ): Observable<any>{
|
||||
|
||||
|
||||
/* needed for content-type x-www */
|
||||
this.params = new HttpParams({
|
||||
fromObject: userData
|
||||
});
|
||||
|
||||
return this.http.post( this.registrationUrl, this.params, httpOptions )
|
||||
.map(res => {
|
||||
console.log(res)
|
||||
return(
|
||||
res
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
loginUser( userData ): Observable<any>{
|
||||
|
||||
this.params = new HttpParams({
|
||||
fromObject: userData
|
||||
});
|
||||
|
||||
return this.http.get( this.loginUrl, this.params, httpOptions )
|
||||
.map(res => {
|
||||
return(
|
||||
res
|
||||
);
|
||||
|
||||
@@ -17,20 +17,11 @@ export class EmailValidator {
|
||||
return new Promise(resolve => {
|
||||
this.debouncer = setTimeout(() => {
|
||||
this.registrationService.validateEmail(control.value).subscribe((res) => {
|
||||
console.log(res.users.length)
|
||||
if(res.users.length === 0){
|
||||
resolve(null);
|
||||
}else{
|
||||
resolve({'emailInUse': true});
|
||||
}
|
||||
/*
|
||||
if(res.ok){
|
||||
resolve(null);
|
||||
}
|
||||
}, (err) => {
|
||||
resolve({'usernameInUse': true});
|
||||
*/
|
||||
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
@@ -17,19 +17,11 @@ export class UsernameValidator {
|
||||
return new Promise(resolve => {
|
||||
this.debouncer = setTimeout(() => {
|
||||
this.registrationService.validateUserName(control.value).subscribe((res) => {
|
||||
console.log(res.users.length)
|
||||
if(res.users.length === 0){
|
||||
resolve(null);
|
||||
}else{
|
||||
resolve({'usernameInUse': true});
|
||||
}
|
||||
/*
|
||||
if(res.ok){
|
||||
resolve(null);
|
||||
}
|
||||
}, (err) => {
|
||||
resolve({'usernameInUse': true});
|
||||
*/
|
||||
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
Reference in New Issue
Block a user