public JsonResult Create(RegisterIM model)
        {
            if (!ModelState.IsValid)
            {
                var errorMes = GetModelErrorMessage();
                AR.Setfailure(errorMes);
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }


            var result = _userServices.Register(model.UserName, model.Email, model.Password, model.DisplayName);

            if (result == 1)
            {
                AR.Setfailure(Messages.CannotRegisterEmail);
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }

            if (result == 2)
            {
                AR.Setfailure(Messages.CannotRegisterUserName);
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }


            int count;
            int pageSize = SettingsManager.User.PageSize;
            var list     = _userServices.GetPagedElements(0, pageSize, string.Empty, null, null, null, out count);

            //    List<UserVM> userList = _mapper.Map<List<User>, List<UserVM>>(list);
            AR.Data = RenderPartialViewToString("_UserList", list);

            AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.User));
            return(Json(AR, JsonRequestBehavior.DenyGet));
        }
Пример #2
0
        public IActionResult Register(RegisterIM model)
        {
            if (!ModelState.IsValid)
            {
                var errorMes = GetModelErrorMessage();
                AR.Setfailure(errorMes);
                return(Json(AR));
                // return Json(false);
            }


            var result = _userServices.CreateUser(model.UserName, model.Email, model.Password, model.DisplayName);

            if (result == 1)
            {
                AR.Setfailure(Messages.CannotRegisterEmail);
                _logger.LogError(Messages.CannotRegisterEmail);
                return(Json(AR));
            }

            if (result == 2)
            {
                AR.Setfailure(Messages.CannotRegisterUserName);
                _logger.LogError(Messages.CannotRegisterUserName);
                return(Json(AR));
            }


            AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, model.UserName));
            _logger.LogError(string.Format(Messages.AlertCreateSuccess, model.UserName));
            return(Json(AR));
        }
Пример #3
0
        public bool AppRegister(RegisterIM im)
        {
            if (im.Cellphone.StartsWith("170") || im.Cellphone.StartsWith("171"))
            {
                throw new CommonException(ReasonCode.PhoneNumber_Invalid, MessageResources.InvalidCellphone);
            }

            var verifier = new RegisterCellphoneVerifier();

            SecurityVerify.Verify(verifier, SystemPlatform.FiiiPay, $"{im.CountryId}:{im.Cellphone}", im.SMSCode, true);

            var accountDAC = new UserAccountDAC();

            if (!IsNullOrEmpty(im.InviterCode) && !accountDAC.ExistInviterCode(im.InviterCode))
            {
                throw new CommonException(ReasonCode.INVITORCODE_NOT_EXISTS, MessageResources.InvalidInvitation);
            }
            if (!AccountUseable(im.CountryId, im.Cellphone))
            {
                throw new CommonException(ReasonCode.ACCOUNT_EXISTS, Format(MessageResources.AccountAlreadyExist, im.Cellphone));
            }

            bool result = Register(im.CountryId, im.Cellphone, im.Password, im.InviterCode);

            if (result)
            {
                SecurityVerify.InvalidateCode(verifier, SystemPlatform.FiiiPay, $"{im.CountryId}:{im.Cellphone}");
            }

            return(result);
        }
Пример #4
0
        public ServiceResult <bool> Register(RegisterModel model)
        {
            ServiceResult <bool> result = new ServiceResult <bool>();

            var im = new RegisterIM
            {
                CountryId   = model.CountryId,
                Cellphone   = model.Cellphone,
                Password    = model.Password,
                SMSCode     = model.SMSCode,
                InviterCode = model.InviterCode
            };

            result.Data = new UserAccountComponent().AppRegister(im);


            return(result);
        }
Пример #5
0
        public async Task <IActionResult> CreateUserAsync([FromBody] RegisterIM model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _context.Users.CountAsync(d => d.Email == model.Email);

            if (result > 0)
            {
                return(BadRequest("邮箱已存在"));
            }

            result = await _context.Users.CountAsync(d => d.Username == model.UserName);

            if (result > 0)
            {
                return(BadRequest("用户名已存在"));
            }


            var securityStamp = EncryptionHelper.GenerateSalt();
            var passwordHash  = EncryptionHelper.HashPasswordWithSalt(model.Password, securityStamp);

            var newUser = new User()
            {
                Id            = IdentityGenerator.SequentialGuid(),
                Username      = model.UserName,
                Email         = model.Email,
                SecurityStamp = Convert.ToBase64String(securityStamp),
                PasswordHash  = passwordHash,
                CreateDate    = DateTime.Now,
                IsActive      = true,
            };

            _context.Add(newUser);
            await _context.SaveChangesAsync();

            return(Ok("用户创建成功"));
        }
        // GET: User/Create
        public ActionResult Create()
        {
            RegisterIM vm = new RegisterIM();

            return(PartialView("_UserCreate", vm));
        }