Exemple #1
0
        public async Task <IActionResult> Login(LoginViewModel loginViewModel)
        {
            if (ModelState.IsValid)
            {
                if (_userStore.ValidateCredentials(loginViewModel.UserName, loginViewModel.Password))
                {
                    TestUser user = _userStore.FindByUsername(loginViewModel.UserName);
                    AuthenticationProperties authProps = new AuthenticationProperties
                    {
                        IsPersistent = true,
                        ExpiresUtc   = DateTimeOffset.UtcNow.Add(TimeSpan.FromDays(1))
                    };

                    await AuthenticationManagerExtensions.SignInAsync(HttpContext, user.SubjectId, user.Username, authProps, user.Claims.ToArray());

                    if (Url.IsLocalUrl(loginViewModel.ReturnUrl))
                    {
                        return(Redirect(loginViewModel.ReturnUrl));
                    }
                    else if (string.IsNullOrEmpty(loginViewModel.ReturnUrl))
                    {
                        return(Redirect("~/"));
                    }
                    else
                    {
                        throw new Exception("无效的ReturnUrl");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "无效的用户名或密码");
                }
            }
            return(View(loginViewModel));
        }
Exemple #2
0
    private async Task <SignInStatus> SignInOrTwoFactor(ApplicationUser user, bool isPersistent)
    {
        SignInStatus signInStatu;
        string       str            = Convert.ToString(user.Id);
        Task <bool>  cultureAwaiter = this.UserManager.GetTwoFactorEnabledAsync(user.Id);

        if (await cultureAwaiter)
        {
            Task <IList <string> > providerAwaiter = this.UserManager.GetValidTwoFactorProvidersAsync(user.Id);
            IList <string>         listProviders   = await providerAwaiter;
            if (listProviders.Count > 0)
            {
                Task <bool> cultureAwaiter2 = AuthenticationManagerExtensions.TwoFactorBrowserRememberedAsync(this.AuthenticationManager, str);
                if (!await cultureAwaiter2)
                {
                    ClaimsIdentity claimsIdentity = new ClaimsIdentity("TwoFactorCookie");
                    claimsIdentity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", str));
                    this.AuthenticationManager.SignIn(new ClaimsIdentity[] { claimsIdentity });
                    signInStatu = SignInStatus.RequiresVerification;
                    return(signInStatu);
                }
            }
        }
        Task  cultureAwaiter3 = this.SignInAsync(user, isPersistent, false);
        await cultureAwaiter3;

        signInStatu = SignInStatus.Success;
        return(signInStatu);
    }
        public async Task <ActionResult> ExternalLoginCallback(string returnUrl)
        {
            ExternalLoginInfo loginInfo = await AuthenticationManagerExtensions.GetExternalLoginInfoAsync(this.AuthenticationManager);

            if (loginInfo == null)
            {
                return((ActionResult)this.RedirectToAction("Login"));
            }
            SignInStatus result = await this.SignInManager.ExternalSignInAsync(loginInfo, false);

            switch ((int)result)
            {
            case 0:
                return(this.RedirectToLocal(returnUrl));

            case 1:
                return((ActionResult)this.View("Lockout"));

            case 2:
                return((ActionResult)this.RedirectToAction("SendCode", (object)new
                {
                    ReturnUrl = returnUrl,
                    RememberMe = false
                }));

            default:
                // ISSUE: reference to a compiler-generated field
                if (AccountController.\u003C\u003Eo__26.\u003C\u003Ep__0 == null)
                {
                    // ISSUE: reference to a compiler-generated field
                    AccountController.\u003C\u003Eo__26.\u003C\u003Ep__0 = CallSite <Func <CallSite, object, string, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, "ReturnUrl", typeof(AccountController), (IEnumerable <CSharpArgumentInfo>) new CSharpArgumentInfo[2]
                    {
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string)null),
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, (string)null)
                    }));
                }
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                object obj1 = AccountController.\u003C\u003Eo__26.\u003C\u003Ep__0.Target((CallSite)AccountController.\u003C\u003Eo__26.\u003C\u003Ep__0, ((ControllerBase)this).get_ViewBag(), returnUrl);
                // ISSUE: reference to a compiler-generated field
                if (AccountController.\u003C\u003Eo__26.\u003C\u003Ep__1 == null)
                {
                    // ISSUE: reference to a compiler-generated field
                    AccountController.\u003C\u003Eo__26.\u003C\u003Ep__1 = CallSite <Func <CallSite, object, string, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, "LoginProvider", typeof(AccountController), (IEnumerable <CSharpArgumentInfo>) new CSharpArgumentInfo[2]
                    {
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string)null),
                        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, (string)null)
                    }));
                }
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                object obj2 = AccountController.\u003C\u003Eo__26.\u003C\u003Ep__1.Target((CallSite)AccountController.\u003C\u003Eo__26.\u003C\u003Ep__1, ((ControllerBase)this).get_ViewBag(), loginInfo.get_Login().get_LoginProvider());
                return((ActionResult)this.View("ExternalLoginConfirmation", (object)new ExternalLoginConfirmationViewModel()
                {
                    Email = loginInfo.get_Email()
                }));
            }
        }
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            var claims = new List <Claim>
            {
                new Claim("userName", "adamson"),
                new Claim("phone", "13270739236")
            };

            //SignIn(new ClaimsPrincipal(new ClaimsIdentity(claims)), "zfct");

            //await HttpContext.SignInAsync("test", new ClaimsPrincipal(new ClaimsIdentity(claims)), new AuthenticationProperties
            //{
            //    ExpiresUtc=DateTime.UtcNow.AddMinutes(30),
            //    IsPersistent=false,
            //    AllowRefresh=false
            //});


            await AuthenticationManagerExtensions.SignInAsync(HttpContext, "10", new AuthenticationProperties
            {
                ExpiresUtc   = DateTime.UtcNow.AddMinutes(30),
                IsPersistent = false,
                AllowRefresh = false
            });

            return(Redirect(model.ReturnUrl));



            var user = await _userManager.FindByNameAsync(model.UserName);

            if (user == null)
            {
                ModelState.AddModelError(nameof(model.UserName), "用户名不存在");
            }
            else
            {
                var result = await _signManager.CheckPasswordSignInAsync(user, model.PassWord, false);

                if (result.Succeeded)
                {
                    var claims1 = new List <Claim>
                    {
                        new Claim("userName", "adamson"),
                        new Claim("phone", "13270739236")
                    };

                    SignIn(new ClaimsPrincipal(new ClaimsIdentity(claims)), "zfct");
                }
                else
                {
                    ModelState.AddModelError(nameof(model.PassWord), "用户名密码不匹配");
                }
            }

            return(View());
        }
        public async Task <ActionResult> ExternalLoginConfirmation(
            ExternalLoginConfirmationViewModel model,
            string returnUrl)
        {
            if (this.get_User().Identity.IsAuthenticated)
            {
                return((ActionResult)this.RedirectToAction("Index", "Manage"));
            }
            if (this.get_ModelState().get_IsValid())
            {
                ExternalLoginInfo info = await AuthenticationManagerExtensions.GetExternalLoginInfoAsync(this.AuthenticationManager);

                if (info == null)
                {
                    return((ActionResult)this.View("ExternalLoginFailure"));
                }
                ApplicationUser applicationUser = new ApplicationUser();
                ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>)applicationUser).set_UserName(model.Email);
                ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>)applicationUser).set_Email(model.Email);
                ApplicationUser user   = applicationUser;
                IdentityResult  result = await((Microsoft.AspNet.Identity.UserManager <ApplicationUser, string>) this.UserManager).CreateAsync(user);
                if (result.get_Succeeded())
                {
                    result = await((Microsoft.AspNet.Identity.UserManager <ApplicationUser, string>) this.UserManager).AddLoginAsync(((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>)user).get_Id(), info.get_Login());
                    if (result.get_Succeeded())
                    {
                        await this.SignInManager.SignInAsync(user, false, false);

                        return(this.RedirectToLocal(returnUrl));
                    }
                }
                this.AddErrors(result);
                info   = (ExternalLoginInfo)null;
                user   = (ApplicationUser)null;
                result = (IdentityResult)null;
            }
            // ISSUE: reference to a compiler-generated field
            if (AccountController.\u003C\u003Eo__27.\u003C\u003Ep__0 == null)
            {
                // ISSUE: reference to a compiler-generated field
                AccountController.\u003C\u003Eo__27.\u003C\u003Ep__0 = CallSite <Func <CallSite, object, string, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, "ReturnUrl", typeof(AccountController), (IEnumerable <CSharpArgumentInfo>) new CSharpArgumentInfo[2]
                {
                    CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string)null),
                    CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, (string)null)
                }));
            }
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            object obj = AccountController.\u003C\u003Eo__27.\u003C\u003Ep__0.Target((CallSite)AccountController.\u003C\u003Eo__27.\u003C\u003Ep__0, ((ControllerBase)this).get_ViewBag(), returnUrl);

            return((ActionResult)this.View((object)model));
        }
