can I check the authentication at server side ...how it is possible...how 
to post the data to server side.. If there is any solution for this

On Wednesday, October 4, 2017 at 2:08:52 PM UTC+5:30, Vinu Prasad wrote:
>
> i want authenticate the users with the help of a json file . Only the 
> users with the users who have the username and password in the user.json 
> can be logged in. All others will not have the permission.
> I tried it . but it is not working ..Please help.
>
> *user.json*
> [
>   {
>      "username" : "apple",
>      "password" : "123"
>    },
>    {
>      "username" : "orange",
>      "password" : "456"
>    }
> ]
>
>
>
>
> *login.component.ts*
> import {Component} from '@angular/core';
> import {FormGroup, AbstractControl, FormBuilder, Validators} from 
> '@angular/forms';
> import { Http, Response, Headers, RequestOptions } from "@angular/http";
> import { Router } from '@angular/router';
> //import { Cookie } from 'ng2-cookies/ng2-cookies';
> @Component({
> selector: 'login',
> templateUrl: './login.html',
> styleUrls: ['./login.scss']
> })
> export class Login {
> edited: boolean;
> _router: any;
> http: any;
>
> public form:FormGroup;
> public email:AbstractControl;
> public password:AbstractControl;
> public submitted:boolean = false;
>
> constructor(fb:FormBuilder) {
> this.form = fb.group({
> 'email': ['', Validators.compose([Validators.required, Validators.
> minLength(2)])],
> 'password': ['', Validators.compose([Validators.required, Validators.
> minLength(1)])]
> });
>
> this.email = this.form.controls['email'];
> this.password = this.form.controls['password'];
> }
>
> public onSubmit(event):void {
> this.submitted = true;
> this.edited = false;
> if (this.form.valid) {
> var uname = event.email;
> var pass = event.password;
> // your code goes here
> // console.log(values);
> this.http
> .get('http://192.168.0.100:8000/user')
> .subscribe((data) => {
> setTimeout(() => {
> var userData = [];
> var passData = [];
> $.each(data.json(), function (key, value) {
> // console.log( key + ": " + value._source.UserName );
> var tempData = value.username;
> var tempdata2 = value.password;
> userData.push(tempData);
> passData.push(tempdata2);
>
> });
>
> if ((userData[0] == uname) && (passData[0] == pass)) {
> // this._router.navigate(['pages']);
> alert("ok")
> } else {
> // this._router.navigate(['login']);
> alert("fse")
> this.edited = true;
> }
> }, 1000);
> });
>
>
> }
> }
> }
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to