示例#1
0
        public async Task <IActionResult> Registration([FromBody] RegistrationUserDto model)
        {
            var user = new User
            {
                Email    = model.Email,
                UserName = model.UserName,
                LastName = model.LastName,
                Name     = model.Name,
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(BadRequest(new { Message = "Can't create user", result.Errors }));
            }

            await _userManager.AddToRoleAsync(user, _configuration["Roles:Client"]);

            var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            var callbackUrl = Url.EmailConfirmationLink(nameof(UserController.ConfirmEmail), "User", user.Id, token, Request.Scheme);
            var sendRes     = await _sender.SendEmailAsync(_configuration["EmailCredential:Email"], model.Email, "Your register confirm link", callbackUrl);

            if (!sendRes)
            {
                return(BadRequest("Ups, we can't to send message to your email"));
            }

            return(Ok(new { IsSuccess = true }));
        }
示例#2
0
        public async Task RegistrationUser(RegistrationUserDto dto)
        {
            ValidationResult validationResult;

            try
            {
                validationResult = _validationManager.ValidateRegistrationUserDto(dto);
            }
            catch (ArgumentNullException ex)
            {
                throw new BusinessFaultException(ex.ParamName);
            }
            if (validationResult.HasErrors)
            {
                throw new BusinessFaultException(validationResult.GetErrors());
            }

            var user = Mapper.Map <ApplicationUser>(dto);

            user.UserProfile    = Mapper.Map <UserProfile>(dto);
            user.Id             = Guid.NewGuid().ToString();
            user.EmailConfirmed = true;

            await CreateUser(user, dto.Password, CommonRoles.Regular);
        }
示例#3
0
        public ActionResult UpdatePassword([FromBody] RegistrationUserDto userDto)
        {
            try
            {
                var user = new User(
                    userDto.Email,
                    userDto.Password
                    );

                _userRepository.Save(user);

                return(Ok(new { message = "Account successfully created!" }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            };
        }
        public void ValidateRegistrationUserDto_Must_Validate_Registration_User_Dto_Without_Errors()
        {
            //Arrange
            var dto = new RegistrationUserDto
            {
                ContactName          = "Test",
                Login                = "******",
                Password             = "******",
                PasswordСonfirmation = "qwerty",
                Phone                = "+7(111) 111-11-11",
            };

            //Act
            ValidationResult result = null;

            Assert.DoesNotThrow(() => result = _manager.ValidateRegistrationUserDto(dto));

            //Assert
            Assert.False(result.HasErrors);
        }
        public ValidationResult ValidateRegistrationUserDto(RegistrationUserDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(ArgumentExceptionResources.RegistrationDtoNotFound);
            }
            var validationResult = new ValidationResult("Регистрация пользователя");

            ValidateRegistartionBaseDto(dto, validationResult);

            if (string.IsNullOrEmpty(dto.ContactName))
            {
                validationResult.AddError(ValidationErrorResources.ContactNameIsEmpty);
            }
            if (IsInvalidPhoneNumber(dto.Phone))
            {
                validationResult.AddError(ValidationErrorResources.PhoneNumberIsIncorrect);
            }

            return(validationResult);
        }
        public async Task <IActionResult> RegisterUser(RegistrationUserDto registerUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Fill all fields"));
            }
            var user = _mapper.Map <User>(registerUser);

            if (await _users.UserExists(user))
            {
                return(BadRequest("This user already exists"));
            }
            user.Role = "user";
            user      = await _users.Register(user, registerUser.Password);

            if (user == null)
            {
                return(StatusCode(500));
            }
            var identity = _authService.CreateIdentity(user);

            return(Ok(_authService.CreateToken(identity)));
        }
        public void ValidateRegistrationUserDto_Must_Validate_Registration_User_Dto_With_All_Possible_Errors()
        {
            //Arrange
            var dto = new RegistrationUserDto
            {
                ContactName          = "",
                Login                = "******",
                Password             = "******",
                PasswordСonfirmation = "qwerty1",
                Phone                = "+7(111)-111-11-11",
            };

            //Act
            ValidationResult result = null;

            Assert.DoesNotThrow(() => result = _manager.ValidateRegistrationUserDto(dto));

            //Assert
            Assert.True(result.HasErrors);
            Assert.AreEqual(ValidationErrorResources.LoginIsNotValid, result.Errors[0]);
            Assert.AreEqual(ValidationErrorResources.PasswordsNotMatch, result.Errors[1]);
            Assert.AreEqual(ValidationErrorResources.ContactNameIsEmpty, result.Errors[2]);
            Assert.AreEqual(ValidationErrorResources.PhoneNumberIsIncorrect, result.Errors[3]);
        }
 public Task <IHttpActionResult> RegistrationUser(RegistrationUserDto dto)
 {
     return(CallBusinessLogicActionAsync(() => _userManager.RegistrationUser(dto)));
 }