//public Member GetMember(DataSource ds) //{ // MemberId = ExecuteScalar<OAuth2Member, int>(ds, "MemberId", P("Type", Type) & P("UserId", UserId)); // if (MemberId > 0) // return Member.GetById(ds, MemberId); // return null; //} //public DataStatus BindMember(DataSource ds, long memberId) //{ // MemberId = memberId; // return Update(ds, ColumnMode.Include, "MemberId"); //} //public Member BindMember(DataSource ds, string memberName) //{ // Member member = Member.GetByName(ds, memberName); // if (member != null) // { // if (BindMember(ds, member.Id) == DataStatus.Success) // return member; // } // return null; //} public static DataStatus Register(DataSource ds, string type, string userId, Member member, RegisterType rt) { if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(userId)) { ds.Begin(); try { Member temp = Member.GetByType(ds, member, rt); if (temp == null) { DataStatus status = member.Insert(ds); if (status != DataStatus.Success) { ds.Commit(); return(status); } else { temp = member; } } else { if (rt != RegisterType.Mobile && !string.Equals(temp.Password, member.Password.MD5())) { ds.Commit(); return(DataStatus.Exist); } } OAuth2Member user = new OAuth2Member() { Type = type, UserId = userId, MemberId = temp.Id }; if (user.Update(ds, ColumnMode.Include, "MemberId") != DataStatus.Success) { if (user.Insert(ds) != DataStatus.Success) { throw new Exception(); } } ds.Commit(); return(DataStatus.Success); } catch (Exception) { ds.Rollback(); return(DataStatus.Failed); } } else { return(DataStatus.ExistOther); } }
public void Submit() { try { M.RegisterType type = (M.RegisterType) int.Parse(Request.Form["RegisterType"]); PassportSection section = PassportSection.GetSection(); M.Member member = DbTable.Load <M.Member>(Request.Form); if (type == M.RegisterType.Mobile) { if (section.VerifyMobile) { if (!V.MobileHash.Equals(DataSource, member.Mobile, V.MobileHash.Register, Request.Form["SmsCaptcha"])) { SetResult((int)M.LoginStatus.SmsCaptchaError); return; } member.VerMob = true; } } if (!IsWap) { if (section.RegisterWithCaptcha) { if (!Captcha.CheckCaptcha(Request.Form["CaptchaName"], Request.Form["Captcha"])) { SetResult((int)M.LoginStatus.CaptchaError); return; } } } string password = member.Password; if (member.ParentId == 0) { bool convertResult = long.TryParse(Request.QueryString["ParentId"], out member.ParentId); if (!convertResult) { member.ParentId = Utility.GetReference(this, DataSource); } } member.Approved = section.DefaultApproved; member.CreationDate = DateTime.Now; DataStatus status = member.Insert(DataSource); if (status == DataStatus.Success) { int errCount; string name; switch (type) { case M.RegisterType.Email: name = member.Email; break; case M.RegisterType.Mobile: name = member.Mobile.ToString(); break; default: name = member.Name; break; } M.LoginStatus state = M.Member.Login(DataSource, name, password, ClientIp, out errCount, out member); if (state == M.LoginStatus.Success) { Web.PassportAuthentication.SetAuthCookie(true, false, member); } SetResult((int)state); } else { SetResult((int)status); } } catch (Exception) { SetResult(false); } }