Esempio n. 1
0
        public virtual async Task <IActionResult> OnPostAsync()
        {
            try
            {
                await AccountAppService.SendPasswordResetCodeAsync(
                    new SendPasswordResetCodeDto
                {
                    Email         = Email,
                    AppName       = "MVC", //TODO: Const!
                    ReturnUrl     = ReturnUrl,
                    ReturnUrlHash = ReturnUrlHash
                }
                    );
            }
            catch (UserFriendlyException e)
            {
                Alerts.Danger(GetLocalizeExceptionMessage(e));
                return(Page());
            }


            return(RedirectToPage(
                       "./PasswordResetLinkSent",
                       new
            {
                returnUrl = ReturnUrl,
                returnUrlHash = ReturnUrlHash
            }));
        }
Esempio n. 2
0
    public virtual async Task <IActionResult> OnPostAsync()
    {
        try
        {
            await CheckSelfRegistrationAsync();

            if (IsExternalLogin)
            {
                var externalLoginInfo = await SignInManager.GetExternalLoginInfoAsync();

                if (externalLoginInfo == null)
                {
                    Logger.LogWarning("External login info is not available");
                    return(RedirectToPage("./Login"));
                }

                await RegisterExternalUserAsync(externalLoginInfo, Input.EmailAddress);
            }
            else
            {
                await RegisterLocalUserAsync();
            }

            return(Redirect(ReturnUrl ?? "~/")); //TODO: How to ensure safety? IdentityServer requires it however it should be checked somehow!
        }
        catch (BusinessException e)
        {
            Alerts.Danger(GetLocalizeExceptionMessage(e));
            return(Page());
        }
    }
Esempio n. 3
0
        public virtual async Task <IActionResult> OnPostAsync()
        {
            var user = await SignInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                Alerts.Warning("双因素认证失败,用户未登录或已失效!");
                return(Page());
            }

            var result = await SignInManager.TwoFactorSignInAsync(Input.Provider, Input.Code, Input.RememberMe, Input.RememberBrowser);

            if (result.Succeeded)
            {
                return(RedirectSafely(Input.ReturnUrl));
            }
            if (result.IsLockedOut)
            {
                Logger.LogWarning(7, "User account locked out.");
                Alerts.Warning(L["UserLockedOutMessage"]);
                return(Page());
            }
            else
            {
                Alerts.Danger("授权码验证无效!");
                return(Page());
            }
        }
        public virtual async Task <IActionResult> OnPostAsync()
        {
            // 验证用户登录状态
            var user = await SignInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                Alerts.Warning(L["TwoFactorAuthenticationInvaidUser"]);
                return(Page());
            }
            // 双因素登录
            var result = await SignInManager.TwoFactorSignInAsync(Provider, Input.VerifyCode, RememberMe, Input.RememberBrowser);

            if (result.Succeeded)
            {
                return(RedirectSafely(ReturnUrl, ReturnUrlHash));
            }
            if (result.IsLockedOut)
            {
                Logger.LogWarning(7, "User account locked out.");
                Alerts.Warning(L["UserLockedOutMessage"]);
                return(Page());
            }
            else
            {
                Alerts.Danger(L["TwoFactorAuthenticationInvaidUser"]);// TODO: 更多状态码的解读
                return(Page());
            }
        }
