Я новичок в веб-развертывании, я уже создал приложения angular 8 и php 7 и разместил их у себя.На локальном уровне все вызовы API работают, но после ошибок развертывания, таких как состояние 500, и даже один вызов API не работает на TLS-сервере
, здесь код:
<?php
$json = file_get_contents('php://input');
$decoded = json_decode($json);
$email = htmlspecialchars($decoded->email, ENT_QUOTES);
$pass = htmlspecialchars($decoded->password, ENT_QUOTES);
function conn()
{
$dbhost = "localhost";
$user = "root";
$pass = "";
$db = "smart";
$conn = new PDO('mysql:host=91.134.248.250;dbname=smart', $user,
$pass);
return $conn;
}
function encrypt_decrypt($action, $string)
{
$output = FALSE;
$encrypt_method = "AES-256-CBC";
$secret_key = 'WS-SERVICE-KEY';
$secret_iv = 'WS-SERVICE-VALUE';
$key = hash('sha256', $secret_key);
$iv = substr(hash('sha256', $secret_iv),
0, 16);
if($action == 'encrypt') {
$output =
base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0,
$iv));
} else {
if($action == 'decrypt') {
$output =
openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0,
$iv);
}
}
return $output;
}
if(empty($email) || empty($pass) || mb_strlen($pass) < 6 || mb_strlen($pass) > 30) {
json_encode(FALSE);
die;
} else {
$db = conn();
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$password = encrypt_decrypt('encrypt', $pass);
$res = $db->prepare("SELECT * FROM user WHERE email = ? and password = ? ");
$res->execute([$email, $password]);
$values = $res->fetchAll();
echo json_encode(sizeof($values) > 0 ? TRUE : FALSE);
}
?>
здесь код connectcter.componet.ts:
import { Component, OnInit, OnDestroy } from '@angular/core';
import { FormGroup, Validators, FormControl } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
import { User } from '../models/user.model';
import { UserService } from 'app/services/user.service';
import { Inject, Injectable } from '@angular/core';
import { AuthService } from '../services/auth.service';
import { NgxUiLoaderService } from 'ngx-ui-loader';
import { LocalStorageService } from 'ngx-localstorage';
import { Subscription } from 'rxjs/Subscription';
import { filter, map } from 'rxjs/operators';
import { AlertService } from 'ngx-alerts';
import { Router } from '@angular/router';
@Component({
selector: 'app-connecter',
templateUrl: './connecter.component.html',
styleUrls: ['./connecter.component.scss']
})
export class ConnecterComponent implements OnInit, OnDestroy {
onSubmit() {
let email = this.AuthForm.get('email').value;
let password = this.AuthForm.get('password').value;
let nomcomplet = '';
let occupation = '';
let newUser = new User(email, password, nomcomplet, occupation, '');
console.log(newUser);
this.httpSubscription = this.http.post("http://www.smartlibrairie.com/SmartLibrary/api/logins.php",
JSON.stringify(newUser)).subscribe(res => {
console.log(res);
if (res === true) {
this.ngxService.start();
setTimeout(() => {
this.ngxService.stop();
}, 3000);
if (newUser.email === "admin@gmail.com") {
this.ngxService.start();
this.authService.signIn().then(
() => {
console.log('Connexion réussite !');
this.authStatus = this.authService.isAuth;
this.ngxService.stop();
this.router.navigate(['espace-admin']);
localStorage.setItem('token', "true");
console.log(this.authStatus);
}
);
localStorage.setItem('session', newUser.email);
}else {
this.ngxService.start();
this.authService.signIn().then(
() => {
console.log('Connexion réussite !');
this.authStatus = this.authService.isAuth;
this.ngxService.stop();
this.router.navigate(['produits']);
localStorage.setItem('token', "true");
console.log(this.authStatus);
}
);
//Parse the serialized data back into an aray of objects
localStorage.setItem('session',newUser.email);
}
} else if (res === false){
this.alertService.danger('Erreur de connexion! Vérifier vos données saisies');
this.AuthForm.reset();
}
});
}
}
[! [введите описание изображения здесь] [1]] [1]
[1]: https://i.stack.imgur.com/kQqYs.png