Je sais que cette question a déjà été posée ici. (Veuillez cliquer sur le lien avant de voter pour le fermer sous la balise en double.) Mais aucune des solutions n'a fonctionné pour moi.

Je peux accéder à / sans aucune erreur. Mais lorsque j'essaie d'utiliser une demande d'obtention pour me connecter, j'obtiens cette erreur:

NotFoundHttpException
in RoutesRequests.php (line 594)
at Application->handleDispatcherResponse(array(0))
in RoutesRequests.php (line 532)
at Application->Laravel\Lumen\Concerns\{closure}()
in RoutesRequests.php (line 781)
at Application->sendThroughPipeline(array(), object(Closure))
in RoutesRequests.php (line 534)
at Application->dispatch(null)
in RoutesRequests.php (line 475)
at Application->run()
in index.php (line 28)

index.php (line 28) pointe vers $app->run();

Voici mon code pour la page du formulaire de connexion:

<!DOCTYPE html>
<html>
    <head>
    <title>notes!</title>
    <!-- <link rel="stylesheet" type="text/css" href="{{ url('../assets/css/main.css') }}"> -->
    <style>
            body {
            background-color: #ffffff;
        }

        .banner {
            margin: 100px auto;
            text-align: center;
            vertical-align: middle;
            font-family: 'Open Sans', sans-serif;
            font-size: 30px;
            color: #333333;
        }

        .loginContainer {
            width:30%;
            margin: 50px auto;
            vertical-align: middle;
            background-color: #333333;
            border:2px;
            border-radius:10px;
        }

        form {
            margin: 0 auto;
            padding: 50px;
        }

        form input {
            display: block;
            width: 300px;
            margin: 0 auto;
            margin-top: 5px;
            padding: 5px;
            font-size: 30px;
        }

        form button {
            display: block;
            width: 314px;
            margin: 0 auto;
            margin-top: 5px;
            padding: 5px;
            border-radius: 5px;
            border: none;
            background-color: #3366ff;
            color: #ffffff;
            font-size: 30px;
        }
    </style>
    <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
    </head>
    <body>
    <!-- <div class="navbar">
         <ul>
         <li>Login</li>
         <li>About Me!</li>
         </ul>
         </div> -->
    <div class="banner">
        <h1>Welcome to notes!</h1>
        <h4>Add notes, to-do lists and more!</h4>
    </div>
    <div class="loginContainer">
        <form class="signin" method="get" action="/login/">
        <input type="email" id="inputEmail" placeholder="Email" required="" autofocus="">
        <input type="password" id="inputPassword" placeholder="Password" required="">
        <button type="submit">Sign in</button>
        </form>
    </div>
    </body>
</html>

Voici le code pour routes.php:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$app->get('/', function () use ($app) {
    return view('welcome');
});

$app->get('login/','UsersController@authenticate');
$app->post('todo/','TodoController@store');
$app->get('todo/', 'TodoController@index');
$app->get('todo/{id}/', 'TodoController@show');
$app->put('todo/{id}/', 'TodoController@update');
$app->delete('todo/{id}/', 'TodoController@destroy');

?>

Voici le fichier UsersController.php:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\Hash;

use Illuminate\Http\Request;

use App\Users;

class UsersController extends Controller

{

  public function __construct()

   {

//        $this->middleware('auth:api');

   }

   /**
    * Display a listing of the resource.
    *
    * @return \Illuminate\Http\Response
    */

   public function authenticate(Request $request)

   {

       $this->validate($request, [

       'email' => 'required',

       'password' => 'required'

        ]);

      $user = Users::where('email', $request->input('email'))->first();

     if(Hash::check($request->input('password'), $user->password)){

          $apikey = base64_encode(str_random(40));

          Users::where('email', $request->input('email'))->update(['api_key' => "$apikey"]);;

          return response()->json(['status' => 'success','api_key' => $apikey]);

      }else{

          return response()->json(['status' => 'fail'],401);

      }

   }

}    

?>
0
Flame of udun 25 juil. 2017 à 02:26

2 réponses

Meilleure réponse

Le premier argument de l'itinéraire est coupé avec '/'

Correction de l'action du formulaire: / login / -> / login

<form class="signin" method="get" action="/login">
3
mokamoto12 27 juil. 2017 à 02:11

Je pense que vous .htaccess fichier manquant, ajoutez le fichier. htaccess dans le répertoire public et attribuez l'autorisation de lecture à apache:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
-1
Govind Samrow 27 juil. 2017 à 04:47