public async Task <IActionResult> Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _userStore.Queryable.SingleOrDefault(p => p.Name == model.UserName);
                if (user is null)
                {
                    ModelState.AddModelError(string.Empty, "用户不存在");
                    return(View(model));
                }

                if (!_passwordHash.VerifyHash(user.PasswordHash, model.Password))
                {
                    ModelState.AddModelError(string.Empty, "密码不正确");
                    return(View(model));
                }

                var role       = _roleStore.GetById(user.RoleId);
                var department = _departmentStore.GetById(user.DepartmentId);

                var identity = _userProfile.PopulateIdentity(user, role, department,
                                                             CookieAuthenticationDefaults.AuthenticationScheme);

                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                              new ClaimsPrincipal(identity));
            }

            return(View(model));
        }