问题
Why am i getting this incorrect entry pop up but my php file executes login successfully. its confusing where file should i edit is it the ts file or the php file i need some eyes and brains to fix this code I've provided i need you guys. I hope you guys takes time to help everyone especially those who don't have much knowledge of ionic3 as this framework don't have much resources to learn it deeply thankyou for your future answers.
login.html
<ion-list style="padding: 50px">
<ion-item>
<ion-label floating>Username</ion-label>
<ion-input name="username" #username></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Password</ion-label>
<ion-input type="password" name="userpass" #userpass></ion-input>
</ion-item>
<div style="padding-top: 50px ">
<button ion-button block (click)="signIn()">Sign In</button>
<button ion-button outline block (click)="RegisterPage()">Register</button>
</div>
</ion-list>
login.ts
import { Component, ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
import { Http, Headers, RequestOptions } from "@angular/http";
import { LoadingController } from 'ionic-angular';
import 'rxjs/add/operator/map';
import { RegisterPage } from '../register/register';
import { TabsPage } from '../tabs/tabs';
import { HomePage } from '../home/home';
@IonicPage()
@Component({
selector: 'page-login',
templateUrl: 'login.html',
})
export class LoginPage {
@ViewChild("username") username;
@ViewChild("userpass") userpass;
data: string;
items: any;
constructor(public navCtrl: NavController,
public navParams: NavParams,
public alertCtrl: AlertController,
private http: Http,
public loading: LoadingController
)
{
}
RegisterPage() {
this.navCtrl.push(RegisterPage)
}
signIn() {
//// check to confirm the username and userpass fields are filled
if (this.username.value == "") {
let alert = this.alertCtrl.create({
title: "ATTENTION",
subTitle: "Username field is empty",
buttons: ['OK']
});
alert.present();
} else
if (this.userpass.value == "") {
let alert = this.alertCtrl.create({
title: "ATTENTION",
subTitle: "Password field is empty",
buttons: ['OK']
});
alert.present();
} else {
var headers = new Headers();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'application/json');
let options = new RequestOptions({
headers: headers
});
let data = {
username: this.username.value,
userpass: this.userpass.value
};
let loader = this.loading.create({
content: 'Processing please wait...',
});
loader.present().then(() => {
this.http.post('http://localhost/8990API/login.php', data, options)
.map(res => res.json())
.subscribe(res => {
console.log(res)
loader.dismiss()
if (res.status == "Login successfully") {
let alert = this.alertCtrl.create({
title: "CONGRATS",
subTitle: (res.message),
buttons: ['OK']
});
alert.present();
this.navCtrl.push(HomePage, data);
this.navCtrl.push(TabsPage);
}
else {
let alert = this.alertCtrl.create({
title: "Incorrect entry please try again.",
subTitle: (res.message),
buttons: ['OK']
});
alert.present();
}
});
});
}
}
}
login.php
<?php
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
}
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
}
exit(0);
}
require "dbconnect.php";
$data = file_get_contents('php://input');
if (isset($data)) {
$request = json_decode($data,true);
if (!empty($request) && isset($request['username'], $request['userpass'])) {
$username = $request['username'] ?? '';
$userpass = $request['userpass'] ?? '';
$userpass = sha1($userpass."@la]#}^(dy*%-Ga=/,Ga!.");
$sql = "SELECT * FROM useraccount WHERE username = '$username' and userpass = '$userpass'";
$result = mysqli_query($con, $sql);
if ($result && ($count = mysqli_num_rows($result)) > 0) {
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
// $active = $row['active'];
$status = "success";
$message = "Login successfully";
}
else {
$status = "fail";
$message = "Your Login Username or Password is invalid";
}
}
else {
$status = "fail";
$message = "You must specify a Username and Password";
}
}
else {
$status = "fail";
$message = "You must specify a Username and Password";
}
echo json_encode(array('status' => $status, 'message' => $message, 'data' => $data));
?>
来源:https://stackoverflow.com/questions/58254494/why-am-i-getting-this-incorrect-entry-pop-up-but-my-php-file-executes-login-succ