public static Credential Login(IAuthentication authentication, ICredentialProvider credentialProvider, string identity, string password, string @namespace, bool isRemember, out string redirectUrl) { if (authentication == null) { throw new ArgumentNullException("authentication"); } if (credentialProvider == null) { throw new ArgumentNullException("credentialProvider"); } //进行身份验证(即验证身份标识和密码是否匹配) var result = authentication.Authenticate(identity, password, @namespace); //注册用户凭证 var credential = credentialProvider.Register(result.User, AuthenticationUtility.GetScene(), (result.HasParameters ? result.Parameters : null)); //将注册成功的用户凭证保存到Cookie中 AuthenticationUtility.SetCredentialCookie(credential, isRemember ? TimeSpan.FromDays(7) : TimeSpan.Zero); object redirectObject = null; //如果验证事件中显式指定了返回的URL,则使用它所指定的值 if (result.HasParameters && result.Parameters.TryGetValue("RedirectUrl", out redirectObject) && redirectObject != null) { redirectUrl = redirectObject.ToString(); } else //返回重定向的路径中 { redirectUrl = AuthenticationUtility.GetRedirectUrl(credential.Scene); } return(credential); }
public static Credential Login(IAuthenticator authenticator, ICredentialProvider credentialProvider, string identity, string password, string @namespace, bool isRemember, out string redirectUrl) { if (authenticator == null) { throw new ArgumentNullException(nameof(authenticator)); } if (credentialProvider == null) { throw new ArgumentNullException(nameof(credentialProvider)); } System.Collections.Generic.IDictionary <string, object> parameters = new System.Collections.Generic.Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); //进行身份验证(即验证身份标识和密码是否匹配) var user = authenticator.Authenticate(identity, password, @namespace, null, ref parameters); //构建用户凭证 var credential = new Credential(user, AuthenticationUtility.GetScene(), TimeSpan.FromHours(2), parameters); //注册用户凭证 credentialProvider.Register(credential); //将注册成功的用户凭证保存到Cookie中 AuthenticationUtility.SetCredentialCookie(credential, isRemember ? TimeSpan.FromDays(7) : TimeSpan.Zero); object redirectObject = null; //如果验证事件中显式指定了返回的URL,则使用它所指定的值 if (parameters != null && parameters.TryGetValue("RedirectUrl", out redirectObject) && redirectObject != null) { redirectUrl = redirectObject.ToString(); } else //返回重定向的路径中 { redirectUrl = AuthenticationUtility.GetRedirectUrl(credential.Scene); } return(credential); }