* User Login * url - /login * method - POST * params - email, password */ $app->post('/login', function () use($app) { // check for required params //Utils::verifyRequiredParams(array('email', 'password')); // reading post params //$email = $app->request()->post('email'); //$password = $app->request()->post('password'); $jsonLogin = $app->request->getBody(); $objLogin = json_decode($jsonLogin, true); $response = array(); // check for correct email and password $user = UserService::checkLogin($objLogin["email"], base64_decode($objLogin["password"])); if ($user != NULL) { $response["error"] = false; $response['username'] = $user['username']; $response['email'] = $user['email']; $response['apiKey'] = $user['apiKey']; } else { // unknown error occurred $response['error'] = true; $response['message'] = "Invalid username or password. Please try again"; } Utils::echoResponse(200, $response); }); $app->get('/books', function () { // Fetch all books $books = Book::all();
require_once 'Exceptions/LoginException.php'; //require_once 'Exceptions/FalseLoginException.php'; //require_once 'Exceptions/InvalidInputException.php'; session_start(); /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ if (isset($_GET["action"]) && $_GET["action"] == "login") { if (isset($_POST["username"]) && isset($_POST["password"])) { unset($_SESSION["msg"]); unset($_SESSION["warningmsg"]); try { $userSvc = new UserService(); $service = $userSvc->checkLogin($_POST["username"], $_POST["password"]); if ($service == "access granted") { $_SESSION[redirect_arrayName()] = redirect_par(); $_SESSION["username"] = $_POST["username"]; header("location:index.php"); exit(0); } } catch (LoginException $ex) { $_SESSION["warningmsg"] = $ex->getMessage(); } } } if (isset($_GET["action"]) && $_GET["action"] == "new") { if (isset($_POST["username"]) && isset($_POST["password"]) && isset($_POST["name"]) && isset($_POST["surname"]) && isset($_POST["email"])) { unset($_SESSION["msg"]); unset($_SESSION["warningmsg"]);
<form action="<?php echo $_SERVER['PHP_SELF']; ?> " method="post"> <input type="text" name="id"> <input type="text" name="password"> <input type="submit" value="登录"> </form> <?php //error_reporting(0); require_once 'User.Service.php'; $id = $_POST['id']; $password = $_POST['password']; if (empty($id)) { exit; } //echo $id . $password; $us = new UserService(); if ($username = $us->checkLogin($id, $password)) { echo $username . '登录成功!'; //header("Location:login.php?name=$username"); //exit(); } else { header('Location:login.php?errNo=1'); exit; }
<?php session_start(); require_once 'business/userService.php'; if (isset($_GET["action"]) && $_GET["action"] == "login") { $check = UserService::checkLogin($_POST["username"], $_POST["wachtwoord"]); if ($check) { $_SESSION["aangemeld"] = true; header('location: toongeheim.php'); exit(0); } else { header('location: aanmelden.php'); exit(0); } } else { include "presentation/loginform.php"; }