示例#1
0
        public SimpleAjaxResult Register()
        {
            try
            {
                var serialNo = SerialNoHelper.Create();
                var account  = AccountService.GetByName(AccountName);
                if (account == null || (account.State != AccountStates.Invalid && account.State != AccountStates.Normal))
                {
                    return(new SimpleAjaxResult("卡号不存在或已注册"));
                }
                if (User.SaltAndHash(AccountPassword, account.PasswordSalt) != account.Password)
                {
                    return(new SimpleAjaxResult("卡号不存在或已注册"));
                }
                AccountUser owner    = null;
                bool        hasOwner = false;
                if (account.OwnerId.HasValue)
                {
                    owner    = MembershipService.GetUserById(account.OwnerId.Value) as AccountUser;
                    hasOwner = true;
                    if (owner.SignOnTime != null)
                    {
                        Logger.Error(LogTypes.RegisterAccountUser, "卡号 " + AccountName + " 不存在或已注册");
                        return(new SimpleAjaxResult("卡号不存在或已注册"));
                    }
                }
                {
                    var user = MembershipService.GetUserByName(UserName);
                    if (user != null)
                    {
                        Logger.Error(LogTypes.RegisterAccountUser, "用户名 " + UserName + " 已存在");
                        return(new SimpleAjaxResult("用户名已存在"));
                    }
                }

                owner             = owner ?? new AccountUser();
                owner.Name        = UserName;
                owner.DisplayName = string.IsNullOrWhiteSpace(owner.DisplayName) ? UserName : owner.DisplayName;
                owner.SetPassword(UserPassword);
                owner.SignOnTime = DateTime.Now;
                TransactionHelper.BeginTransaction();
                if (!hasOwner)
                {
                    MembershipService.CreateUser(owner);
                    account.OwnerId = owner.UserId;
                    AccountService.Update(account);
                }
                else
                {
                    MembershipService.UpdateUser(owner);
                }
                if (owner.Roles == null || owner.Roles.Count == 0)
                {
                    MembershipService.AssignRoles(owner, MembershipService.QueryRoles(new RoleRequest()
                    {
                        Name = RoleNames.Account
                    }).Select(x => x.RoleId).ToArray());
                }

                Logger.LogWithSerialNo(LogTypes.RegisterAccountUser, serialNo, owner.UserId, owner.Name, AccountName);
                TransactionHelper.Commit();
                return(new SimpleAjaxResult());
            }
            catch (System.Exception ex)
            {
                Logger.Error(LogTypes.RegisterAccountUser, ex);
                return(new SimpleAjaxResult("系统错误"));
            }
        }
示例#2
0
        //public CreateQrCodeResult CreateQrCode()
        //{
        //    var set = SetWeChatService.GetById(1);
        //    var access_token = AccessTokenContainer.GetToken(set.appID);
        //    return Senparc.Weixin.MP.AdvancedAPIs.QrCodeApi.Create(access_token, 0, 001);

        //}

        public ResultMessage Save()
        {
            try
            {
                //if (string.IsNullOrWhiteSpace(openID))
                //    return new ResultMessage() { Code = -1, Msg = "请重新进入页面!" };
                //var account = AccountService.GetByopenID(openID);
                //if (account != null)
                //    return new ResultMessage() { Code = -1, Msg = "你已注册!" };
                var user = MembershipService.GetByMobile(Mobile);
                if (user != null)
                {
                    return new ResultMessage()
                           {
                               Code = -1, Msg = "手机号码已注册,请更换!"
                           }
                }
                ;
                if (string.IsNullOrWhiteSpace(Password))
                {
                    return new ResultMessage()
                           {
                               Code = -1, Msg = "请输入密码!"
                           }
                }
                ;
                if (Password != PasswordConfirm)
                {
                    return new ResultMessage()
                           {
                               Code = -1, Msg = "两次输入密码不一致!"
                           }
                }
                ;
                var     site       = SiteService.Query(new SiteRequest()).FirstOrDefault();
                int     salerId    = 0;
                Account saleAccont = null;
                if (!string.IsNullOrWhiteSpace(orangeKey))
                {
                    saleAccont = AccountService.GetByorangeKey(orangeKey);

                    if (saleAccont == null)
                    {
                        return new ResultMessage()
                               {
                                   Code = -2, Msg = "推荐码不存在!"
                               }
                    }
                    ;
                    salerId = saleAccont.accountId;
                }
                TransactionHelper.BeginTransaction();
                AccountUser modelUser = new AccountUser();
                modelUser.Address     = Address;
                modelUser.DisplayName = Name;
                modelUser.Email       = Email;
                modelUser.Gender      = Sex;
                modelUser.Mobile      = Mobile;
                modelUser.Name        = Mobile;
                modelUser.SetPassword(Password);
                modelUser.State = UserStates.Normal;
                MembershipService.CreateUser(modelUser);
                Account modelAccount = new Account();
                //var QrCodeResult = CreateQrCode();
                //modelAccount.ticket = QrCodeResult.ticket;
                modelAccount.activatePoint = 0;
                //modelAccount.notActivatePoint = 0;
                modelAccount.orangeKey = modelUser.UserId.ToString().PadLeft(modelUser.UserId.ToString().Length + 2, '0');
                //modelAccount.payPoint = 0;
                modelAccount.openID = openID;
                //modelAccount.presentExp = site.givePoint;
                modelAccount.salerId    = salerId;
                modelAccount.state      = AccountStates.Normal;
                modelAccount.submitTime = DateTime.Now;
                modelAccount.userId     = modelUser.UserId;
                modelAccount.grade      = AccountGrade.not;
                AccountService.Insert(modelAccount);
                if (salerId > 0)
                {
                    RecommendLog recommendlog = new RecommendLog();
                    recommendlog.remark     = string.Format("推荐了{0}", Mobile);
                    recommendlog.salerId    = saleAccont.userId;
                    recommendlog.submitTime = DateTime.Now;
                    recommendlog.userId     = modelUser.UserId;
                    recommendlog.userName   = Mobile;
                    RecommendLogService.Insert(recommendlog);
                }
                TransactionHelper.Commit();
                return(new ResultMessage()
                {
                    Code = 0
                });
            }
            catch (Exception ex)
            {
                Log4netService.Insert(ex);
                return(new ResultMessage()
                {
                    Code = -1, Msg = "系统错误!"
                });
            }
        }