public static bool AutoSignOn(Func <string> getSessionCookieValue, Func <TransferSignOnInfo> getTransferSignOnInfo) { ISSOClientProvider cp = IocInstance.Container.Resolve <ISSOClientProvider>(); var sessionCookieValue = getSessionCookieValue(); if (!string.IsNullOrEmpty(sessionCookieValue)) { var encrypt = cp.GetEncryptor(); try { var decrypted = encrypt.Decrypt(sessionCookieValue); if (!string.IsNullOrEmpty(decrypted)) { IJsonSerializer js = IocInstance.Container.Resolve <IJsonSerializer>(); var session = js.Deserialize <Session>(decrypted); cp.SaveSession(session); return(true); } } catch { } } else { var transferSignOnInfo = getTransferSignOnInfo(); if (transferSignOnInfo != null) { var r = cp.TransferSignOn(transferSignOnInfo); return(r.Status == ResponseStatus.Success); } } return(false); }
public static void SignOff() { RemoveSessionCookie(); ISSOClientProvider scp = IocInstance.Container.Resolve <ISSOClientProvider>(); scp.SignOff(); }
public AccountController(ISSOClientProvider ssoClientProvider, IObjectProvider<SSOServer> serverProvider, IObjectProvider<SSOClient> clientProvider, ICaptchaGenerator captcha, IJsonSerializer jsonSerializer) { this.ssoClientProvider = ssoClientProvider; this.serverProvider = serverProvider; this.clientProvider = clientProvider; this.captcha = captcha; this.jsonSerializer = jsonSerializer; }
public AccountController(ISSOClientProvider ssoClientProvider, IObjectProvider <SSOServer> serverProvider, IObjectProvider <SSOClient> clientProvider, ICaptchaGenerator captcha, IJsonSerializer jsonSerializer) { this.ssoClientProvider = ssoClientProvider; this.serverProvider = serverProvider; this.clientProvider = clientProvider; this.captcha = captcha; this.jsonSerializer = jsonSerializer; }
public static ServerResponse SignOn(string accountOrEmailOrMobile, string password, bool rememberMe = false, string captcha = null) { ServerResponse response = new ServerResponse(); var signOnInfo = new SignOnInfo() { ClientId = CurrentClient.ClientId, SessionId = HttpContext.Current.Session.SessionID, DeviceId = HttpContext.Current.Request.UserHostAddress, DeviceInfo = HttpContext.Current.Request.UserAgent, AccountOrEmailOrMobile = accountOrEmailOrMobile, Password = password, }; bool captchaPassed = true; try { if (!string.IsNullOrEmpty(captcha)) { var captchaGenerator = IocInstance.Container.Resolve <ICaptchaGenerator>(); if (captchaGenerator.Verify(signOnInfo.SessionId, captcha) == false) { captchaPassed = false; response.Status = ResponseStatus.Failed; response.Message = DAF.SSO.Resources.Locale(o => o.CaptchaNotCorrect); } } if (captchaPassed) { ISSOClientProvider scp = IocInstance.Container.Resolve <ISSOClientProvider>(); var r = scp.SignOn(signOnInfo); if (r.Status == ResponseStatus.Success) { response.Status = ResponseStatus.Success; if (rememberMe) { SetSessionCookie(); } } else { response.Status = ResponseStatus.Failed; response.Message = r.Message; } } } catch (Exception ex) { response.Status = ResponseStatus.Exception; response.Message = ex.Message; } return(response); }
public static void SetSessionCookie() { if (IsAuthenticated && HttpContext.Current.Response != null) { SetClientCookie(); IJsonSerializer js = IocInstance.Container.Resolve <IJsonSerializer>(); ISSOConfiguration sc = IocInstance.Container.Resolve <ISSOConfiguration>(); ISSOClientProvider cp = IocInstance.Container.Resolve <ISSOClientProvider>(); var val = js.Serialize(CurrentSession); var encrypt = cp.GetEncryptor(); var encryptedVal = encrypt.Encrypt(val); HttpCookie c = new HttpCookie("sid", encryptedVal); c.Path = "/"; //c.Domain = CurrentClient.BaseUrl; c.Expires = DateTime.Now.AddMinutes(sc.SessionExpiredTimeOutMunites); HttpContext.Current.Response.Cookies.Remove("sid"); HttpContext.Current.Response.Cookies.Add(c); } }