Beispiel #1
0
        /// <summary>
        /// 第三方登录回调
        /// </summary>
        /// <param name="identify">第三方标识</param>
        /// <param name="collection">回调参数</param>
        /// <returns></returns>
        public PartnerBackResult LoginBack(string identify, NameValueCollection collection)
        {
            PartnerBackContext context = new PartnerBackContext();

            context.PartnerIdentify = identify;
            context.ResponseParam   = collection;

            Partners partner = Partners.GetInstance(context);

            if (!partner.BackVerifySign(context))
            {
                Logger.WriteLog(string.Format("第三方登录回调非法请求,第三方标识:{0}", identify), "Passport", "LoginBack");
                throw new BusinessException("登录失败!");
            }

            CustomerInfo customer = null;

            if (context.ActionType == PassportActionType.Accept)
            {
                partner.GetResponseUserInfo(context);

                customer = new CustomerInfo()
                {
                    CustomerID    = context.CustomerID,
                    CustomerName  = context.CustomerName,
                    CustomersType = (int)context.CustomerSouce,
                    InitRank      = 1,
                    Password      = "",
                    CellPhone     = context.CellPhone,
                    Email         = context.Email
                };

                var existsCustomer = CustomerFacade.GetCustomerByID(context.CustomerID);
                if (existsCustomer == null)
                {
                    int customerSysNo = LoginFacade.CreateCustomer(customer).SysNo;
                    if (customerSysNo <= 0)
                    {
                        Logger.WriteLog(string.Format("第三方登录回调注册用户失败,第三方标识:{0}", identify), "Passport", "LoginBack");
                        throw new BusinessException("第三方登录注册用户失败!");
                    }
                    customer.SysNo = customerSysNo;
                }
                else
                {
                    customer.SysNo = existsCustomer.SysNo;
                }
            }
            PartnerBackResult result = new PartnerBackResult()
            {
                Customer   = customer,
                ReturnUrl  = context.ReturnUrl,
                ActionType = context.ActionType
            };

            return(result);
        }
