Esempio n. 1
0
        public IActionResult Index(int StatusCode)
        {
            // Allows us to get the URL of the current page..
            var statusCodeResult = HttpContext.Features.Get <IStatusCodeReExecuteFeature>();
            var model            = new StatusResultViewModel();

            switch (StatusCode)
            {
            case 404:
            {
                model.Num     = "404";
                model.Title   = "OPPS!! PAGE NOT BE FOUND";
                model.Message = $"Sorry but the page you are looking for does not exist, have been removed, " +
                                $"Name changed or is temporarity unavailable.";

                this._logger.LogError(
                    $"\n404 Message Error: {model.Message}," +
                    $" \nPath Error: {statusCodeResult.OriginalPath}" +
                    $" \nQuery String: {statusCodeResult.OriginalQueryString}\n\n"
                    );
            }
            break;

            case 503:
            {
                model.Num     = "503";
                model.Title   = "OPPS!! SERVRE ERROR";
                model.Message = $"The server encountered an error and could not complete your request, Please try again later or refresh the page..";

                this._logger.LogError(
                    $"\n404 Message Error: {model.Message}," +
                    $" \nPath Error: {statusCodeResult.OriginalPath}" +
                    $" \nQuery String: {statusCodeResult.OriginalQueryString}\n\n"
                    );
            }
            break;

            default:
            {
                model.Num     = "XXX";
                model.Title   = "OPPS!! SORRY!!!";
                model.Message = $"Sorry we can not serve your request at the moment, Please come later!!..";

                this._logger.LogError(
                    $"\n\nMessage Error: {model.Message}," +
                    $" \nPath Error: {statusCodeResult.OriginalPath}" +
                    $" \nQuery String: {statusCodeResult.OriginalQueryString}\n\n"
                    );
            }
            break;
            }

            return(View("NotFound", model));
        }
Esempio n. 2
0
        public IActionResult Error()
        {
            var model = new StatusResultViewModel();

            model.Num     = "X_X";
            model.Title   = "OPPS!! SORRY!!!";
            model.Message = $"Sorry we can not serve your request at the moment, Please come later!!..";
            var exceptionSatuts = HttpContext.Features.Get <IExceptionHandlerPathFeature>();

            if (!(exceptionSatuts == null))
            {
                this._logger.LogError(
                    $"\n\n\n\n\n" +
                    $"\nMessage Error: {exceptionSatuts.Error.Message}," +
                    $"\nPath Error: {exceptionSatuts.Path}",
                    $"\nStack Trace: {exceptionSatuts.Error.StackTrace}" +
                    $"\n\n\n\n\n\n"
                    );
            }

            return(View(model));
        }
Esempio n. 3
0
        public async Task <IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            var login = new AccountSignUpViewModel()
            {
                ExternalLogins = new ExternalLoginsViewModel()
                {
                    ReturnUrl      = returnUrl,
                    ExternalLogins = (await this._signInManager.GetExternalAuthenticationSchemesAsync()).ToList()
                }
            };

            if (remoteError != null)
            {
                ModelState.AddModelError(string.Empty, $"Error from External Provider: {remoteError}");
                return(View(nameof(SignIn), login));
            }

            var info = await this._signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ModelState.AddModelError(string.Empty, "Error Loading External Login Information.");
                return(View(nameof(SignIn), login));
            }

            var     email = info.Principal.FindFirstValue(ClaimTypes.Email);
            AppUser user  = null;

            if (email != null)
            {
                user = await this._userManager.FindByEmailAsync(email);
            }

            var signInResult = await this._signInManager.ExternalLoginSignInAsync
                               (
                info.LoginProvider,
                info.ProviderKey,
                isPersistent : false,
                bypassTwoFactor : true
                               );

            if (signInResult.Succeeded)
            {
                return(LocalRedirect(returnUrl));
            }
            else
            {
                if (email != null)
                {
                    if (user == null)
                    {
                        var firstName = info.Principal.FindFirstValue(ClaimTypes.GivenName);
                        var lastName  = info.Principal.FindFirstValue(ClaimTypes.Surname);
                        var name      = info.Principal.FindFirstValue(ClaimTypes.Name);
                        var gendre    = info.Principal.FindFirstValue(ClaimTypes.Gender);
                        user = new AppUser
                        {
                            UserName  = email,
                            Email     = email,
                            FirstName = firstName == null ? "User" : firstName,
                            LastName  = lastName == null ? "User" : lastName,
                            Gendre    = gendre == null ? "unset" : gendre
                        };

                        var generatedUserPassword = GenerateRandomPassword();

                        var result = await this._userManager.CreateAsync(user, generatedUserPassword);

                        if (!result.Succeeded)
                        {
                            return(RedirectToAction(nameof(SignUp), login));
                        }

                        var token = await this._userManager.GenerateEmailConfirmationTokenAsync(user);

                        var confirmationLink = Url.Action(
                            "ConfirmEmail",
                            "Account",
                            new { userId = user.Id, token = token },
                            Request.Scheme
                            );
                        this._logger.LogWarning
                        (
                            $"\n\n\n" +
                            $"\nUser: {email}" +
                            $"\nGenerated Password: \"{generatedUserPassword}\"" +
                            $"\nGenerated Email Confirmation: \"{confirmationLink}\"" +
                            $"\n\n\n"
                        );
                    }

                    await this._userManager.AddLoginAsync(user, info);

                    await this._signInManager.SignInAsync(user, isPersistent : true);

                    return(LocalRedirect(returnUrl));
                }

                var modl = new StatusResultViewModel();
                modl.Title   = $"Email claim not received from: {info.LoginProvider}";
                modl.Message = "Please contact support on [email protected]";

                return(View("../Error/NotFound", modl));
            }
        }