Пример #1
0
        public void TestMethod1()
        {
            IUserManagementServices _userService = IoCFactory.Instance.CurrentContainer.Resolve <IUserManagementServices>();
            var users = _userService.GetUsers();

            Guid id = Guid.NewGuid();

            _userService.CreateUser(new UserInfo()
            {
                UserName     = "******",
                UserNickName = "austin",
                Tel          = "13311596779",
                PID          = "13062119890507542X",
                UniqueId     = id.ToString(),
                UserPwd      = "11223344"
            });
            //Guid id = new Guid("0604c7ab-01fe-4c52-bbc2-b1a62583e52d");
            users = _userService.GetUsers();
            _userService.ChangeUser(new UserInfo()
            {
                UserName     = "******",
                UserNickName = "austin",
                Tel          = "13910226712",
                PID          = "13062119890507542X",
                UniqueId     = id.ToString(),
                UserPwd      = "121121"
            });
            var u = _userService.GetInfo(id.ToString());

            u.UserName     = "******";
            u.UserNickName = "austin";
            u.Tel          = "13910226712";
            u.PID          = "13062119890507542X";
            u.UniqueId     = id.ToString();
            u.UserPwd      = "121121";
            _userService.ChangeUser(u);
            users = _userService.GetUsers();
            _userService.ChangePassword(id.ToString(), "121121", "QAZWSX");
            users = _userService.GetUsers();
            _userService.ResetPassWord(id.ToString());

            users = _userService.GetUsers();
        }
Пример #2
0
        public async Task <IActionResult> Login(LoginDTO model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //var tenant = RouteData.Values.SingleOrDefault(r => r.Key == "tenantid");

            //Transform the login details
            model.username = model.username;

            //Verify Username or Email
            var auser = await _userService.CheckUser(model.username);

            if (auser == null)
            {
                this.AddNotification("Invalid login attempt. please try again!", NotificationType.ERROR);
                _logger.LogWarning("Invalid login attempt. please try again!");
                return(View(model));
            }
            else if (!(await _userManager.IsEmailConfirmedAsync(auser)))
            {
                this.AddNotification("Invalid login attempt. please try again!", NotificationType.ERROR);
                return(View(model));
            }
            else if (auser.UserName.ToLower() != "admin" || auser.Email.ToLower() != "*****@*****.**")
            {
                //Get Institution Users
                var userri = (await _userService.GetUsers()).Where(v => v.usernname.ToLower() == model.username.ToLower()).FirstOrDefault();
                if (userri.isactive == false)
                {
                    return(RedirectToAction(nameof(Lockout)));
                }
                else if (userri.usercategory == "V")
                {
                }
                else if (userri.usercategory == "T")
                {
                    return(RedirectToAction(nameof(Lockout)));
                }
            }

            await _userManager.UpdateSecurityStampAsync(auser);


            //var Lockoutcheck = _context.TSysConfigurationCaps.Where(x => x.ConfigId == 5009 && x.Enabled == 1).Single();
            //if (!string.IsNullOrEmpty(Lockoutcheck.ConfigValue) && int.TryParse(Lockoutcheck.ConfigValue, out int n) == true)
            //{
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, set lockoutOnFailure: true
            var result = await _signInManager.PasswordSignInAsync(auser.UserName, model.password, isPersistent : false, lockoutOnFailure : true);

            if (result.Succeeded)
            {
                //Create Last Login Date
                await _accountService.CreateLastLoginDate(auser.Id);

                //Create Distributed Cache Cache
                // _memoryCache.SetString(CacheKeys.Entry, DateTime.UtcNow.ToString());
                //var tenantid = long.Parse(tenant.Value.ToString());
                //var appusers = (await _userService.GetTenantUsers(tenantid)).Where(x => x.appuserid == auser.Id);


                //var userid = _
                _logger.LogInformation("User logged in.");
                return(RedirectToLocal(returnUrl));
            }


            if (result.IsLockedOut)
            {
                _logger.LogWarning("User account locked out.");
                return(RedirectToAction(nameof(Lockout)));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                return(View(model));
            }
        }