Esempio n. 1
0
        public string RegisterUser(RegisterUserBindingModel userModel)
        {
            if (this.users.All().Any(u => u.Email == userModel.Email))
            {
                return("/store/login");
            }

            if (!RegisterUserValidator.IsValid(userModel))
            {
                return("/store/register");
            }

            var newUser = new User()
            {
                FullName = userModel.FullName,
                Email    = userModel.Email,
                Password = userModel.Password
            };

            if (!this.users.All().Any())
            {
                newUser.IsAdministrator = true;
            }

            this.users.Add(newUser);
            this.users.SaveChanges();

            return("/store/login");
        }
Esempio n. 2
0
 public EfRegisterUserCommand(WatchShopContext context, RegisterUserValidator validator, IEmailSender sender, IMapper mapper)
 {
     _context   = context;
     _validator = validator;
     _sender    = sender;
     _mapper    = mapper;
 }
Esempio n. 3
0
        public async Task <IActionResult> Register(RegisterUserRequestDTO registerUserRequestDTO)
        {
            RegisterUserValidator validator = new RegisterUserValidator();
            var validationResult            = validator.Validate(registerUserRequestDTO);

            if (!validationResult.IsValid)
            {
                _logger.LogInformation("Not valid input.");
                ValidatorError validatorError = new ValidatorError();
                return(BadRequest(new {
                    message = validatorError.GetErrorMessagesAsString(validationResult.Errors)
                }));
            }

            var user = await _userRepo.CreateUser(registerUserRequestDTO.User, registerUserRequestDTO.Password);

            if (user == null)
            {
                return(BadRequest(new {
                    message = "User with given email already exists."
                }));
            }

            return(Ok(user));
        }
 public EfRegisterUserCommand(ArtsContext context, RegisterUserValidator validator, IMapper mapper, IEmailSender email)
 {
     this.context   = context;
     this.validator = validator;
     this.mapper    = mapper;
     this.email     = email;
 }
Esempio n. 5
0
 public EfRegisterUserCommand(RegisterUserValidator validator, PerfumeContext context, IMapper mapper, IEmailSender sender)
 {
     _validator = validator;
     _context   = context;
     _mapper    = mapper;
     _sender    = sender;
 }
Esempio n. 6
0
 public RegisterUserHandler(
     NotificationContext notification,
     IUserManager userManager,
     RegisterUserValidator validator) : base(notification, userManager)
 {
     _validator = validator;
 }
Esempio n. 7
0
 public AuthAppService(RegisterUserValidator registerUserValidator, IRepository <User> userRepository, IOptions <JWTSettings> jwtSettings, IMapper mapper)
 {
     _registerUserValidator = registerUserValidator;
     _userRepository        = userRepository;
     _jwtSettings           = jwtSettings.Value;
     _mapper = mapper;
 }
Esempio n. 8
0
        public TokenDTO RegisterUser(UserDTO userData)
        {
            var validator        = new RegisterUserValidator(_userRepository);
            var validationResult = validator.Validate(userData);

            if (!validationResult.IsValid)
            {
                throw new ValidationException(validationResult.Errors);
            }
            var user = new User
            {
                Name     = userData.Name,
                Email    = userData.Email,
                Password = _cryptoService.Encrypt(userData.Password)
            };

            _userRepository.Insert(user);
            var auth = new AuthDTO
            {
                Email    = userData.Email,
                Password = userData.Password
            };

            return(_authService.Authenticate(auth));
        }
Esempio n. 9
0
        public void ShouldAcceptValidUserDataForRegister()
        {
            Mock <IUserRepository> userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(x => x.GetByEmail(It.IsAny <string>())).Returns(() => null);

            var userData = new UserDTO
            {
                Name                 = "Test1",
                Email                = "*****@*****.**",
                Password             = "******",
                PasswordConfirmation = "pwd"
            };

            var sut    = new RegisterUserValidator(userRepositoryMock.Object);
            var result = sut.Validate(userData);

            Assert.True(result.IsValid);
        }