Esempio n. 5
0
    public virtual async Task <IActionResult> OnPostAsync(string action)
    {
        await CheckLocalLoginAsync();

        ValidateModel();

        ExternalProviders = await GetExternalProviders();

        EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin);

        await ReplaceEmailToUsernameOfInputIfNeeds();

        await IdentityOptions.SetAsync();

        var result = await SignInManager.PasswordSignInAsync(
            LoginInput.UserNameOrEmailAddress,
            LoginInput.Password,
            LoginInput.RememberMe,
            true
            );

        await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
        {
            Identity = IdentitySecurityLogIdentityConsts.Identity,
            Action   = result.ToIdentitySecurityLogAction(),
            UserName = LoginInput.UserNameOrEmailAddress
        });

        if (result.RequiresTwoFactor)
        {
            return(await TwoFactorLoginResultAsync());
        }

        if (result.IsLockedOut)
        {
            Alerts.Warning(L["UserLockedOutMessage"]);
            return(Page());
        }

        if (result.IsNotAllowed)
        {
            Alerts.Warning(L["LoginIsNotAllowed"]);
            return(Page());
        }

        if (!result.Succeeded)
        {
            Alerts.Danger(L["InvalidUserNameOrPassword"]);
            return(Page());
        }

        //TODO: Find a way of getting user's id from the logged in user and do not query it again like that!
        var user = await UserManager.FindByNameAsync(LoginInput.UserNameOrEmailAddress) ??
                   await UserManager.FindByEmailAsync(LoginInput.UserNameOrEmailAddress);

        Debug.Assert(user != null, nameof(user) + " != null");

        return(RedirectSafely(ReturnUrl, ReturnUrlHash));
    }
Esempio n. 6
0
        public ActionResult Index()
        {
            Alerts.Danger("Danger alert message!", "Test Alert");
            Alerts.Warning("Warning alert message!", "Test Alert");
            Alerts.Info("Info alert message!", "Test Alert");
            Alerts.Success("Success alert message!", "Test Alert");

            return(View());
        }
Esempio n. 7
0
        [UnitOfWork] //TODO: Will be removed when we implement action filter
        public virtual async Task <IActionResult> OnPostAsync(string action)
        {
            EnableLocalLogin = true; //TODO: We can get default from a setting?

            ValidateModel();

            await ReplaceEmailToUsernameOfInputIfNeeds();

            var result = await SignInManager.PasswordSignInAsync(
                LoginInput.UserNameOrEmailAddress,
                LoginInput.Password,
                LoginInput.RememberMe,
                true
                );

            if (result.RequiresTwoFactor)
            {
                return(RedirectToPage("./SendSecurityCode", new
                {
                    returnUrl = ReturnUrl,
                    returnUrlHash = ReturnUrlHash,
                    rememberMe = LoginInput.RememberMe
                }));
            }

            if (result.IsLockedOut)
            {
                Alerts.Warning(L["UserLockedOutMessage"]);
                return(Page());
            }

            if (result.RequiresTwoFactor)
            {
                return(RedirectToPage("./SendSecurityCode"));
            }

            if (result.IsNotAllowed)
            {
                Alerts.Warning(L["LoginIsNotAllowed"]);
                return(Page());
            }

            if (!result.Succeeded)
            {
                Alerts.Danger(L["InvalidUserNameOrPassword"]);
                return(Page());
            }

            //TODO: Find a way of getting user's id from the logged in user and do not query it again like that!
            var user = await UserManager.FindByNameAsync(LoginInput.UserNameOrEmailAddress) ??
                       await UserManager.FindByEmailAsync(LoginInput.UserNameOrEmailAddress);

            Debug.Assert(user != null, nameof(user) + " != null");

            return(RedirectSafely(ReturnUrl, ReturnUrlHash));
        }
Esempio n. 8
0
 public override async Task <IActionResult> OnPostAsync()
 {
     try
     {
         return(await base.OnPostAsync());
     }
     catch (Exception e)
     {
         Alerts.Danger(e.Message);
         return(Page());
     }
 }
Esempio n. 9
0
        public IActionResult Index()
        {
            Alerts.Danger("Danger alert message!", "Test Alert");
            Alerts.Warning("Warning alert message!", "Test Alert");
            Alerts.Info("Info alert message!", "Test Alert");
            Alerts.Success("Success alert message!", "Test Alert");

            Alerts.Danger("Danger toast message!", "Test Toast", displayType: AlertDisplayType.Toastr);
            Alerts.Warning("Warning toast message!", "Test Toast", displayType: AlertDisplayType.Toastr);
            Alerts.Info("Info toast message!", "Test Toast", displayType: AlertDisplayType.Toastr);
            Alerts.Success("Success toast message!", "Test Toast", displayType: AlertDisplayType.Toastr);

            Alerts.Danger("Danger toast message!", "Test Toast", dismissible: false, displayType: AlertDisplayType.Toastr);
            Alerts.Warning("Warning toast message!", "Test Toast", dismissible: false, displayType: AlertDisplayType.Toastr);
            Alerts.Info("Info toast message!", "Test Toast", dismissible: false, displayType: AlertDisplayType.Toastr);
            Alerts.Success("Success toast message!", "Test Toast", dismissible: false, displayType: AlertDisplayType.Toastr);

            return(View());
        }
        public virtual async Task <IActionResult> OnPostAsync()
        {
            var result = await SignInManager.TwoFactorAuthenticatorSignInAsync(Input.Code, Input.RememberMe, Input.RememberBrowser);

            if (result.Succeeded)
            {
                return(RedirectSafely(Input.ReturnUrl));
            }
            if (result.IsLockedOut)
            {
                Logger.LogWarning(7, "User account locked out.");
                Alerts.Warning(L["UserLockedOutMessage"]);
                return(Page());
            }
            else
            {
                Alerts.Danger("��Ȩ����֤��Ч!");
                return(Page());
            }
        }
Esempio n. 11
0
        public virtual async Task <IActionResult> OnPostAsync()
        {
            var result = await SignInManager.TwoFactorAuthenticatorSignInAsync(Input.VerifyCode, RememberMe, RememberBrowser);

            if (result.Succeeded)
            {
                return(RedirectSafely(ReturnUrl, ReturnUrlHash));
            }
            if (result.IsLockedOut)
            {
                Logger.LogWarning(7, "User account locked out.");
                Alerts.Warning(L["UserLockedOutMessage"]);
                return(Page());
            }
            else
            {
                Alerts.Danger(L["TwoFactorAuthenticationInvaidUser"]);// TODO: ¸ü¶à״̬ÂëµÄ½â¶Á
                return(Page());
            }
        }
Esempio n. 12
0
        public override async Task <IActionResult> OnPostAsync()
        {
            try
            {
                await CheckSelfRegistrationAsync();

                if (IsExternalLogin)
                {
                    var externalLoginInfo = await SignInManager.GetExternalLoginInfoAsync();

                    if (externalLoginInfo == null)
                    {
                        Logger.LogWarning("External login info is not available");
                        return(RedirectToPage("./Login"));
                    }
                    await RegisterExternalUserAsync(externalLoginInfo, Input.EmailAddress);
                }
                else
                {
                    await RegisterLocalUserAsync();
                }

                /*if (UserManager.Options.SignIn.RequireConfirmedAccount)*/
                {
                    return(RedirectToPage("RegisterConfirmation", new { email = Input.EmailAddress, returnUrl = ReturnUrl }));
                }

                /*else
                 * {
                 *  await SignInManager.SignInAsync(_abpIdentityUser, isPersistent: true);
                 *  return LocalRedirect(ReturnUrl);
                 * }*/
                // return Redirect(ReturnUrl ?? "~/"); //TODO: How to ensure safety? IdentityServer requires it however it should be checked somehow!
            }
            catch (BusinessException e)
            {
                Alerts.Danger(e.Message);
                return(Page());
            }
        }
