2013-05-07 152 views
1

我想將驗證碼字段放入驗證提交表單api/auth/credentialsServiceStack使用驗證碼驗證驗證

所以,現在的形式將需要從用戶名密碼了rememberMe除了含有驗證碼場。

然後,我將檢查存儲驗證碼圖像的答案與提交驗證碼結果的表單的會話。

我的問題是,SS源代碼的哪些部分是否需要重寫才能正確執行?

我的感覺是,我應該看看重寫和自定義CredentialsAuthProvider類的開始?

回答

1

這裏是一個匆匆的方式來做到這一點:

public ExtDeskResponse Post(MyAuth req) { 
     //Captcha Validation 
     var valid = req.Captcha == base.Session.Get<Captcha>("Captcha").result; 
     //SS Authentication 
     var authService = AppHostBase.Instance.TryResolve<AuthService>(); 
     authService.RequestContext = new HttpRequestContext(
      System.Web.HttpContext.Current.Request.ToRequest(), 
      System.Web.HttpContext.Current.Response.ToResponse(), 
      null); 
     var auth = string.IsNullOrWhiteSpace(
      authService.Authenticate(new Auth { 
       UserName = req.UserName, 
       Password = req.Password, 
       RememberMe = req.RememberMe, 
      }).UserName); 
     if (valid && auth) { 
      //...logic 
     } 
     return new MyAuthResponse() { 
      //...data 
     }; 
    } 

期待看到你們讓我更優雅/有效的/可擴展的方式來做到這一點。