Esempio n. 10
0
        public void ShouldNotAcceptInvalidUserDataForRegister()
        {
            Mock <IUserRepository> userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(x => x.GetByEmail(It.IsAny <string>())).Returns(() => null);

            var userData = new UserDTO
            {
                Name                 = "",
                Email                = "",
                Password             = "******",
                PasswordConfirmation = "pwdd"
            };

            var sut    = new RegisterUserValidator(userRepositoryMock.Object);
            var result = sut.Validate(userData);

            Assert.False(result.IsValid);
            Assert.NotEmpty(result.Errors);
        }
Esempio n. 11
0
        public async Task <IHttpActionResult> Register([FromBody] RegisterUser model)
        {
            var sb = new StringBuilder(Request.RequestUri.GetLeftPart(UriPartial.Authority));

            sb.Append("/api/user/{0}/confirmemail/{1}");

            //throws 400
            var validator = new RegisterUserValidator();

            validator.ValidateAndThrow(model);

            var(id, token) = await _service.RegisterAsync(model.Email, model.UserName, model.Password);

            if (id is null && token is null)
            {
                // throws 409 conflict
                throw new OperationCanceledException("Please provide unique UserName and Email.");
            }
            return(Ok(id));
        }
Esempio n. 12
0
        // RegisterUser <username> <password> <repeat-password> <email>
        public void Execute()
        {
            RegisterUserValidator.AreEqual(this.Password, this.RepeatedPassword);
            RegisterUserValidator.Exists(this.Username, context);

            User user = new User
            {
                Username         = this.Username,
                Password         = this.Password,
                Email            = this.Email,
                IsDeleted        = false,
                RegisteredOn     = DateTime.Now,
                LastTimeLoggedIn = DateTime.Now
            };

            using (context)
            {
                context.Users.Add(user);
                context.SaveChanges();
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(UserMessages.Success(this.Username));
        }
Esempio n. 13
0
 public RegisterUserCommand(RegisterUserValidator validator, IUserRepository userRepository)
 {
     _validator      = validator;
     _userRepository = userRepository;
 }
Esempio n. 14
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // validation
                var validator = new RegisterUserValidator();
                ValidationResult valResult = validator.Validate(model);
                if (!valResult.IsValid)
                {
                    AddErrors(valResult);
                    ViewBag.ReturnUrl = returnUrl;
                    return View(model);
                }

                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }

                // changed email as username
                var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };
                //var result = await UserManager.CreateAsync(user);

                // create user and profile 
                var result = _profileService.CreateUserProfile(new Profile
                {
                    UserName = model.UserName,
                    Email = model.Email,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Locations = model.Location,
                    ProfileStyle = ProfileStyle.GetDefault(),
                }, user, null);


                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Esempio n. 15
0
 public RegisterUser(MoviePlusContext context, RegisterUserValidator validator, IEmailSender email = null)
 {
     _context   = context;
     _validator = validator;
     _email     = email;
 }
Esempio n. 16
0
 public EFRegisterUserCommand(BlogContext context, RegisterUserValidator validator, IEmailSender email)
 {
     _context   = context;
     _validator = validator;
     this.email = email;
 }
 public EfRegisterUserCommand(BlogContext context, IEmailSender sender, RegisterUserValidator validator)
 {
     _context   = context;
     _sender    = sender;
     _validator = validator;
 }
 public EfRegisterUserCommand(CinemaContext context, RegisterUserValidator validator, IEmailSender sender)
 {
     _context   = context;
     _validator = validator;
     _sender    = sender;
 }
Esempio n. 19
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // validation
                var validator = new RegisterUserValidator();
                ValidationResult valResult = validator.Validate(model);
                if (!valResult.IsValid)
                {
                    AddErrors(valResult);
                    return View(model);
                }

                // create user
                var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };
                //var result = await UserManager.CreateAsync(user, model.Password);

                // create profile
                var result = _profileService.CreateUserProfile(new Profile
                {
                    UserName = model.UserName,
                    Email = model.Email,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Locations = model.Location,
                    ProfileStyle = ProfileStyle.GetDefault(),
                }, user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }