Hello all,
First of all, am a Newbie in PHP and Slim so please be mild with me.
I tried migrating the forgot password tutorial in php authentication system from Slim 2 to Slim 3 and am stuck in loop now.
Has anyone succeeded in migrating it and if yes, can you please share or help me figure out what is wrong with my code.
I am trying to pass some arguments from my getResetPassword get method to postResetPassword post method but if I var_dump the “$args” variable in my postResetPassword post method, it gives me an empty array.
PasswordResetController.php
<?php
/**
* Created by PhpStorm.
* User: Ivan
* Date: 25/03/2017
* Time: 04:38
*/
namespace App\Controllers\Auth;
use App\Controllers\Controller;
use \App\Models\User;
class PasswordResetController extends Controller
{
public function getResetPassword($request, $response, $args)
{
$email = $request->getParam("email");
$identifier = $request->getParam("identifier");
$hashedIdentifier = $this->hash->hash($identifier);
$user = User::where("email", $email)->first();
if (!$user) {
$this->flash->addMessage("error", "User with specified reset link not found.");
return $response->withRedirect($this->router->pathFor("home"));
}
if ((!$user->recover_hash) || (!$this->hash->hashCheck($user->recover_hash, $hashedIdentifier))) {
$this->flash->addMessage("error", "There is a problem resetting your password. ensure that you copied the reset link correctly or that you have not used this link before.");
return $response->withRedirect($this->router->pathFor("home"));
}
$args = ["email" => $user->email, "identifier" => $identifier];
return $this->view->render($response, "auth/password/reset.twig", $args);
}
public function postResetPassword($request, $response, $args)
{
var_dump($args); /* unfortunately gives an empty array */
die();
$email = $request->getParam("email");
$identifier = $request->getParam("identifier");
$hashedIdentifier = $this->hash->hash($identifier);
$user = User::where("email", $email)->first();
if (!$user) {
$this->flash->addMessage("error", "User with specified reset link not found.");
return $response->withRedirect($this->router->pathFor("home"));
}
if ((!$user->recover_hash) || (!$this->hash->hashCheck($user->recover_hash, $hashedIdentifier))) {
$this->flash->addMessage("error", "There is a problem resetting your password. ensure that you copied the reset link correctly or that you have not used this link before.");
return $response->withRedirect($this->router->pathFor("home"));
}
die("all ok");
}
}
routes.php
<?php
/**
* Created by PhpStorm.
* User: Ivan
* Date: 17/03/2017
* Time: 02:03
*/
/* .......... snipped some code here */
$app->get("/auth/password/reset", "PasswordResetController:getResetPassword")->setName("auth.password.reset");
$app->post("/auth/password/reset", "PasswordResetController:postResetPassword");
reset.twig
{% extends "templates/app.twig" %}
{% block title %} Change Password {% endblock %}
{% block content %}
<section id="register">
<div class="container">
<div class="row text-center">
<div class="col-md-6 col-md-offset-3">
<div class="contact-heading">
<h2 class="title-one">Reset Password</h2>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row text-center">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-body">
<form action="{{ path_for("auth.password.reset") }}" method="post" autocomplete="off">
<div class="form-group{{ errors.new_password ? " has-error" : "" }}">
<input type="password" name="new_password" class="form-control name-field" required="required" placeholder="New Password">
{% if errors.new_password %}
<span class="help-block">{{ errors.new_password | first }}</span>
{% endif %}
</div>
<div class="form-group{{ errors.confirm_password ? " has-error" : "" }}">
<input type="password" name="confirm_password" class="form-control name-field" required="required" placeholder="Confirm Password">
{% if errors.confirm_password %}
<span class="help-block">{{ errors.confirm_password | first }}</span>
{% endif %}
</div>
<center>
<button type="submit" class="btn btn-primary">Reset password</button>
</center>
{{ csrf.field | raw }}
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
{% endblock %}
can anyone please help me.
I have stuck in this for some days now.
Thanks.