Skip to content

Commit

Permalink
[BF] - Error 500 when changing password - fixes #679
Browse files Browse the repository at this point in the history
  • Loading branch information
yannrobin committed May 19, 2021
1 parent fef3fb0 commit 8a80950
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function updatePassword( PasswordRequest $r ): RedirectResponse
AlertContainer::push( 'Password updated successfully', Alert::SUCCESS );

// Logout all the active session except the current one
D2EM::getRepository( UserEntity::class )->deleteActiveSession( $user->getId(), false );
D2EM::getRepository( UserRememberTokenEntity::class )->deleteByUser( $user->getId(), false );

return Redirect::to( route( "profile@edit" ) );
}
Expand Down
31 changes: 31 additions & 0 deletions database/Repositories/UserRememberToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

namespace Repositories;

use Auth;
use Illuminate\Auth\Recaller;
use Illuminate\Support\Facades\Session as SessionFacade;

use Doctrine\ORM\EntityRepository;
Expand Down Expand Up @@ -71,4 +73,33 @@ public function getAllForFeList( \stdClass $feParams, int $userid, int $id = nul
return $this->getEntityManager()->createQuery( $dql )->getArrayResult();
}

/**
* Delete all the Remember token for the user
*
* @param int $userid
* @param bool $deleteCurrentToken Do we need to delete the current token
*
* @return int|mixed|string
*/
public function deleteByUser( int $userid, bool $deleteCurrentToken = false )
{
$dql = "DELETE FROM Entities\\UserRememberToken urt
WHERE urt.User = ?1";
$token = null;
// get the token of the current session
if( $recallerName = request()->cookies->get( Auth::getRecallerName() ) ) {
$recaller = new Recaller( $recallerName );
$token = $recaller->token();
}

if( !$deleteCurrentToken ){
if( $token ){
$dql .= " AND urt.token != '" . $token . "'";
} else {
$dql .= " AND urt.token IS NOT NULL";
}
}

return $this->getEntityManager()->createQuery( $dql )->setParameter(1, $userid )->execute();
}
}

0 comments on commit 8a80950

Please sign in to comment.