我已经像这样覆盖了 CredentialsAuthProvider:
public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
{
//TODO: Auth the user and return if valid login
return true;
}
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
base.OnAuthenticated(authService, session, tokens, authInfo);
//User has been authenticated
//Find the user's role form the DB
if (roleA)
//GOTO mypage1
if (roleB)
//GOTO mypage2
}
我向 ~/auth/Credentials 执行了一个简单的帖子,当身份验证工作并调用 OnAuthenticated 方法时,我如何根据角色或类似的东西实际将用户重定向到适当的页面?
我厌倦了在 OnAuthenticated 方法中执行以下操作,但没有达到预期的效果:
authService.("/views/customers");
使用 Starter Template 更新(见下面的评论):
public class CustomCredentialsAuthProvider : CredentialsAuthProvider
{
public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
{
return true;
}
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
session.ReferrerUrl = "http://www.msn.com";
base.OnAuthenticated(authService, session, tokens, authInfo);
}
}
以及要发布的表格:
<form method="POST" action="/auth/credentials">
<input name="UserName"/>
<input name="Password" type="password"/>
<input type="submit"/>
</form>