Commit 243d2906 authored by Viral Solani's avatar Viral Solani

Merge branch 'develop' of https://github.com/viralsolani/laravel-adminpanel into develop

parents f39415e0 36716b68
......@@ -43,7 +43,7 @@ class ForgotPasswordController extends APIController
return $this->respondNotFound(trans('api.messages.forgot_password.validation.email_not_found'));
}
$token = $this->repository->createNewToken();
$token = $this->repository->saveToken();
$user->notify(new UserNeedsPasswordReset($token));
......
<?php
namespace App\Http\Controllers\Api\V1;
use App\Repositories\Frontend\Access\User\UserRepository;
use Tymon\JWTAuth\JWTAuth;
use Illuminate\Support\Facades\Password;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
use Validator;
/**
* Class ResetPasswordController.
*/
class ResetPasswordController extends APIController
{
/**
* User Repository
* @var obj
*/
protected $user;
/**
* Rest Password Constructor
*
* @param UserRepository $user
*/
public function __construct(UserRepository $user)
{
$this->user = $user;
}
/**
* Reset Password
* @param Request
* @param JWTAuth
*
* @return \Illuminate\Http\JsonResponse
*/
public function reset(Request $request, JWTAuth $JWTAuth)
{
$validation = Validator::make($request->all(), [
'token' => 'required',
'email' => 'required|email',
'password' => 'required|min:4|confirmed|regex:"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$"',
]);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
dd('viral');
$response = $this->broker()->reset(
$this->credentials($request), function ($user, $password) {
$this->resetPassword($user, $password);
}
);
if($response !== Password::PASSWORD_RESET) {
throw new HttpException(500);
}
if(!Config::get('boilerplate.reset_password.release_token')) {
return response()->json([
'status' => 'ok',
]);
}
$user = User::where('email', '=', $request->get('email'))->first();
return response()->json([
'status' => 'ok',
'token' => $JWTAuth->fromUser($user)
]);
}
/**
* Get the broker to be used during password reset.
*
* @return \Illuminate\Contracts\Auth\PasswordBroker
*/
public function broker()
{
return Password::broker();
}
/**
* Get the password reset credentials from the request.
*
* @param $request
* @return array
*/
protected function credentials($request)
{
return $request->only(
'email', 'password', 'password_confirmation', 'token'
);
}
/**
* Reset the given user's password.
*
* @param \Illuminate\Contracts\Auth\CanResetPassword $user
* @param string $password
* @return void
*/
protected function resetPassword($user, $password)
{
$user->password = $password;
$user->save();
}
}
......@@ -293,7 +293,7 @@ class UserRepository extends BaseRepository
*
* @return string
*/
public function createNewToken()
public function saveToken()
{
$token = hash_hmac('sha256', Str::random(40), 'hashKey');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment