예제 #1
0
        public async Task <IActionResult> Create([Bind("Email,Password,ConfirmPassword,FirstName,LastName,Birthday,Phone,Address,Role")] CreateApplicationUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = ConvertCreateApplicationUserViewModelToApplicationUserModel(model);
                //var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var isCreatedUserRole = await CreateNewUserRole(user, model.Role);

                    if (isCreatedUserRole)
                    {
                        _logger.LogInformation("Create UserRole successfully");
                    }

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    _logger.LogInformation("User created a new account with password.");
                    return(RedirectToAction(nameof(Index)));
                }

                AddErrors(result);
            }

            return(View(model));
        }
예제 #2
0
        public async Task Create(CreateApplicationUserViewModel model)
        {
            int courierId = 0;

            if (model.Role == "Courier")
            {
                courierId = await _courierService.AddCourier(new CreateCourierViewModel()
                {
                    FirstName   = model.FirstName,
                    SecondName  = model.SecondName,
                    Email       = model.Email,
                    PhoneNumber = model.PhoneNumber
                });
            }

            var identityUser = new ApplicationUser()
            {
                UserName  = model.Email,
                Email     = model.Email,
                CourierId = courierId
            };

            var result = await _userManager.CreateAsync(identityUser, model.Password);

            if (result.Succeeded)
            {
                var currentUser = await _userManager.FindByEmailAsync(identityUser.Email);

                await _userManager.AddToRoleAsync(currentUser, model.Role);

                SendPassword(model);
            }
        }
예제 #3
0
        public async Task <IActionResult> Create(CreateApplicationUserViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = new ApplicationUser {
                    UserName = viewModel.Name, Email = viewModel.Email
                };
                IdentityResult result = await userManager.CreateAsync(user, viewModel.Password);

                if (result.Succeeded)
                {
                    if (viewModel.IsAdmin)
                    {
                        await userManager.AddToRoleAsync(user, "admin");
                    }
                    else
                    {
                        await userManager.AddToRoleAsync(user, "user");
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    foreach (IdentityError error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                }
            }
            return(View(viewModel));
        }
        public IActionResult Create()
        {
            var model = new CreateApplicationUserViewModel {
                Roles = _userService.GetRoles()
            };

            return(View(model));
        }
예제 #5
0
        public async Task <IActionResult> CreateAccount(CreateApplicationUserViewModel applicationUser)
        {
            if (applicationUser is null)
            {
                throw new ArgumentNullException(nameof(applicationUser));
            }

            var result = await _mediator.Send(new CreateAccountCommand(applicationUser.Email, applicationUser.Password, applicationUser.ConfirmPassword));

            return(RedirectToAction("Index", "Home"));
        }
        public async Task <IActionResult> Create(CreateApplicationUserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Roles = _userService.GetRoles();
                return(View(model));
            }

            await _userService.Create(model);

            return(RedirectToAction("Index", "Home"));
        }
        /// <summary>
        /// Creates a Single <see cref="ApplicationUser"/> in the Database from <see cref="CreateApplicationUserViewModel"/>
        /// </summary>
        /// <param name="model"></param>
        /// <returns><see cref="bool"/></returns>
        public async Task <bool> CreateSingleApplicationUser(CreateApplicationUserViewModel model)
        {
            if (!_healthyGamerPortalDbContext.ApplicationUsers.Any(i => i.Email == model.Email))
            {
                ApplicationUser applicationUser = _mapper.Map <ApplicationUser>(model);
                CreatePasswordHash(Encoding.UTF8.GetBytes("NotDiscord"), out string salt, out string hashedPassword);

                applicationUser.Password = hashedPassword;
                applicationUser.Salt     = salt;
                _healthyGamerPortalDbContext.ApplicationUsers.Add(applicationUser);
                await _healthyGamerPortalDbContext.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
예제 #8
0
        public async Task <IActionResult> Create(CreateApplicationUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var api = RestService.For <IHealthyGamerPortalUserApi>(new HttpClient(new Helpers.AuthenticatedHttpClientHandler())
                {
                    BaseAddress = new Uri(BaseUrl)
                });
                var response = await api.CreateSingleApplicationUser(model);

                if (response.Result)
                {
                    TempData.Add("success-msg", "User has been created");
                    return(RedirectToAction("Index", "ApplicationUser"));
                }
                ModelState.AddModelError("Email", "This email has already been registered");
                return(View(model));
            }
            return(View(model));
        }
예제 #9
0
        private void SendPassword(CreateApplicationUserViewModel model)
        {
            var message = File.ReadAllText(@"..\WebApplication1\wwwroot\emails\loginMail.html");

            var replace = $"{model.Email}";

            message = message.Replace("#UserLogin#", replace);

            replace = $"{model.Password}";

            message = message.Replace("#UserPassword#", replace);

            var mail = new MailDto()
            {
                Address = model.Email,
                Message = message,
                Subject = "Dane do logowania"
            };

            _mailService.EnqueueMail(mail);
        }
예제 #10
0
    public async Task <IActionResult> Create([FromBody] CreateApplicationUserViewModel model)
    {
        var user = new ApplicationUser()
        {
            Email     = model.Email,
            UserName  = model.Email,
            FirstName = model.FirstName,
            LastName  = model.LastName
        };
        var result = await _userStore.Create(user, model.Password);

        if (result.Succeeded)
        {
            return(Ok());
        }
        else
        {
            foreach (var error in result.Errors)
            {
                ModelState.AddModelError("error", error.Description);
            }
            return(BadRequest(result.Errors));
        }
    }
예제 #11
0
        public async Task <IActionResult> CreateSingleApplicationUser([FromBody] CreateApplicationUserViewModel model)
        {
            var result = await _applicationUserService.CreateSingleApplicationUser(model);

            return(Ok(GenerateSuccessfulResponse(result)));
        }
예제 #12
0
        private ApplicationUser ConvertCreateApplicationUserViewModelToApplicationUserModel(CreateApplicationUserViewModel model)
        {
            var user = new ApplicationUser
            {
                UserName    = model.Email,
                Email       = model.Email,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                Birthday    = model.Birthday,
                Phone       = model.Phone,
                PhoneNumber = model.Phone,
                Address     = model.Address,
                Role        = model.Role,
            };

            return(user);
        }
예제 #13
0
 public async Task <IActionResult> CreateProfile(CreateApplicationUserViewModel something)
 {
     return(View("Index", "AuthorizationManagement"));
 }
예제 #14
0
 public async Task <IActionResult> AddEntrance(CreateApplicationUserViewModel model)
 {
     return(PartialView("_AddEntrance", model));
 }