예제 #1
0
        public void getIP()
        {
            //arranjo
            var ip = MockListaIp().FirstOrDefault();

            var asserto = _mock.Setup(p => p.Query()).Returns(MockListaIp());
            /*----*/
            //ação
            var acao = _service.GetIP();

            //asserto
            Assert.AreEqual(ip, acao);
        }
예제 #2
0
        public IActionResult GetIP()
        {
            string ip = string.Empty;

            ip = IP.GetIP(HttpContext);

            if (!string.IsNullOrEmpty(ip))
            {
                return(Ok(ip));
            }
            else
            {
                return(new ObjectResult("Cannot return your IP address")
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
예제 #3
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("CheckEmail");
            if (ModelState.IsValid && Input.ProfessorID != null)
            {
                var user = new ApplicationUser {
                    UserName = Input.UserName, Email = Input.Email, ProfessorId = Input.ProfessorID, RoleName = Input.RoleName
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    bool roleExists = await _roleManager.RoleExistsAsync(Input.RoleName);

                    if (!roleExists)
                    {
                        await _roleManager.CreateAsync(new IdentityRole(Input.RoleName));

                        var permissao = await _userManager.AddToRoleAsync(user, Input.RoleName);

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

                            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                            var callbackUrl = Url.Page(
                                "/Account/ConfirmEmail",
                                pageHandler: null,
                                values: new { userId = user.Id, code = code },
                                protocol: Request.Scheme);
                            var x = IpService.GetIP();
                            await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                              $"Seu Ip de Acesso é : {x.ip}");

                            //return RedirectToPage("./CheckEmail", user);
                            //return new JsonResult(returnUrl);
                            return(new JsonResult(new
                            {
                                redirectUrl = Url.Page("CheckEmail", "OnGet", user),
                                isRedirect = true
                            }));
                        }
                    }

                    if (!await _userManager.IsInRoleAsync(user, Input.RoleName))
                    {
                        var permissao = await _userManager.AddToRoleAsync(user, Input.RoleName);

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

                            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                            var callbackUrl = Url.Page(
                                "/Account/ConfirmEmail",
                                pageHandler: null,
                                values: new { userId = user.Id, code = code },
                                protocol: Request.Scheme);
                            var x = IpService.GetIP();
                            await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                              $"Seu Ip de Acesso é : {x.ip}");

                            //return RedirectToPage("./CheckEmail", user);
                            //return new JsonResult(returnUrl);
                            return(new JsonResult(new
                            {
                                redirectUrl = Url.Page("CheckEmail", "OnGet", user),
                                isRedirect = true
                            }));
                        }
                    }
                }
            }
            return(new JsonResult(returnUrl));
        }