Esempio n. 13
0
        [UnitOfWork] //TODO: Will be removed when we implement action filter
        public virtual async Task <IActionResult> OnPostAsync()
        {
            ValidateModel();

            var result = await SignInManager.PasswordSignInAsync(
                Input.UserNameOrEmailAddress,
                Input.Password,
                Input.RememberMe,
                true
                );

            if (result.IsLockedOut)
            {
                Alerts.Warning(L["UserLockedOutMessage"]);
                return(Page());
            }

            if (result.RequiresTwoFactor)
            {
                return(RedirectToPage("./SendSecurityCode"));
            }

            if (result.IsNotAllowed)
            {
                Alerts.Warning(L["LoginIsNotAllowed"]);
                return(Page());
            }

            if (!result.Succeeded)
            {
                Alerts.Danger(L["InvalidUserNameOrPassword"]);
                return(Page());
            }

            return(RedirectSafely(ReturnUrl, ReturnUrlHash));
        }
        public async override Task <IActionResult> OnPostAsync(string action)
        {
            if (action == "Cancel")
            {
                var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl);

                if (context == null)
                {
                    return(Redirect("~/"));
                }

                await Interaction.GrantConsentAsync(context, new ConsentResponse()
                {
                    Error = AuthorizationError.AccessDenied
                });

                return(Redirect(ReturnUrl));
            }

            await CheckLocalLoginAsync();

            ValidateModel();

            ExternalProviders = await GetExternalProviders();

            EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin);

            await ReplaceEmailToUsernameOfInputIfNeeds();

            var result = await SignInManager.PasswordSignInAsync(
                LoginInput.UserNameOrEmailAddress,
                LoginInput.Password,
                LoginInput.RememberMe,
                true
                );

            await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
            {
                Identity = IdentitySecurityLogIdentityConsts.Identity,
                Action   = result.ToIdentitySecurityLogAction(),
                UserName = LoginInput.UserNameOrEmailAddress
            });

            if (result.RequiresTwoFactor)
            {
                return(await TwoFactorLoginResultAsync());
            }

            if (result.IsLockedOut)
            {
                Alerts.Warning(L["UserLockedOutMessage"]);
                return(Page());
            }

            if (result.IsNotAllowed)
            {
                Alerts.Warning(L["LoginIsNotAllowed"]);
                return(Page());
            }

            if (!result.Succeeded)
            {
                Alerts.Danger(L["InvalidUserNameOrPassword"]);
                return(Page());
            }

            //TODO: Find a way of getting user's id from the logged in user and do not query it again like that!
            var user = await UserManager.FindByNameAsync(LoginInput.UserNameOrEmailAddress) ??
                       await UserManager.FindByEmailAsync(LoginInput.UserNameOrEmailAddress);

            Debug.Assert(user != null, nameof(user) + " != null");
            await IdentityServerEvents.RaiseAsync(new UserLoginSuccessEvent(user.UserName, user.Id.ToString(), user.UserName)); //TODO: Use user's name once implemented

            return(RedirectSafely(ReturnUrl, ReturnUrlHash));
        }
Esempio n. 15
0
        [UnitOfWork] //TODO: Will be removed when we implement action filter
        public override async Task <IActionResult> OnPostAsync(string action)
        {
            if (action == "Cancel")
            {
                var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl);

                if (context == null)
                {
                    return(Redirect("~/"));
                }

                await Interaction.GrantConsentAsync(context, ConsentResponse.Denied);

                return(Redirect(ReturnUrl));
            }

            await CheckLocalLoginAsync();

            ValidateModel();

            await ReplaceEmailToUsernameOfInputIfNeeds();

            var result = await SignInManager.PasswordSignInAsync(
                LoginInput.UserNameOrEmailAddress,
                LoginInput.Password,
                LoginInput.RememberMe,
                true
                );

            if (result.RequiresTwoFactor)
            {
                return(RedirectToPage("./SendSecurityCode", new
                {
                    returnUrl = ReturnUrl,
                    returnUrlHash = ReturnUrlHash,
                    rememberMe = LoginInput.RememberMe
                }));
            }

            if (result.IsLockedOut)
            {
                Alerts.Warning(L["UserLockedOutMessage"]);
                return(Page());
            }

            if (result.IsNotAllowed)
            {
                Alerts.Warning(L["LoginIsNotAllowed"]);
                return(Page());
            }

            if (!result.Succeeded)
            {
                Alerts.Danger(L["InvalidUserNameOrPassword"]);
                return(Page());
            }

            //TODO: Find a way of getting user's id from the logged in user and do not query it again like that!
            var user = await UserManager.FindByNameAsync(LoginInput.UserNameOrEmailAddress) ??
                       await UserManager.FindByEmailAsync(LoginInput.UserNameOrEmailAddress);

            Debug.Assert(user != null, nameof(user) + " != null");
            await IdentityServerEvents.RaiseAsync(new UserLoginSuccessEvent(user.UserName, user.Id.ToString(), user.UserName)); //TODO: Use user's name once implemented

            return(RedirectSafely(ReturnUrl, ReturnUrlHash));
        }