Пример #1
0
        public async Task <OperationResult <UserCreateCommandResult> > Handle(UserCreateCommand request, CancellationToken cancellationToken)
        {
            var userNameExist = await _userRepository.IsExistUser(request.PhoneNumber);

            if (userNameExist)
            {
                return(OperationResult <UserCreateCommandResult> .FailureResult("این شماره تلفن وجود دارد"));
            }

            var phoneNumberExist = await _userRepository.IsExistUserName(request.UserName);

            if (phoneNumberExist)
            {
                return(OperationResult <UserCreateCommandResult> .FailureResult("این نام کاربری دارد"));
            }

            var user = new User {
                UserName = request.UserName, Name = request.FirstName, FamilyName = request.LastName, PhoneNumber = request.PhoneNumber, PhoneNumberConfirmed = true
            };

            var createResult = await _userRepository.CreateUser(user);

            if (!createResult.Succeeded)
            {
                return(OperationResult <UserCreateCommandResult> .FailureResult(string.Join(",", createResult.Errors.Select(c => c.Description))));
            }

            var code = await _userRepository.GeneratePhoneNumberToken(user, user.PhoneNumber);

            //TODO Send Code Via Sms Provider

            return(OperationResult <UserCreateCommandResult> .SuccessResult(new UserCreateCommandResult { UserGeneratedKey = user.GeneratedCode }));
        }
Пример #2
0
 public ActionResult Register(RegisterModel u)
 {
     if (_userManager.CreateUser(u))
     {
         TempData["User"] = _userManager.GetUserByLogin(u.User_Login).User_Id;
         return(RedirectToRoute(new { controller = "RegisteredUser", action = "Index" }));
     }
     return(new HttpUnauthorizedResult());
 }
Пример #3
0
        public async Task <IActionResult> CreateUser([FromBody] UserNewModel objInput)
        {
            //var IsValidClaim = HttpContext.ValidatePermission("2");
            //if (!IsValidClaim)
            //    return Unauthorized("you don't have permission");


            var blUser = await _userManager.CreateUser(objInput);

            if (blUser.Status == HttpStatusCode.OK)
            {
                return(Ok(blUser));
            }
            else
            {
                return(BadRequest(blUser));
            }
        }