不正確的憑據我是新來的Silex,我用this tutorial建立學說ORM。的Silex:自定義UserProvider
但是現在,當我嘗試登錄時,出現「Bad credentials」錯誤。 這發生在我使用默認的「login_check」控制器時。
如果我使用一個自定義的,它的工作原理,但我不知道如何給用戶,他一直在尋找的頁面重定向。 (我試過蒙山$請求 - >包頭中> GET(在我登錄控制器「引薦」),但它是空的。)
這裏是我的自定義login_check contorller:
$app->post('/login-check-perso', function(Request $request) use ($app){
$route = $request->request->filter('route');
$password = $request->get('_password');
$username = $request->get('_email');
$userProvider = new \Lib\Provider\UserProvider($app);
$user = null;
try {
$user = $userProvider->loadUserByUsername($username);
}
catch (UsernameNotFoundException $e)
{
}
$encoder = $app['security.encoder_factory']->getEncoder($user);
// compute the encoded password
$encodedPassword = $encoder->encodePassword($password, $user->getSalt());
// compare passwords
if ($user->getPassword() == $encodedPassword)
{
// set security token into security
$token = new UsernamePasswordToken($user, $password, 'yourProviderKeyHere', array('ROLE_ADMIN'));
$app['security']->setToken($token);
// redirect or give response here
} else {
// error feedback
echo "wrong password";
die();
}
// replace url by the one the user requested while he wasn't logged in
return $app->redirect('/web/index_dev.php/admin/');
})->bind('login_check_perso');
因此,如果有人可以解釋如何使用默認的「login_check」,或向我解釋如何將用戶重定向到他正在嘗試訪問的頁面,但未登錄時,它會很棒。
感謝
編輯:
我認爲 「壞證書」 是由錯誤的編碼器設置造成的,我用this
配置礦:
$app['security.encoder.digest'] = $app->share(function ($app) {
// use the sha1 algorithm
// don't base64 encode the password
// use only 1 iteration
return new MessageDigestPasswordEncoder('sha1', false, 1);
});
$app['security.encoder_factory'] = $app->share(function ($app) {
return new EncoderFactory(
array(
'Symfony\Component\Security\Core\User\UserInterface' => $app['security.encoder.digest'],
'Entity\User' => $app['security.encoder.digest'],
)
);
});
是正確的嗎?
感謝您的回覆, 但我不知道如何讓它工作。 我不知道如何在我的自定義「login_check」控制器後調用它。 而且它從來沒有被默認的「login_check」調用,因爲我得到了「Bad credentials」錯誤。 我添加了一些信息到我的問題,也許它會有所幫助。 – OlivierG