Servicestack添加字段UserAuth表并检查登录

时间:2015-03-16 18:49:21

标签: authentication servicestack ormlite-servicestack

我想在UserAuth表上添加新字段(例如:已阻止,已验证),我想在登录时进行检查。我怎么能这样做?我没有找到任何关于自定义身份验证的教程..

谢谢..

1 个答案:

答案 0 :(得分:1)

最后,我找到了项目的其他解决方案......

1)添加插件SessionFeaute:

this.Plugins.Add(new SessionFeature() { SessionExpiry = TimeSpan.FromMinutes(15) });

2)注册ICacheClient:

  container.Register<ICacheClient>(new MemoryCacheClient());

3)验证方法:

  public void Authenticate(ISession session , User user)
    {
        session.Set("UserInfo",user);
    }

4)退出方法:session.GetSessionBag().Set<User>("UserInfo",null);

5)RequestFilter:

public class UserInfoFilterAttribute : RequestFilterAttribute
{
    public UserInfoFilterAttribute() { }
    public UserInfoFilterAttribute(ApplyTo applyTo) : base(applyTo) { }
    public override void Execute(IRequest req, IResponse res, object requestDto)
    {
            var user = req.GetSessionBag().Get<User>("UserInfo");
            if (user == null)
            {
              res.StatusCode = (int)HttpStatusCode.Unauthorized;
              res.EndRequest();
            }
    }
}

6)最后使用过滤器进行受限服务。

  [UserInfoFilterAttribute]
public class AccountInfoService : ServiceStack.Service
{

}

非常感谢...