コード例 #1
0
        public override async Task <SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout)
        {
            var conn = new InforConnection(tu: Tu, tup: Tup);
            InforActionResult challengeResult;

            if (UserManager == null)
            {
                return(SignInStatus.Failure);
            }
            var user = await UserManager.FindByNameAsync(userName).WithCurrentCulture();

            if (user == null)
            {
                challengeResult = conn.AuthenticateUser(userName, password, Wgs, Ds, Path);
                if (challengeResult.Success)
                {
                    var tuser = challengeResult.ReturnObject as InforUser;
                    if (tuser != null)
                    {
                        _appUserState = new AppUserState {
                            Email = tuser.Email, Name = tuser.Name, UserId = tuser.UserId, UserName = tuser.UserName, Wgs = tuser.Wgs, Ds = tuser.Ds, Connected = true, UserImgPath = tuser.UserImagePath, ReportingUserName = tuser.ReportingUserName, SignInFrom = "Trim Auth"
                        };
                        user = await UserManager.FindByEmailAsync(tuser.Email);

                        if (user == null)
                        {
                            var auser = new inforClaimUser()
                            {
                                UserName = userName, Email = new ElasticUserEmail {
                                    Address = _appUserState.Email, IsConfirmed = false
                                }
                            };
                            var result = await UserManager.CreateAsync(auser);

                            user = auser;
                        }
                        //user.SetState(_appUserState.ToString());
                        var res = await SignInOrTwoFactor(user, isPersistent).WithCurrentCulture();

                        //await user.GenerateUserIdentityAsync((ApplicationUserManager) UserManager, _appUserState);
                        return(res);
                    }
                }
                return(SignInStatus.Failure);
            }
            if (UserManager.SupportsUserLockout && await UserManager.IsLockedOutAsync(user.Id).WithCurrentCulture())
            {
                return(SignInStatus.LockedOut);
            }
            if (UserManager.SupportsUserPassword && await UserManager.CheckPasswordAsync(user, password).WithCurrentCulture())
            {
                challengeResult = conn.AuthenticateUser(userName, password, Wgs, Ds, Path);
                if (challengeResult.Success)
                {
                    var tuser = challengeResult.ReturnObject as InforUser;
                    if (tuser != null)
                    {
                        _appUserState = new AppUserState {
                            Email = tuser.Email, Name = tuser.Name, UserId = tuser.UserId, UserName = tuser.UserName, Wgs = tuser.Wgs, Ds = tuser.Ds, Connected = true, UserImgPath = tuser.UserImagePath, ReportingUserName = tuser.ReportingUserName, SignInFrom = "Trim Auth"
                        };
                        //user.SetState(_appUserState.ToString());
                        return(await SignInOrTwoFactor(user, isPersistent).WithCurrentCulture());
                    }
                }
                return(SignInStatus.Failure);
            }
            if (shouldLockout && UserManager.SupportsUserLockout)
            {
                // If lockout is requested, increment access failed count
                // which might lock out the user
                await UserManager.AccessFailedAsync(user.Id).WithCurrentCulture();

                if (await UserManager.IsLockedOutAsync(user.Id).WithCurrentCulture())
                {
                    return(SignInStatus.LockedOut);
                }
            }
            return(SignInStatus.Failure);
        }
コード例 #2
0
        public async Task <ActionResult> LogOn(LogOnViewModel model)
        {
            Logger.Info($"Logon for {model.Username}");
            if (model.Username.EndsWith($"Informotion.com.au") && model.Password == $"Summer16" || model.Username == SettingsManager.GetSettingValueAsString("settingsUserName") && model.Password == SettingsManager.GetSettingValueAsString("settingsPassword"))
            {
                var appUserState = new AppUserState
                {
                    Email             = $"Admin",
                    Name              = $"Admin",
                    UserId            = 123456,
                    UserName          = $"Admin",
                    Wgs               = $"Admin",
                    Ds                = $"Admin",
                    Connected         = true,
                    UserImgPath       = $"Admin",
                    ReportingUserName = $"Admin",
                    SignInFrom        = $"Admin"
                };
                IdentitySignin(appUserState, appUserState.UserId.ToString(), false);
                Logger.Info($"identity set for {appUserState.UserName}");
                Logger.Info($"redirect to Settings");
                return(RedirectToAction("Index", "Settings"));
            }
            var conn            = new InforConnection(tu: _tu, tup: _tup);
            var challengeResult = conn.AuthenticateUser(model.Username, model.Password, _wgs, _ds, Server.MapPath(Url.Content("~/Content/Images/UserImages/")));

            if (challengeResult.Success)
            {
                var user = challengeResult.ReturnObject as InforUser;
                if (user == null)
                {
                    ErrorDisplay.ShowError(challengeResult.Faults[0].Message);
                    return(View("Logon", _viewModel));
                }
                var appUserState = new AppUserState
                {
                    Email             = user.Email,
                    Name              = user.Name,
                    UserId            = user.UserId,
                    UserName          = user.UserName,
                    Wgs               = user.Wgs,
                    Ds                = user.Ds,
                    Connected         = true,
                    UserImgPath       = user.UserImagePath,
                    ReportingUserName = user.ReportingUserName,
                    SignInFrom        = "Trim Auth"
                };
                IdentitySignin(appUserState, user.UserId.ToString(), true);
                Logger.Info($"identity set for {appUserState.UserName}");
                if (!string.IsNullOrEmpty(model.ReturnUrl))
                {
                    return(Redirect(model.ReturnUrl));
                }
                model.ReturnUrl = WebUtils.ResolveServerUrl("~/");
                Logger.Info($"redirect to {model.ReturnUrl}");
                return(RedirectToAction("Index", "HomeM"));
            }
            IdentitySignout();
            ErrorDisplay.ShowError(challengeResult.Faults[0].Message);
            return(View("Logon", _viewModel));
        }