Exemple #6
0
        async Task SignInOidc(string username)
        {
            var user = _users.FindByUsername(username);
            await _events.RaiseAsync(new UserLoginSuccessEvent(user.Username, user.SubjectId, user.Username));

            AuthenticationProperties props = new AuthenticationProperties();
            // issue authentication cookie with subject ID and username
            var isuser = new IdentityServerUser(user.SubjectId)
            {
                DisplayName = user.Username
            };

            await AuthenticationManagerExtensions.SignInAsync(HttpContext, isuser, props);
        }
Exemple #7
0
        public async Task <IActionResult> Login(UserLogin loginModel)
        {
            var user = dbContext.Users.FirstOrDefault(u => u.Username == loginModel.Username);

            if (user != null)
            {
                if (user.Password == loginModel.Password.Sha256())
                {
                    await AuthenticationManagerExtensions.SignInAsync(HttpContext, user.Id.ToString(), user.Username, new Claim("Name", loginModel.Username));

                    return(Redirect(loginModel.ReturnUrl));
                }
            }
            return(Redirect("~/"));
        }
        public async Task <IActionResult> Login(LoginModel loginModel)
        {
            var user    = dbContext.Users.FirstOrDefault(u => u.Username == loginModel.Username);
            var request = interaction.GetAuthorizationContextAsync(loginModel.ReturnUrl).Result;

            if (user != null)
            {
                if (user.Password == loginModel.Password.Sha256())
                {
                    await AuthenticationManagerExtensions.SignInAsync(HttpContext, user.Id.ToString(), user.Username, new Claim("Name", loginModel.Username));

                    interaction.GrantConsentAsync(request, new ConsentResponse
                    {
                        ScopesConsented = new[] { "offline_access", "api" }
                    }).Wait();
                    return(Redirect(loginModel.ReturnUrl));
                }
            }
            return(Redirect("~/"));
        }
        public async Task <IActionResult> Login(LoginViewModel loginViewModel, string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                ViewData["returnUrl"] = returnUrl;

                //var user = await _userManager.FindByEmailAsync(loginViewModel.Email);
                var user = _users.FindByUsername(loginViewModel.UserName);

                if (user == null)
                {
                    ModelState.AddModelError(nameof(loginViewModel.UserName), "UserName not exists");
                }
                else
                {
                    if (_users.ValidateCredentials(loginViewModel.UserName, loginViewModel.Password))
                    {
                        // issue authentication cookie with subject ID and username
                        var isuser = new IdentityServerUser(user.SubjectId)
                        {
                            DisplayName = user.Username,
                        };
                        //是否记住
                        var prop = new AuthenticationProperties()
                        {
                            IsPersistent = true,
                            ExpiresUtc   = DateTimeOffset.UtcNow.Add(TimeSpan.FromMinutes(30))
                        };
                        // 也可以用这个 HttpContext.SignInAsync();
                        await AuthenticationManagerExtensions.SignInAsync(HttpContext, isuser, prop);
                    }
                }
                //账号密码先不做验证,需要可以自己写
                //await _signInManager.SignInAsync(user, new AuthenticationProperties { IsPersistent = true });

                return(RedirectToLocal(returnUrl));
            }

            return(View());
        }
