private string UserLogin(string userName, string password) { string text = string.Empty; Hidistro.Membership.Context.Member member = Hidistro.Membership.Context.Users.GetUser(0, userName, false, true) as Hidistro.Membership.Context.Member; string result; if (member == null || member.IsAnonymous) { result = "用户名或密码错误"; } else { if (Hidistro.Membership.Context.HiContext.Current.SiteSettings.IsDistributorSettings) { if (!member.ParentUserId.HasValue || member.ParentUserId.Value != Hidistro.Membership.Context.HiContext.Current.SiteSettings.UserId) { result = "您不是本站会员,请您进行注册"; return(result); } } else { if (member.ParentUserId.HasValue && member.ParentUserId.Value != 0) { result = "您不是本站会员,请您进行注册"; return(result); } } member.Password = password; Hidistro.Membership.Core.Enums.LoginUserStatus loginUserStatus = MemberProcessor.ValidLogin(member); if (loginUserStatus == Hidistro.Membership.Core.Enums.LoginUserStatus.Success) { System.Web.HttpCookie authCookie = System.Web.Security.FormsAuthentication.GetAuthCookie(member.Username, false); Hidistro.Membership.Core.IUserCookie userCookie = member.GetUserCookie(); userCookie.WriteCookie(authCookie, 30, false); ShoppingCartInfo shoppingCart = ShoppingCartProcessor.GetShoppingCart(); CookieShoppingProvider cookieShoppingProvider = CookieShoppingProvider.Instance(); bool flag = false; if (cookieShoppingProvider.GetShoppingCart() != null && cookieShoppingProvider.GetShoppingCart().GetQuantity() > 0) { flag = true; } cookieShoppingProvider.ClearShoppingCart(); Hidistro.Membership.Context.HiContext.Current.User = member; if (shoppingCart != null && flag) { ShoppingCartProcessor.ConvertShoppingCartToDataBase(shoppingCart); } member.OnLogin(); } else { if (loginUserStatus == Hidistro.Membership.Core.Enums.LoginUserStatus.AccountPending) { text = "用户账号还没有通过审核"; } else { if (loginUserStatus == Hidistro.Membership.Core.Enums.LoginUserStatus.InvalidCredentials) { text = "用户名或密码错误"; } else { text = "未知错误"; } } } result = text; } return(result); }
private void Notify_Authenticated(object sender, AuthenticatedEventArgs e) { this.parameters.Add("CurrentOpenId", e.OpenId); Hidistro.Membership.Context.HiContext current = Hidistro.Membership.Context.HiContext.Current; string usernameWithOpenId = Hidistro.Membership.Core.UserHelper.GetUsernameWithOpenId(e.OpenId, this.openIdType); if (!string.IsNullOrEmpty(usernameWithOpenId)) { Hidistro.Membership.Context.Member member = Hidistro.Membership.Context.Users.GetUser(0, usernameWithOpenId, false, true) as Hidistro.Membership.Context.Member; if (member == null) { base.Response.Write("登录失败,信任登录只能用于会员登录。"); return; } if (Hidistro.Membership.Context.HiContext.Current.SiteSettings.IsDistributorSettings) { if (!member.ParentUserId.HasValue || member.ParentUserId.Value != Hidistro.Membership.Context.HiContext.Current.SiteSettings.UserId) { base.Response.Write("账号已经与本平台的其它子站绑定,不能在此域名上登录。"); return; } } else { if (member.ParentUserId.HasValue && member.ParentUserId.Value != 0) { base.Response.Write("账号已经与本平台的其它子站绑定,不能在此域名上登录。"); return; } } System.Web.HttpCookie authCookie = System.Web.Security.FormsAuthentication.GetAuthCookie(member.Username, false); Hidistro.Membership.Core.IUserCookie userCookie = member.GetUserCookie(); userCookie.WriteCookie(authCookie, 30, false); Hidistro.Membership.Context.HiContext.Current.User = member; ShoppingCartInfo shoppingCart = ShoppingCartProcessor.GetShoppingCart(); CookieShoppingProvider cookieShoppingProvider = CookieShoppingProvider.Instance(); cookieShoppingProvider.ClearShoppingCart(); current.User = member; bool flag = false; if (cookieShoppingProvider.GetShoppingCart() != null && cookieShoppingProvider.GetShoppingCart().GetQuantity() > 0) { flag = true; cookieShoppingProvider.ClearShoppingCart(); } if (shoppingCart != null && flag) { ShoppingCartProcessor.ConvertShoppingCartToDataBase(shoppingCart); } if (!string.IsNullOrEmpty(this.parameters["token"])) { System.Web.HttpCookie httpCookie = new System.Web.HttpCookie("Token_" + Hidistro.Membership.Context.HiContext.Current.User.UserId.ToString()); httpCookie.Expires = System.DateTime.Now.AddMinutes(30.0); httpCookie.Value = this.parameters["token"]; System.Web.HttpContext.Current.Response.Cookies.Add(httpCookie); } } else { string a; if ((a = this.openIdType.ToLower()) != null) { if (a == "hishop.plugins.openid.alipay.alipayservice") { this.SkipAlipayOpenId(); goto IL_288; } if (a == "hishop.plugins.openid.qq.qqservice") { this.SkipQQOpenId(); goto IL_288; } if (a == "hishop.plugins.openid.taobao.taobaoservice") { this.SkipTaoBaoOpenId(); goto IL_288; } if (a == "hishop.plugins.openid.sina.sinaservice") { this.SkipSinaOpenId(); goto IL_288; } } this.Page.Response.Redirect(Globals.GetSiteUrls().Home); } IL_288: string a2 = this.parameters["HITO"]; if (a2 == "1") { this.Page.Response.Redirect(Globals.GetSiteUrls().UrlData.FormatUrl("submitOrder")); return; } this.Page.Response.Redirect(Globals.GetSiteUrls().Home); }
private void btnRegister_Click(object sender, System.EventArgs e) { if (!this.chkAgree.Checked) { this.ShowMessage("您必须先阅读并同意注册协议", false); } else { if (string.Compare(this.txtUserName.Text.Trim().ToLower(System.Globalization.CultureInfo.InvariantCulture), "anonymous", false, System.Globalization.CultureInfo.InvariantCulture) == 0) { this.ShowMessage("已经存在相同的用户名", false); } else { if (this.txtUserName.Text.Trim().Length < 2 || this.txtUserName.Text.Trim().Length > 20) { this.ShowMessage("用户名不能为空,且在2-20个字符之间", false); } else { if (string.Compare(this.txtPassword.Text, this.txtPassword2.Text) != 0) { this.ShowMessage("两次输入的密码不相同", false); } else { if (this.txtPassword.Text.Length == 0) { this.ShowMessage("密码不能为空", false); } else { if (this.txtPassword.Text.Length < System.Web.Security.Membership.Provider.MinRequiredPasswordLength || this.txtPassword.Text.Length > HiConfiguration.GetConfig().PasswordMaxLength) { this.ShowMessage(string.Format("密码的长度只能在{0}和{1}个字符之间", System.Web.Security.Membership.Provider.MinRequiredPasswordLength, HiConfiguration.GetConfig().PasswordMaxLength), false); } else { Hidistro.Membership.Context.Member member; if (Hidistro.Membership.Context.HiContext.Current.SiteSettings.IsDistributorSettings) { member = new Hidistro.Membership.Context.Member(Hidistro.Membership.Core.Enums.UserRole.Underling); member.ParentUserId = Hidistro.Membership.Context.HiContext.Current.SiteSettings.UserId; } else { member = new Hidistro.Membership.Context.Member(Hidistro.Membership.Core.Enums.UserRole.Member); } if (Hidistro.Membership.Context.HiContext.Current.ReferralUserId > 0) { member.ReferralUserId = new int?(Hidistro.Membership.Context.HiContext.Current.ReferralUserId); } member.GradeId = MemberProcessor.GetDefaultMemberGrade(); member.Username = Globals.HtmlEncode(this.txtUserName.Text.Trim()); member.Email = this.txtEmail.Text; member.Password = this.txtPassword.Text; member.PasswordFormat = System.Web.Security.MembershipPasswordFormat.Hashed; member.TradePasswordFormat = System.Web.Security.MembershipPasswordFormat.Hashed; member.TradePassword = this.txtPassword.Text; if (this.txtCellPhone != null) { member.CellPhone = this.txtCellPhone.Text; } member.IsApproved = true; member.RealName = string.Empty; member.Address = string.Empty; if (this.ValidationMember(member)) { if (!Hidistro.Membership.Context.HiContext.Current.CheckVerifyCode(this.txtNumber.Text)) { this.ShowMessage("验证码输入错误", false); } else { switch (MemberProcessor.CreateMember(member)) { case Hidistro.Membership.Core.Enums.CreateUserStatus.UnknownFailure: this.ShowMessage("未知错误", false); break; case Hidistro.Membership.Core.Enums.CreateUserStatus.Created: { Messenger.UserRegister(member, this.txtPassword.Text); member.OnRegister(new Hidistro.Membership.Context.UserEventArgs(member.Username, this.txtPassword.Text, null)); Hidistro.Membership.Core.IUser user = Hidistro.Membership.Context.Users.GetUser(0, member.Username, false, true); ShoppingCartInfo shoppingCart = ShoppingCartProcessor.GetShoppingCart(); CookieShoppingProvider cookieShoppingProvider = CookieShoppingProvider.Instance(); cookieShoppingProvider.ClearShoppingCart(); Hidistro.Membership.Context.HiContext.Current.User = user; if (shoppingCart != null) { ShoppingCartProcessor.ConvertShoppingCartToDataBase(shoppingCart); } System.Web.HttpCookie authCookie = System.Web.Security.FormsAuthentication.GetAuthCookie(member.Username, false); Hidistro.Membership.Core.IUserCookie userCookie = user.GetUserCookie(); userCookie.WriteCookie(authCookie, 30, false); this.Page.Response.Redirect(Globals.GetSiteUrls().UrlData.FormatUrl("registerUserSave") + "?UserId=" + user.UserId); break; } case Hidistro.Membership.Core.Enums.CreateUserStatus.DuplicateUsername: this.ShowMessage("已经存在相同的用户名", false); break; case Hidistro.Membership.Core.Enums.CreateUserStatus.DuplicateEmailAddress: this.ShowMessage("电子邮件地址已经存在", false); break; case Hidistro.Membership.Core.Enums.CreateUserStatus.DisallowedUsername: this.ShowMessage("用户名禁止注册", false); break; case Hidistro.Membership.Core.Enums.CreateUserStatus.InvalidPassword: this.ShowMessage("无效的密码", false); break; case Hidistro.Membership.Core.Enums.CreateUserStatus.InvalidEmail: this.ShowMessage("无效的电子邮件地址", false); break; } } } } } } } } } }
protected void SkipSinaOpenId() { Hidistro.Membership.Context.Member member; if (Hidistro.Membership.Context.HiContext.Current.SiteSettings.IsDistributorSettings) { member = new Hidistro.Membership.Context.Member(Hidistro.Membership.Core.Enums.UserRole.Underling); member.ParentUserId = Hidistro.Membership.Context.HiContext.Current.SiteSettings.UserId; } else { member = new Hidistro.Membership.Context.Member(Hidistro.Membership.Core.Enums.UserRole.Member); } if (Hidistro.Membership.Context.HiContext.Current.ReferralUserId > 0) { member.ReferralUserId = new int?(Hidistro.Membership.Context.HiContext.Current.ReferralUserId); } member.GradeId = MemberProcessor.GetDefaultMemberGrade(); member.Username = this.parameters["CurrentOpenId"]; if (string.IsNullOrEmpty(member.Username)) { member.Username = "******" + this.GenerateUsername(8); } member.Email = this.GenerateUsername() + "@localhost.com"; string text = this.GeneratePassword(); member.Password = text; member.PasswordFormat = System.Web.Security.MembershipPasswordFormat.Hashed; member.TradePasswordFormat = System.Web.Security.MembershipPasswordFormat.Hashed; member.TradePassword = text; member.IsApproved = true; member.RealName = string.Empty; member.Address = string.Empty; if (MemberProcessor.CreateMember(member) != Hidistro.Membership.Core.Enums.CreateUserStatus.Created) { member.Username = "******" + this.GenerateUsername(9); member.Password = (member.TradePassword = text); if (MemberProcessor.CreateMember(member) != Hidistro.Membership.Core.Enums.CreateUserStatus.Created) { member.Username = this.GenerateUsername(); member.Email = this.GenerateUsername() + "@localhost.com"; member.Password = (member.TradePassword = text); if (MemberProcessor.CreateMember(member) != Hidistro.Membership.Core.Enums.CreateUserStatus.Created) { base.Response.Write("为您创建随机账户时失败,请重试。"); return; } } } Hidistro.Membership.Core.UserHelper.BindOpenId(member.Username, this.parameters["CurrentOpenId"], this.parameters["HIGW"]); System.Web.HttpCookie authCookie = System.Web.Security.FormsAuthentication.GetAuthCookie(member.Username, false); Hidistro.Membership.Core.IUserCookie userCookie = member.GetUserCookie(); userCookie.WriteCookie(authCookie, 30, false); ShoppingCartInfo shoppingCart = ShoppingCartProcessor.GetShoppingCart(); CookieShoppingProvider cookieShoppingProvider = CookieShoppingProvider.Instance(); cookieShoppingProvider.ClearShoppingCart(); Hidistro.Membership.Context.HiContext.Current.User = member; if (shoppingCart != null) { ShoppingCartProcessor.ConvertShoppingCartToDataBase(shoppingCart); } if (!string.IsNullOrEmpty(this.parameters["token"])) { System.Web.HttpCookie httpCookie = new System.Web.HttpCookie("Token_" + Hidistro.Membership.Context.HiContext.Current.User.UserId.ToString()); httpCookie.Expires = System.DateTime.Now.AddMinutes(30.0); httpCookie.Value = this.parameters["token"]; System.Web.HttpContext.Current.Response.Cookies.Add(httpCookie); } this.Page.Response.Redirect(Globals.GetSiteUrls().Home); }