Login function dose not work


#1

I want to create a basic login using providers.
Below my code.

providerlogin.ts

import { Injectable } from '@angular/core';
//import { Storage } from '@ionic/storage';
import { Http, Response } from '@angular/http';
import { Events } from 'ionic-angular';
import 'rxjs/add/operator/map';
  /*Generated class for the LoginProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class LoginProvider {
url:string;
  constructor( private http: Http) {
     this.url = "http://www.mydomain.com/demo/append/index.php/Login/";
  }

   login(data: any){
    let seq = this.http.get(this.url+data.useremail+"/"+data.password);
    seq.map((res:Response) => {});
      
    return seq;
  }
}

below my home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { MyProvider } from '../../providers/my/my';
import { LoginProvider } from '../../providers/login/login';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
useremail:string;
password:string;

  constructor(public navCtrl: NavController, public postService:MyProvider, public userService:LoginProvider) {

  }

ionViewDidLoad(){

this.postService.load();

}
userlogin(){
alert(this.useremail)
	this.userService.login(this.useremail,this.password);
}
}

HTML

<ion-header>
  <ion-navbar>
    <button ion-button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>Home</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
 <ion-item>
    <ion-label floating>Email</ion-label>
    <ion-input type="text" [(ngModel)]="useremail" required=""></ion-input>
  </ion-item>

  <ion-item>
    <ion-label floating>Password</ion-label>
    <ion-input type="password" [(ngModel)]="password" required=""></ion-input>
  </ion-item>
  
  <div padding>
      <button ion-button block (click)="userlogin();">Login</button>
  </div>

  <button ion-button color="secondary" (click)="homeredirect()">Skip</button>
</ion-content>

please help me anyone how to login function is work.


#2

it seems like nothing happens after you sent the credentials to the server.
How should this work?:eyes:
I would recommend searching for a tutorial for this topic to get a feeling for how to do it.

I would do these steps in your code:

  1. Send Credentials to the server
  2. Check the response from the Server
  3. If everything is ok store the session and redirect to the next page - or if there was an error alert the user what went wrong

#3

Actully i’m new in ionic.so please give me some tutorial link.


#4

It depends on your backend, what backend are you using? only php or with a framework? whats your code there?

weblinks: