我正在使用 ServiceStack 中的内置授权和注册功能(a la Razor Rockstars),真的很棒!但是,我有一个奇怪的问题。每当我注册一个新用户时,我的 UserAuth 表(我正在使用 SqlServer)的第一行都会被 OVERWRITTEN 覆盖,而不是添加一个新行。奇怪的是,我的同事能够从他的机器成功注册并向表中添加新行,但从那时起,每个新注册都会覆盖表的第一行,导致很多挫败感。
我还没有定制注册服务(我还没有弄清楚如何)。在 AppHost.cs 中:
container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory(ConfigUtils.GetConnectionString("MyDatabase"),
SqlServerDialect.Provider));
...
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[] {
new CustomCredentialsAuthProvider()
}
));
Plugins.Add(new RegistrationFeature());
container.Register<IUserAuthRepository>(c =>
new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()));
var authRepo = (OrmLiteAuthRepository)container.Resolve<IUserAuthRepository>();
authRepo.CreateMissingTables();
我在 CustomCredentialsAuthProvider 中所做的非常基本:
public override bool TryAuthenticate(ServiceStack.ServiceInterface.IServiceBase authService, string userName, string password)
{
//Add here your custom auth logic (database calls etc)
//Return true if credentials are valid, otherwise false
//Call the base class if needed
return base.TryAuthenticate(authService, userName, password);
}
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
//Fill the IAuthSession with data which you want to retrieve in the app eg:
//session.FirstName = "some_firstname_from_db";
//base.OnAuthenticated(authService, session, tokens, authInfo);
//Important: You need to save the session!
authService.SaveSession(session, SessionExpiry);
}
我使用的表单代码在第一次和第二次注册时工作正常。但是,之后的每个注册都会覆盖表中的第一行:
<form action='@Url.Content("~/register")' method='POST'>
<fieldset>
<legend>Create New Account</legend>
<input type='hidden' name='Continue' value='@Url.Content("~/admin/users")' />
<dl>
<dt>User Name:</dt>
<dd><input type='text' name='UserName' /></dd>
<dt>Email:</dt>
<dd><input type='text' name='Email' /></dd>
<dt>Password:</dt>
<dd><input type='password' name='Password' /></dd>
</dl>
<input type='submit' value='Create' />
</fieldset>
</form>