Beispiel #1
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            ReturnUrl = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = Input.FullName, Email = Input.Email, PhoneNumber = Input.Password, Role = Input.SectionRole
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    if (!await RoleManager.RoleExistsAsync(user.Role))
                    {
                        var Role = new IdentityRole(user.Role);
                        var res  = await RoleManager.CreateAsync(Role);

                        if (res.Succeeded)
                        {
                            await _userManager.AddToRoleAsync(user, user.Role);

                            _logger.LogInformation("User created a new account with password.");
                            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                            var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                            await _emailSender.SendEmailConfirmationAsync(Input.Email, callbackUrl);
                        }
                    }
                    else
                    {
                        await _userManager.AddToRoleAsync(user, user.Role);

                        _logger.LogInformation("User created a new account with password.");
                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

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

                    return(LocalRedirect(Url.GetLocalUrl(returnUrl)));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Beispiel #2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            ReturnUrl = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = Input.FullName, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

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

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

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

                    //await _signInManager.SignInAsync(user, isPersistent: false);
                    return(LocalRedirect(Url.GetLocalUrl(returnUrl)));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        //interface actie - resultaat onPost (submit roept die aan)
        public IActionResult OnPost()
        {
            var ticket = new Models.Ticket()
            {
                TicketSubject   = Input.TicketSubject,
                TicketDetails   = Input.TicketDetails,
                TicketRequestor = User.Identity.Name,
                TicketDate      = DateTime.Now,
                PriorityType    = Input.TicketPriority,
                StatusType      = Models.Status.Open,
                ProductType     = Input.TicketProduct,
            };

            m_ticketService.AddTicket(ticket);
            m_ticketService.AddCategoryToTicket(ticket.TicketId, Input.Category);

            var user = new ApplicationUser {
                UserName = Input.TicketRequestor, Email = Input.TicketRequestor
            };
            var result = m_userManager.CreateAsync(user).Result;

            if (result.Succeeded)
            {
                //add user to role
                var test2 = m_userManager.AddToRoleAsync(user, "Customer").Result;
                //add notifcation settings
                var userNotifications = m_userManager.Users.Include(x => x.Notifications).FirstOrDefault(x => x.UserName == user.UserName);
                userNotifications.Notifications.Add(new Models.Notifications()
                {
                    TicketCreated = true,
                    TicketUpdate  = true,
                    NewArticle    = true,
                    NewDocument   = true
                });
                m_context.SaveChanges();
                //new account has been created
                //stuur een Email confirmatie mail  ....
                var code        = m_userManager.GenerateEmailConfirmationTokenAsync(user).Result;
                var callbackUrl = Url.EmailConfirmationNewTicketLink(user.Id, code, Request.Scheme);

                m_mailmanager.SendEmailConfirmationAsync(Input.TicketRequestor, callbackUrl, Input.TicketRequestor);

                // zorg ervoor dat de gebruiker hier ook zijn passwoord kan setten
            }
            else
            {
                //account already in DB
                //stuur mail dat er een ticket is aangemaakt
                SendMailTicketCreate(ticket.TicketId);
            }



            //na post van ticket, redirect naar my ticket lijst
            return(RedirectToPage("../Tickets/MyTickets"));
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            ReturnUrl = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = Input.Email, Email = Input.Email, Company = Input.Company, Firstname = Input.Firstname, Lastname = Input.Lastname
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

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

                    //add user to role
                    var test2 = _userManager.AddToRoleAsync(user, "Customer").Result;
                    //add notifcation settings
                    var userNotifications = _userManager.Users.Include(x => x.Notifications).FirstOrDefault(x => x.UserName == user.UserName);
                    userNotifications.Notifications.Add(new Models.Notifications()
                    {
                        TicketCreated = true,
                        TicketUpdate  = true,
                        NewArticle    = true,
                        NewDocument   = true
                    });
                    m_context.SaveChanges();

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    m_mailmanager.SendEmailConfirmationAsync(Input.Email, callbackUrl, Input.Email);

                    //Prevent newly registered users from being automatically logged on
                    //await _signInManager.SignInAsync(user, isPersistent: false);
                    return(RedirectToPage("./RegisterSucces", new { id = Input.Email }));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                    if (error.Code == "DuplicateUserName")
                    {
                        return(RedirectToPage("./ErrorHandling"));
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        public IActionResult OnPostCreate(int id)
        {
            var ticket = new Models.Ticket()
            {
                TicketSubject   = Input.TicketSubject,
                TicketDetails   = Input.TicketDetails,
                TicketRequestor = User.Identity.Name,
                TicketDate      = DateTime.Now,
                PriorityType    = Input.TicketPriority,
                StatusType      = Models.Status.Open,
                ProductType     = Input.TicketProduct
            };

            m_ticketService.AddTicket(ticket);

            var user = new ApplicationUser {
                UserName = Input.TicketRequestor, Email = Input.TicketRequestor
            };
            var result = m_userManager.CreateAsync(user).Result;

            if (result.Succeeded)
            {
                //add user to role
                var test2 = m_userManager.AddToRoleAsync(user, "Customer").Result;
                //new account has been created
                //stuur een Email confirmatie mail  ....
                var code        = m_userManager.GenerateEmailConfirmationTokenAsync(user).Result;
                var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                m_mailmanager.SendEmailConfirmationAsync(Input.TicketRequestor, callbackUrl, Input.TicketRequestor);

                // zorg ervoor dat de gebruiker hier ook zijn passwoord kan setten
            }
            else
            {
                //account already in DB
                //stuur mail dat er een ticket is aangemaakt
                SendMailTicketCreate(ticket.TicketId);
            }

            if (Input.Delete == true)
            {
                m_emailReceiver.DeleteMailTicket(id);
            }

            return(Redirect("../../Tickets/MyTickets"));
        }
        //interface actie - resultaat onPost (submit roept die aan)
        public IActionResult OnPost()
        {
            var user = new ApplicationUser {
                UserName = Input.Email, Email = Input.Email, Firstname = Input.Firstname, Lastname = Input.Lastname
            };
            var result = m_userManager.CreateAsync(user).Result;

            if (result.Succeeded)
            {
                //add user to role
                var test2 = m_userManager.AddToRoleAsync(user, Input.Role).Result;
                //add notifcation settings
                var userNotifications = m_userManager.Users.Include(x => x.Notifications).FirstOrDefault(x => x.UserName == user.UserName);
                userNotifications.Notifications.Add(new Models.Notifications()
                {
                    TicketCreated = true,
                    TicketUpdate  = true,
                    NewArticle    = true,
                    NewDocument   = true
                });
                m_context.SaveChanges();

                //new account has been created
                //stuur een Email confirmatie mail  ....
                var code        = m_userManager.GenerateEmailConfirmationTokenAsync(user).Result;
                var callbackUrl = Url.EmailConfirmationNewTicketLink(user.Id, code, Request.Scheme);

                m_mailmanager.SendEmailConfirmationAsync(Input.Email, callbackUrl, Input.Email);

                // zorg ervoor dat de gebruiker hier ook zijn passwoord kan setten
            }
            else
            {
                return(RedirectToPage("../Error"));
            }

            return(RedirectToPage("../Admin/AdminChangeRoles"));
        }
        public async Task <IActionResult> OnPostSendVerificationEmailAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            ApplicationUser user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Não foi possível carregar user ID '{_userManager.GetUserId(User)}'.");
            }

            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

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

            TempData["StatusMessage"] = "Verificação de envio de e-mail. Por favor verifique seu e-mail.";

            return(RedirectToPage());
        }
        public async Task <IActionResult> OnPostSendVerificationEmailAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            ApplicationUser user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

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

            TempData["StatusMessage"] = "Verification email sent. Please check your email.";

            return(RedirectToPage());
        }