Beispiel #2
0
        public ActionResult AjaxRegister()
        {
            var model = new RegisterVM();

            this.TryUpdateModel <RegisterVM>(model);
            var result = new AjaxResult
            {
                Success = false
            };

            //判断此CustomerID是否被注册过
            if (LoginFacade.IsExistCustomer(model.CustomerID))
            {
                result.Message = "该账户名已经被注册";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }

            if (model.Password != model.RePassword)
            {
                result.Message = "密码与确认密码不相同";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }

            model.Password = HttpUtility.UrlDecode(model.Password.Replace("+", "%2b"));

            CustomerInfo item = EntityConverter <RegisterVM, CustomerInfo> .Convert(model);

            item.InitRank     = 1;
            item.CustomerName = item.CustomerID;

            //密码处理
            string encryptPassword = string.Empty;
            string password        = item.Password;
            string passwordSalt    = string.Empty;

            PasswordHelper.GetNewPasswordAndSalt(ref password, ref encryptPassword, ref passwordSalt);
            item.Password     = encryptPassword;
            item.PasswordSalt = passwordSalt;

            if (LoginFacade.CreateCustomer(item).SysNo > 0)
            {
                LoginUser lUser = new LoginUser();
                lUser.UserDisplayName = item.CustomerName;
                lUser.UserID          = item.CustomerID;
                lUser.UserSysNo       = item.SysNo;
                lUser.RememberLogin   = false;
                lUser.LoginDateText   = DateTime.Now.ToString();
                lUser.TimeoutText     = DateTime.Now.AddMinutes(int.Parse(ConfigurationManager.AppSettings["LoginTimeout"].ToString())).ToString();

                CookieHelper.SaveCookie <LoginUser>("LoginCookie", lUser);
                result.Success = true;
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            result.Message = "用户注册失败,请稍后重试";
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public ActionResult AjaxRegister()
        {
            var model = new RegisterVM();

            this.TryUpdateModel <RegisterVM>(model);
            //if (CookieHelper.GetCookie<String>("VerifyCode").ToLower() == model.ValidatedCode.ToLower())
            //{
            if (model.Password != model.RePassword)
            {
                return(Json("密码与确认密码不相同", JsonRequestBehavior.AllowGet));
            }

            model.Password = HttpUtility.UrlDecode(model.Password.Replace("+", "%2b"));

            CustomerInfo item = EntityConverter <RegisterVM, CustomerInfo> .Convert(model);

            item.InitRank     = 1;
            item.CustomerName = item.CustomerID;
            //if (!CheckPasswordPolicy(item.Password))
            //    return Json("密码格式不正确,密码必须是字母与数据的组合", JsonRequestBehavior.AllowGet);

            if (LoginFacade.IsExistCustomer(item.CustomerID))
            {
                return(Json(new JsonResult()
                {
                    ContentType = "f", Data = "该账户名已经被注册"
                }, JsonRequestBehavior.AllowGet));
            }
            if (LoginFacade.IsCustomerEmailExist(item.Email))
            {
                return(Json(new JsonResult()
                {
                    ContentType = "f", Data = "该邮箱已经被注册"
                }, JsonRequestBehavior.AllowGet));
            }

            //密码处理
            string encryptPassword = string.Empty;
            string password        = item.Password;
            string passwordSalt    = string.Empty;

            PasswordHelper.GetNewPasswordAndSalt(ref password, ref encryptPassword, ref passwordSalt);
            item.Password     = encryptPassword;
            item.PasswordSalt = passwordSalt;

            if (LoginFacade.CreateCustomer(item).SysNo > 0)
            {
                LoginUser lUser = new LoginUser();
                lUser.UserDisplayName = item.CustomerName;
                lUser.UserID          = item.CustomerID;
                lUser.UserSysNo       = item.SysNo;
                lUser.RememberLogin   = false;
                lUser.LoginDateText   = DateTime.Now.ToString();
                lUser.TimeoutText     = DateTime.Now.AddMinutes(int.Parse(ConfigurationManager.AppSettings["LoginTimeout"].ToString())).ToString();

                CookieHelper.SaveCookie <LoginUser>("LoginCookie", lUser);

                //更新数据

                bool result = CustomerFacade.UpdateCellPhoneCustomerSysNoByID(int.Parse(model.CellPhoneCode), lUser.UserSysNo);
                return(Json(new JsonResult()
                {
                    ContentType = "s", Data = lUser.UserSysNo
                }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new JsonResult()
            {
                ContentType = "f", Data = "用户注册失败,请稍后重试"
            }, JsonRequestBehavior.AllowGet));
            //}
            //return Json(new JsonResult() { ContentType = "y", Data = "验证码不正确" }, JsonRequestBehavior.AllowGet);
        }
Beispiel #4
0
        public static CustomerInfoViewModel CustomerRegister(CustomerRegisterRequestViewModel request)
        {
            if (string.IsNullOrEmpty(request.CustomerID))
            {
                throw new BusinessException("登录账号不能为空!");
            }
            else if (string.IsNullOrEmpty(request.Password))
            {
                throw new BusinessException("登录密码不能为空!");
            }
            else if (string.IsNullOrEmpty(request.RePassword))
            {
                throw new BusinessException("确认登录密码不能为空!");
            }
            else if (request.Password != request.RePassword)
            {
                throw new BusinessException("密码与确认密码不相同!");
            }
            else if (string.IsNullOrEmpty(request.CellPhone))
            {
                throw new BusinessException("手机号码不能为空!");
            }
            //else if (string.IsNullOrEmpty(request.Email))
            //{
            //    throw new BusinessException("电子邮箱不能为空!");
            //}
            string errorMsg;

            if (!CustomerManager.CheckPasswordFormat(request.Password, out errorMsg))
            {
                throw new BusinessException(errorMsg);
            }
            request.Password       = HttpUtility.UrlDecode(request.Password.Replace("+", "%2b"));
            request.FromLinkSource = HeaderHelper.GetClientType().ToString();
            CustomerInfo item = EntityConverter <CustomerRegisterRequestViewModel, CustomerInfo> .Convert(request);

            var getExistsCustomerInfo = CustomerFacade.GetCustomerByID(item.CustomerID);

            if (null != getExistsCustomerInfo && getExistsCustomerInfo.SysNo > 0)
            {
                throw new BusinessException(string.Format("注册失败,用户名{0}已经被注册!", item.CustomerID));
            }
            item.InitRank     = 1;
            item.CustomerName = item.CustomerID;
            //密码处理
            string encryptPassword = string.Empty;
            string password        = item.Password;
            string passwordSalt    = string.Empty;

            PasswordHelper.GetNewPasswordAndSalt(ref password, ref encryptPassword, ref passwordSalt);
            item.Password      = encryptPassword;
            item.PasswordSalt  = passwordSalt;
            item.CustomersType = 1;
            CustomerInfo regCustomer = LoginFacade.CreateCustomer(item);

            if (regCustomer.SysNo > 0)
            {
                LoginUser lUser = new LoginUser();
                lUser.UserDisplayName = item.CustomerName;
                lUser.UserID          = item.CustomerID;
                lUser.UserSysNo       = item.SysNo;
                lUser.RememberLogin   = true;
                lUser.LoginDateText   = DateTime.Now.ToString();
                lUser.TimeoutText     = DateTime.Now.AddMinutes(int.Parse(ConfigurationManager.AppSettings["LoginTimeout"].ToString())).ToString();
                CookieHelper.SaveCookie <LoginUser>("LoginCookie", lUser);

                item.SysNo        = regCustomer.SysNo;
                item.RegisterTime = DateTime.Now;
                return(EntityConverter <CustomerInfo, CustomerInfoViewModel> .Convert(item, (s, t) =>
                {
                    t.RegisterTimeString = s.RegisterTime.ToString("yyyy年MM月dd日 HH:mm:ss");
                }));
            }
            else
            {
                throw new BusinessException("用户注册失败,请稍后重试!");
            }
        }