Exemple #10
0
        public virtual async Task <ActionResult> Register(RegisterViewModel model)
        {
            ActionResult actionResult;

            AbpUserManager <Tenant, Role, FuelWerx.Authorization.Users.User> .AbpLoginResult loginResultAsync;
            Guid guid;
            Guid guid1;
            bool flag;

            AbpUserManager <Tenant, Role, FuelWerx.Authorization.Users.User> .AbpLoginResult abpLoginResult;
            TenantLogosEditDto tenantLogosEditDto = Abp.Threading.AsyncHelper.RunSync <TenantLogosEditDto>(() => this.GetCurrentTenantLogos());
            dynamic            viewBag            = this.ViewBag;

            guid = (tenantLogosEditDto.HeaderImageId.HasValue ? tenantLogosEditDto.HeaderImageId.Value : Guid.Empty);
            viewBag.TenantCompanyHeaderImageId = guid;
            dynamic obj = this.ViewBag;

            guid1 = (tenantLogosEditDto.HeaderMobileImageId.HasValue ? tenantLogosEditDto.HeaderMobileImageId.Value : Guid.Empty);
            obj.TenantCompanyHeaderMobileImageId = guid1;
            try
            {
                this.CheckSelfRegistrationIsEnabled();
                this.CheckModelState();
                if (!model.IsExternalLogin && this.UseCaptchaOnRegistration())
                {
                    RecaptchaVerificationHelper recaptchaVerificationHelper = this.GetRecaptchaVerificationHelper();
                    if (recaptchaVerificationHelper.Response.IsNullOrEmpty())
                    {
                        throw new UserFriendlyException(this.L("CaptchaCanNotBeEmpty"));
                    }
                    if (recaptchaVerificationHelper.VerifyRecaptchaResponse() != RecaptchaVerificationResult.Success)
                    {
                        throw new UserFriendlyException(this.L("IncorrectCaptchaAnswer"));
                    }
                }
                if (!this._multiTenancyConfig.IsEnabled)
                {
                    model.TenancyName = "Default";
                }
                else if (model.TenancyName.IsNullOrEmpty())
                {
                    throw new UserFriendlyException(this.L("TenantNameCanNotBeEmpty"));
                }
                Tenant activeTenantAsync = await this.GetActiveTenantAsync(model.TenancyName);

                bool settingValueForTenantAsync = await SettingManagerExtensions.GetSettingValueForTenantAsync <bool>(this.SettingManager, "App.UserManagement.AllowSelfRegistration", activeTenantAsync.Id);

                if (!settingValueForTenantAsync)
                {
                    throw new UserFriendlyException(this.L("SelfUserRegistrationIsDisabledMessage_Detail"));
                }
                settingValueForTenantAsync = await SettingManagerExtensions.GetSettingValueForTenantAsync <bool>(this.SettingManager, "App.UserManagement.IsNewRegisteredUserActiveByDefault", activeTenantAsync.Id);

                bool flag1 = settingValueForTenantAsync;
                settingValueForTenantAsync = await SettingManagerExtensions.GetSettingValueForTenantAsync <bool>(this.SettingManager, "Abp.Zero.UserManagement.IsEmailConfirmationRequiredForLogin", activeTenantAsync.Id);

                bool flag2 = settingValueForTenantAsync;
                FuelWerx.Authorization.Users.User user = new FuelWerx.Authorization.Users.User()
                {
                    TenantId     = new int?(activeTenantAsync.Id),
                    Name         = model.Name,
                    Surname      = model.Surname,
                    EmailAddress = model.EmailAddress,
                    IsActive     = flag1
                };
                FuelWerx.Authorization.Users.User userName = user;
                ExternalLoginInfo externalLoginInfoAsync   = null;
                if (model.IsExternalLogin)
                {
                    externalLoginInfoAsync = await AuthenticationManagerExtensions.GetExternalLoginInfoAsync(this.AuthenticationManager);

                    if (externalLoginInfoAsync == null)
                    {
                        throw new ApplicationException("Can not external login!");
                    }
                    FuelWerx.Authorization.Users.User user1 = userName;
                    List <UserLogin> userLogins             = new List <UserLogin>();
                    UserLogin        userLogin = new UserLogin()
                    {
                        LoginProvider = externalLoginInfoAsync.Login.LoginProvider,
                        ProviderKey   = externalLoginInfoAsync.Login.ProviderKey
                    };
                    userLogins.Add(userLogin);
                    user1.Logins   = userLogins;
                    model.UserName = model.EmailAddress;
                    model.Password = FuelWerx.Authorization.Users.User.CreateRandomPassword();
                    if (string.Equals(externalLoginInfoAsync.Email, model.EmailAddress, StringComparison.InvariantCultureIgnoreCase))
                    {
                        userName.IsEmailConfirmed = true;
                    }
                }
                else if (model.UserName.IsNullOrEmpty() || model.Password.IsNullOrEmpty())
                {
                    throw new UserFriendlyException(this.L("FormIsNotValidMessage"));
                }
                userName.UserName = model.UserName;
                userName.Password = (new PasswordHasher()).HashPassword(model.Password);
                IActiveUnitOfWork current = this._unitOfWorkManager.Current;
                current.EnableFilter(new string[] { "MayHaveTenant" });
                this._unitOfWorkManager.Current.SetFilterParameter("MayHaveTenant", "tenantId", activeTenantAsync.Id);
                userName.Roles = new List <UserRole>();
                IQueryable <Role> roles     = this._roleManager.Roles;
                List <Role>       listAsync = await(
                    from r in roles
                    where r.IsDefault
                    select r).ToListAsync <Role>();
                foreach (Role role in listAsync)
                {
                    ICollection <UserRole> userRoles = userName.Roles;
                    userRoles.Add(new UserRole()
                    {
                        RoleId = role.Id
                    });
                }
                this.CheckErrors(await this._userManager.CreateAsync(userName));
                await this._unitOfWorkManager.Current.SaveChangesAsync();

                if (!userName.IsEmailConfirmed)
                {
                    userName.SetNewEmailConfirmationCode();
                    await this._userEmailer.SendEmailActivationLinkAsync(userName, null);
                }
                if (userName.IsActive && (userName.IsEmailConfirmed || !flag2))
                {
                    if (externalLoginInfoAsync == null)
                    {
                        loginResultAsync = await this.GetLoginResultAsync(userName.UserName, model.Password, activeTenantAsync.TenancyName);

                        abpLoginResult = loginResultAsync;
                    }
                    else
                    {
                        loginResultAsync = await this._userManager.LoginAsync(externalLoginInfoAsync.Login, activeTenantAsync.TenancyName);

                        abpLoginResult = loginResultAsync;
                    }
                    if (abpLoginResult.Result != AbpLoginResultType.Success)
                    {
                        this.Logger.Warn(string.Concat("New registered user could not be login. This should not be normally. login result: ", abpLoginResult.Result));
                        abpLoginResult = null;
                    }
                    else
                    {
                        await this.SignInAsync(abpLoginResult.User, abpLoginResult.Identity, false);

                        actionResult = this.Redirect(this.Url.Action("Index", "Application"));
                        return(actionResult);
                    }
                }
                AccountController       accountController       = this;
                RegisterResultViewModel registerResultViewModel = new RegisterResultViewModel()
                {
                    TenancyName    = activeTenantAsync.TenancyName,
                    NameAndSurname = string.Concat(userName.Name, " ", userName.Surname),
                    UserName       = userName.UserName,
                    EmailAddress   = userName.EmailAddress,
                    IsActive       = userName.IsActive,
                    IsEmailConfirmationRequired = flag2
                };
                actionResult = accountController.View("RegisterResult", registerResultViewModel);
            }
            catch (UserFriendlyException userFriendlyException1)
            {
                UserFriendlyException userFriendlyException = userFriendlyException1;
                ((dynamic)this.ViewBag).IsMultiTenancyEnabled = this._multiTenancyConfig.IsEnabled;
                dynamic viewBag1 = this.ViewBag;
                flag = (model.IsExternalLogin ? false : this.UseCaptchaOnRegistration());
                viewBag1.UseCaptcha = flag;
                ((dynamic)this.ViewBag).ErrorMessage = userFriendlyException.Message;
                actionResult = this.View("Register", model);
            }
            return(actionResult);
        }
