Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
<app-home-navbar></app-home-navbar>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="row">
<!-- LOGIN -->
<div class="col-sm-6">
<div class="login">
<h2 class="login-header">LOG IN</h2>
<form [formGroup]="loginForm" class="login-container" (ngSubmit)="login()">
<div class="form-group mb-3">
<label for="username">Username</label>
<p [ngClass]="{'has-error':isSubmitted && formControls['username'].errors}">
<input type="username" placeholder="Username" class="form-control" formControlName="username">
</p>
<div *ngIf="isSubmitted && formControls['username'].errors" class="help-block">
<div *ngIf="formControls['username'].errors['required']">Username is required</div>
</div>
</div>
<div class="form-group mb-3">
<label for="password">Password</label>
<p [ngClass]="{'has-error':isSubmitted && formControls['password'].errors}">
<input type="password" placeholder="Password" class="form-control" formControlName="password">
</p>
<div *ngIf="isSubmitted && formControls['password'].errors" class="help-block">
<div *ngIf="formControls['password'].errors['required']">Password is required</div>
<div *ngIf="formControls['password'].errors['pattern']">Password should have at least 1 number, 1 special character 1 capital letter and minimum length 8</div>
<!--<div *ngIf="formControls['password'].errors['minlength']">Minlength is required</div>-->
</div>
</div>
<div class="form-check mb-3">
<input type="checkbox" class="form-check-input">
<label class="form-check-label">Remember me</label>
</div>
<div class="button">
<button type="submit" (click)="getLogin()" class="btn btn-success">Log in</button>
<button type="reset" (click)="onReset()" class="btn btn-danger float-right">Reset</button>
</div>
<!--<p>
<input type="submit" value="Log in">
</p>-->
</form>
</div>
</div>
<!-- REGISTER -->
<div class="col-sm-6">
<div class="register">
<h2 class="register-header">REGISTER</h2>
<form [formGroup]="registerForm" class="register-container" (ngSubmit)="register()">
<div class="form-group mb-3">
<label for="username">Username</label>
<p [ngClass]="{'has-error':isRegistered && formControls1['username'].errors}">
<input type="username" placeholder="Username" class="form-control" formControlName="username">
</p>
<div *ngIf="isRegistered && formControls1['username'].errors" class="help-block">
<div *ngIf="formControls1['username'].errors['required']">Username is required</div>
</div>
</div>
<div class="form-group mb-3">
<label for="password">Password</label>
<p [ngClass]="{'has-error':isRegistered && formControls1['password'].errors}">
<input type="password" placeholder="Password" class="form-control" formControlName="password" autocomplete="off" spellcheck="false">
</p>
<div *ngIf="isRegistered && formControls1['password'].errors" class="help-block">
<div *ngIf="formControls1['password'].errors['required']">Password is required</div>
<div *ngIf="formControls1['password'].errors['pattern']">Password should have at least 1 number, one capital letter and minimum length 8</div>
</div>
</div>
<div class="form-group mb-3">
<label for="repassword">Retype Password</label>
<p [ngClass]="{'has-error':isRegistered && formControls1['repassword'].errors}">
<input type="password" placeholder="Password" class="form-control" formControlName="repassword" autocomplete="off" spellcheck="false">
</p>
<div *ngIf="isRegistered && formControls1['repassword'].errors" class="help-block">
<div *ngIf="formControls1['repassword'].errors['required']">Password is required</div>
<div *ngIf="formControls1['repassword'].errors['pattern']">Password should have at least 1 number, one capital letter and minimum length 8</div>
<div *ngIf="formControls1['repassword'].errors['passwordValidators']">Password and confirm password is mismatch</div>
</div>
</div>
<div class="form-check mb-3">
<input type="checkbox" class="form-check-input">
<label class="form-check-label">Remember me</label>
</div>
<div class="button">
<button type="submit" (click)="addData()" class="btn btn-success">Sign Up</button>
<button type="reset" (click)="Reset()" class="btn btn-danger float-right">Reset</button>
</div>
<!--<p>
<input type="submit" value="Log in">
</p>-->
</form>
</div>
</div>
</div>
////loginregister.ts///
import { Component, OnInit } from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup, ValidatorFn, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { AuthService } from 'src/app/services/auth.service';
import { PasswordValidators } from './passwordValidators';
@Component({
selector: 'app-loginregister',
templateUrl: './loginregister.component.html',
styleUrls: ['./loginregister.component.css']
})
export class LoginregisterComponent implements OnInit {
"loginForm":FormGroup;
isSubmitted = false;
"registerForm":FormGroup;
isRegistered = false;
frm:any;
public response: any;
public reg:any;
constructor(private formBuilder: FormBuilder, public service: AuthService, public route:Router) {
this.reg = {
username: "",
password:"",
repassword:""
}
}
ngOnInit() {
this.loginForm = this.formBuilder.group({
username: ['', Validators.required],
password: ['',
[Validators.required,
Validators.pattern('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*_=+-]).{8,12}$')]]
//Validators.minLength(6)]]
});
this.registerForm = this.formBuilder.group({
username: ['', Validators.required],
password: ['',
[Validators.required,
Validators.pattern('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*_=+-]).{8,12}$')]],
repassword: ['',
[Validators.required,
Validators.pattern('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*_=+-]).{8,12}$')]]
},
{
validator:PasswordValidators("password", "repassword")
});
this.service.getData().subscribe(data=>{
this.response = data;
//console.log(this.response)
})
}
get formControls() {
return this.loginForm.controls;
}
get formControls1() {
return this.registerForm.controls;
}
login() {
console.log(this.loginForm.value);
this.isSubmitted = true;
if(this.loginForm.invalid) {
return;
}
//this.loginForm.reset();
// to navigate to other page
this.route.navigate(['/customer-home']);
}
register() {
console.log(this.registerForm.value);
this.isRegistered = true;
if(this.registerForm.invalid) {
return;
}
}
passwordMatch(){
return
}
public addData() {
//console.log(this.reg)
this.service.postData(this.registerForm.value)
.subscribe(data=> {
console.log(data)
window.alert(data)
this.refreshData()
})
}
public refreshData() {
this.service.getData().subscribe(data=>{
this.response = data;
console.log(this.response)
})
}
public getLogin() {
this.service.postLogin(this.loginForm.value)
.subscribe(data=> {
console.log(data)
})
//this.route.navigate(['/home']);
}
/*public refreshData() {
this.service.postData(this.registerForm.value).subscribe(data=>{
this.response = data;
console.log(this.response)
})
}*/
onReset():void {
this.isSubmitted=false;
this.loginForm.reset();
}
Reset():void {
this.isRegistered=false;
this.registerForm.reset();
}
}
///passwordValidators.ts////
import { AbstractControl, FormGroup } from "@angular/forms";
export function PasswordValidators(controlName: string, matchingControlName: string) {
return (formGroup: FormGroup) => {
let control = formGroup.controls[controlName];
let matchingControl = formGroup.controls[matchingControlName];
if(matchingControl.errors && !matchingControl.errors["passwordValidators"]){
return ;
}
if(control.value !== matchingControl.value) {
matchingControl.setErrors({["passwordValidators"] : true});
} else {
matchingControl.setErrors(null);
}
}
}
![]() |
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team