Beispiel #1
0
 public void Bind()
 {
     try
     {
         //string target = Request.Form["Target"];
         //if (string.IsNullOrEmpty(target))
         //    target = GetUrl("/");
         string         type   = Request.Form["Oauth2Type"];
         string         userId = Request.Form["Oauth2UserId"];
         M.RegisterType rt     = (M.RegisterType) int.Parse(Request.Form["RegisterType"]);
         M.Member       member = DbTable.Load <M.Member>(Request.Form);
         if (rt == M.RegisterType.Mobile)
         {
             if (!V.MobileHash.Equals(DataSource, member.Mobile, V.MobileHash.Register, Request.Form["Captcha"]))
             {
                 SetResult((int)M.LoginStatus.CaptchaError);
                 return;
             }
             member.VerMob = true;
         }
         string password = member.Password;
         member.ParentId     = Utility.GetReference(this, DataSource);
         member.Approved     = true;
         member.CreationDate = DateTime.Now;
         DataStatus status = M.OAuth2Member.Register(DataSource, type, userId, member, rt);
         if (status == DataStatus.Success)
         {
             M.LoginStatus state = M.OAuth2Member.Login(DataSource, type, userId, ClientIp, out member);
             if (state == M.LoginStatus.Success)
             {
                 PassportAuthentication.SetAuthCookie(true, false, member);
                 OnLogined(member.Id);
                 SetResult(true);
             }
             else
             {
                 SetResult((int)state);
             }
         }
         else
         {
             SetResult((int)status);
         }
     }
     catch (Exception)
     {
         SetResult(false);
     }
 }
Beispiel #2
0
        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);
            }
        }