Exemple #11
0
        public virtual async Task <ActionResult> ExternalLoginCallback(string returnUrl, string tenancyName = "")
        {
            ActionResult      action;
            ActionResult      actionResult;
            Guid              guid;
            Guid              guid1;
            ExternalLoginInfo externalLoginInfoAsync = await AuthenticationManagerExtensions.GetExternalLoginInfoAsync(this.AuthenticationManager);

            if (externalLoginInfoAsync != null)
            {
                if (tenancyName.IsNullOrEmpty())
                {
                    tenancyName = this._tenancyNameFinder.GetCurrentTenancyNameOrNull();
                    if (tenancyName.IsNullOrEmpty())
                    {
                        List <Tenant> tenants = await this.FindPossibleTenantsOfUserAsync(externalLoginInfoAsync.Login);

                        int count = tenants.Count;
                        if (count == 0)
                        {
                            actionResult = await this.RegisterView(externalLoginInfoAsync, null);

                            action = actionResult;
                            return(action);
                        }
                        else if (count == 1)
                        {
                            tenancyName = tenants[0].TenancyName;
                            tenants     = null;
                        }
                        else
                        {
                            TenantLogosEditDto tenantLogosEditDto = Abp.Threading.AsyncHelper.RunSync <TenantLogosEditDto>(() => this.GetCurrentTenantLogos());
                            dynamic            viewBag            = this.ViewBag;
                            guid = (tenantLogosEditDto.HeaderImageId.HasValue ? tenantLogosEditDto.HeaderImageId.Value : Guid.Empty);
                            viewBag.TenantCompanyHeaderImageId = guid;
                            dynamic obj = this.ViewBag;
                            guid1 = (tenantLogosEditDto.HeaderMobileImageId.HasValue ? tenantLogosEditDto.HeaderMobileImageId.Value : Guid.Empty);
                            obj.TenantCompanyHeaderMobileImageId = guid1;
                            AccountController        accountController        = this;
                            TenantSelectionViewModel tenantSelectionViewModel = new TenantSelectionViewModel()
                            {
                                Action  = this.Url.Action("ExternalLoginCallback", "Account", new { returnUrl = returnUrl }),
                                Tenants = tenants.MapTo <List <TenantSelectionViewModel.TenantInfo> >()
                            };
                            action = accountController.View("TenantSelection", tenantSelectionViewModel);
                            return(action);
                        }
                    }
                }
                AbpUserManager <Tenant, Role, FuelWerx.Authorization.Users.User> .AbpLoginResult abpLoginResult = await this._userManager.LoginAsync(externalLoginInfoAsync.Login, tenancyName);

                AbpUserManager <Tenant, Role, FuelWerx.Authorization.Users.User> .AbpLoginResult abpLoginResult1 = abpLoginResult;
                AbpLoginResultType result = abpLoginResult1.Result;
                if (result == AbpLoginResultType.Success)
                {
                    await this.SignInAsync(abpLoginResult1.User, abpLoginResult1.Identity, false);

                    if (string.IsNullOrWhiteSpace(returnUrl))
                    {
                        returnUrl = this.Url.Action("Index", "Application");
                    }
                    action = this.Redirect(returnUrl);
                }
                else
                {
                    if (result != AbpLoginResultType.UnknownExternalLogin)
                    {
                        AccountController  accountController1 = this;
                        AbpLoginResultType abpLoginResultType = abpLoginResult1.Result;
                        string             email = externalLoginInfoAsync.Email;
                        if (email == null)
                        {
                            email = externalLoginInfoAsync.DefaultUserName;
                        }
                        throw accountController1.CreateExceptionForFailedLoginAttempt(abpLoginResultType, email, tenancyName);
                    }
                    actionResult = await this.RegisterView(externalLoginInfoAsync, tenancyName);

                    action = actionResult;
                }
            }
            else
            {
                action = this.RedirectToAction("Login");
            }
            return(action);
        }
        public async Task <IActionResult> Login(LoginInputModel model, string button)
        {
            ViewData["CommonEnter"]                = _localizer["CommonEnter"];
            ViewData["CommonWelcomeText"]          = _localizer["CommonWelcomeText"];
            ViewData["ButtonsEnter"]               = _localizer["ButtonsEnter"];
            ViewData["CommonRememberMe"]           = _localizer["CommonRememberMe"];
            ViewData["CommonINN"]                  = _localizer["CommonINN"];
            ViewData["CommonPassword"]             = _localizer["CommonPassword"];
            ViewData["CommonCredentinalsNotValid"] = _localizer["CommonCredentinalsNotValid"];

            ViewData["CommonInterfaceLanguage"] = _localizer["CommonInterfaceLanguage"];

            ViewData["CommonWrongCreds"] = _localizer["CommonWrongCreds"];

            ViewData["ReturnUrl"] = _httpContextAccessor.HttpContext.Request.Query.Keys.Contains("returnUrl") ? System.Net.WebUtility.UrlEncode(_httpContextAccessor.HttpContext.Request.Query["returnUrl"].ToString()) : string.Empty;

            if (button != "login")
            {
                // the user clicked the "cancel" button
                var context = await _interaction.GetAuthorizationContextAsync(model.ReturnUrl);

                if (context != null)
                {
                    // if the user cancels, send a result back into IdentityServer as if they
                    // denied the consent (even if this client does not require consent).
                    // this will send back an access denied OIDC error response to the client.
                    await _interaction.GrantConsentAsync(context, ConsentResponse.Denied);

                    // we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null
                    return(Redirect(model.ReturnUrl));
                }
                else
                {
                    // since we don't have a valid context, then we just go back to the home page
                    return(Redirect("~/"));
                }
            }

            if (ModelState.IsValid)
            {
                // validate username/password against in-memory store
                var isUserCredentialsValid = _executor.GetQuery <IsUserCredentialsValidQuery>().Process(q => q.Execute(model.Username, model.Password));
                if (isUserCredentialsValid)
                {
                    var user = _executor.GetQuery <GetUserByNameQuery>().Process(q => q.Execute(model.Username));
                    await _events.RaiseAsync(new UserLoginSuccessEvent(user.UserName, user.Id.ToString(), user.UserName));

                    // only set explicit expiration here if user chooses "remember me".
                    // otherwise we rely upon expiration configured in cookie middleware.
                    AuthenticationProperties props = null;
                    if (AccountOptions.AllowRememberLogin && model.RememberLogin)
                    {
                        props = new AuthenticationProperties
                        {
                            IsPersistent = true,
                            ExpiresUtc   = DateTimeOffset.UtcNow.Add(AccountOptions.RememberMeLoginDuration)
                        };
                    }
                    ;

                    // issue authentication cookie with subject ID and username
                    await AuthenticationManagerExtensions.SignInAsync(HttpContext, user.Id.ToString(), user.UserName, props);

                    // make sure the returnUrl is still valid, and if so redirect back to authorize endpoint or a local page
                    // the IsLocalUrl check is only necessary if you want to support additional local pages, otherwise IsValidReturnUrl is more strict
                    if (_interaction.IsValidReturnUrl(model.ReturnUrl) || Url.IsLocalUrl(model.ReturnUrl))
                    {
                        return(Redirect(model.ReturnUrl));
                    }

                    return(Redirect("~/"));
                }

                await _events.RaiseAsync(new UserLoginFailureEvent(model.Username, "invalid credentials"));

                ModelState.AddModelError("", AccountOptions.InvalidCredentialsErrorMessage);
            }

            // something went wrong, show form with error
            var vm = await BuildLoginViewModelAsync(model);

            return(View(vm));
        }
        public async Task <ActionResult> Index(ManageController.ManageMessageId?message)
        {
            // ISSUE: reference to a compiler-generated field
            if (ManageController.\u003C\u003Eo__10.\u003C\u003Ep__0 == null)
            {
                // ISSUE: reference to a compiler-generated field
                ManageController.\u003C\u003Eo__10.\u003C\u003Ep__0 = CallSite <Func <CallSite, object, string, object> > .Create(Binder.SetMember(CSharpBinderFlags.None, "StatusMessage", typeof(ManageController), (IEnumerable <CSharpArgumentInfo>) new CSharpArgumentInfo[2]
                {
                    CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string)null),
                    CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, (string)null)
                }));
            }
            // ISSUE: reference to a compiler-generated field
            Func <CallSite, object, string, object> target = ManageController.\u003C\u003Eo__10.\u003C\u003Ep__0.Target;
            // ISSUE: reference to a compiler-generated field
            CallSite <Func <CallSite, object, string, object> > p0 = ManageController.\u003C\u003Eo__10.\u003C\u003Ep__0;
            object viewBag = ((ControllerBase)this).get_ViewBag();

            ManageController.ManageMessageId?nullable         = message;
            ManageController.ManageMessageId manageMessageId1 = ManageController.ManageMessageId.ChangePasswordSuccess;
            string str1;

            if ((nullable.GetValueOrDefault() == manageMessageId1 ? (nullable.HasValue ? 1 : 0) : 0) == 0)
            {
                nullable = message;
                ManageController.ManageMessageId manageMessageId2 = ManageController.ManageMessageId.SetPasswordSuccess;
                if ((nullable.GetValueOrDefault() == manageMessageId2 ? (nullable.HasValue ? 1 : 0) : 0) == 0)
                {
                    nullable = message;
                    ManageController.ManageMessageId manageMessageId3 = ManageController.ManageMessageId.SetTwoFactorSuccess;
                    if ((nullable.GetValueOrDefault() == manageMessageId3 ? (nullable.HasValue ? 1 : 0) : 0) == 0)
                    {
                        nullable = message;
                        ManageController.ManageMessageId manageMessageId4 = ManageController.ManageMessageId.Error;
                        if ((nullable.GetValueOrDefault() == manageMessageId4 ? (nullable.HasValue ? 1 : 0) : 0) == 0)
                        {
                            nullable = message;
                            ManageController.ManageMessageId manageMessageId5 = ManageController.ManageMessageId.AddPhoneSuccess;
                            if ((nullable.GetValueOrDefault() == manageMessageId5 ? (nullable.HasValue ? 1 : 0) : 0) == 0)
                            {
                                nullable = message;
                                ManageController.ManageMessageId manageMessageId6 = ManageController.ManageMessageId.RemovePhoneSuccess;
                                str1 = (nullable.GetValueOrDefault() == manageMessageId6 ? (nullable.HasValue ? 1 : 0) : 0) != 0 ? "Your phone number was removed." : "";
                            }
                            else
                            {
                                str1 = "Your phone number was added.";
                            }
                        }
                        else
                        {
                            str1 = "An error has occurred.";
                        }
                    }
                    else
                    {
                        str1 = "Your two-factor authentication provider has been set.";
                    }
                }
                else
                {
                    str1 = "Your password has been set.";
                }
            }
            else
            {
                str1 = "Your password has been changed.";
            }
            object         obj             = target((CallSite)p0, viewBag, str1);
            string         userId          = IdentityExtensions.GetUserId(this.get_User().Identity);
            IndexViewModel indexViewModel1 = new IndexViewModel();

            indexViewModel1.HasPassword = this.HasPassword();
            IndexViewModel indexViewModel2 = indexViewModel1;
            string         str             = await((Microsoft.AspNet.Identity.UserManager <ApplicationUser, string>) this.UserManager).GetPhoneNumberAsync(userId);

            indexViewModel2.PhoneNumber = str;
            IndexViewModel indexViewModel3    = indexViewModel1;
            bool           factorEnabledAsync = await((Microsoft.AspNet.Identity.UserManager <ApplicationUser, string>) this.UserManager).GetTwoFactorEnabledAsync(userId);

            indexViewModel3.TwoFactor = factorEnabledAsync;
            IndexViewModel        indexViewModel4   = indexViewModel1;
            IList <UserLoginInfo> userLoginInfoList = await((Microsoft.AspNet.Identity.UserManager <ApplicationUser, string>) this.UserManager).GetLoginsAsync(userId);

            indexViewModel4.Logins = userLoginInfoList;
            IndexViewModel indexViewModel5 = indexViewModel1;
            bool           flag            = await AuthenticationManagerExtensions.TwoFactorBrowserRememberedAsync(this.AuthenticationManager, userId);

            indexViewModel5.BrowserRemembered = flag;
            IndexViewModel model = indexViewModel1;

            indexViewModel2   = (IndexViewModel)null;
            str               = (string)null;
            indexViewModel3   = (IndexViewModel)null;
            indexViewModel4   = (IndexViewModel)null;
            userLoginInfoList = (IList <UserLoginInfo>)null;
            indexViewModel5   = (IndexViewModel)null;
            indexViewModel1   = (IndexViewModel)null;
            return((ActionResult)this.View((object)model));
        }