public async Task <IActionResult> Logon(LoginVM loginVM)
        {
            if (ModelState.IsValid)
            {
                // 提取用户对象
                var user = await _userManager.FindByNameAsync(loginVM.UserName);

                if (user != null)
                {
                    // 检查用户是否被锁定
                    if (user.LockoutEnabled)
                    {
                        // 登录系统
                        var result = await _signInManager.PasswordSignInAsync(user, loginVM.Password, loginVM.RememberMe, lockoutOnFailure : false);

                        if (result.Succeeded)
                        {
                            var applicationUserVM = _boVMService.GetVM(user);
                            if (!String.IsNullOrEmpty(loginVM.ReturnUrl))
                            {
                                return(Redirect(loginVM.ReturnUrl));
                            }
                            else
                            {
                                return(RedirectToAction("Index", "Home"));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("Password", "输入密码错误,请核实后重新输入。");
                            return(View(loginVM));
                        }
                    }
                    else
                    {
                        ViewData["LoginStatusString"] = "用户已被锁定,无法登录!";
                        return(View(loginVM));
                    }
                }
                else
                {
                    ViewData["LoginStatusString"] = "用户名或者密码错误。";
                    return(View(loginVM));
                }
            }
            ViewData["LoginStatusString"] = "";
            return(View(loginVM));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 站点入口方法:需要判断用户是否已经登录,如果已经登录,则显示用户登录信息,否则提供登录模块
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> Index()
        {
            //await ApplicationDataSeed.ForRolesAndUsers(_roleManager,_userManager);

            var userVM = new ApplicationUserVM();

            #region 获取当前的访问用户信息
            var userIdentity = User.Identity;
            if (!String.IsNullOrEmpty(userIdentity.Name))
            {
                var user = await _userManager.FindByNameAsync(userIdentity.Name);

                userVM = await _boVMService.GetVM(user);
            }
            #endregion

            ViewData["ApplicationUserVM"] = userVM;
            ViewData["LoginVM"]           = new LoginVM();

            return(View());
        }
        /// <summary>
        /// 获取当前用户信息
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> Index()
        {
            var boVM            = new ApplicationUserVM();
            var passwordResetVM = new ApplicationUserPasswordResetVM();

            #region 获取当前的访问用户信息
            var userIdentity = User.Identity;
            if (!String.IsNullOrEmpty(userIdentity.Name))
            {
                var user = await _userManager.FindByNameAsync(userIdentity.Name);

                boVM = await _boVMService.GetVM(user);

                passwordResetVM.UserId = user.Id;
            }
            #endregion

            ViewData["ApplicationUserPasswordResetVM"] = passwordResetVM;
            ViewData["ModuleName"]   = "个人信息管理";
            ViewData["FunctionName"] = "个人系统信息";
            return(View(boVM));
        }
Exemplo n.º 4
0
        public async Task <PartialViewResult> CreateOrEdit(Guid id)
        {
            var functionName = "新建系统用户数据";
            var boVM         = await _boVMService.GetVM(id);

            if (!boVM.IsNew)
            {
                functionName = "编辑系统用户数据:" + boVM.UserName + "(" + boVM.Name + ")";
            }

            ViewData["ModuleName"]   = "系统用户管理";
            ViewData["FunctionName"] = functionName;

            if (boVM.IsNew)
            {
                return(PartialView("_Create", boVM));
            }
            else
            {
                return(PartialView("_Edit", boVM));
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Login(LoginVM loginVM)
        {
            if (ModelState.IsValid)
            {
                // 提取用户对象
                //var user = await _userManager.FindByEmailAsync(loginVM.Email);
                var user = await _userManager.FindByNameAsync(loginVM.UserName);

                if (user != null)
                {
                    // 检查用户是否被锁定
                    if (user.LockoutEnabled)
                    {
                        // 登录系统
                        var result = await _signInManager.PasswordSignInAsync(user, loginVM.Password, false, lockoutOnFailure : false);

                        if (result.Succeeded)
                        {
                            var applicationUserVM = _boVMService.GetVM(user);
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            ModelState.AddModelError("Password", "你输入的用户密码错误,请核实后重新输入。");
                            return(View(loginVM));
                        }
                    }
                    else
                    {
                        ViewData["LoginStatusString"] = "你的用户名已经被锁定了,无法登录。";
                        return(View(loginVM));
                    }
                }
                else
                {
                    ViewData["LoginStatusString"] = "用户名或者密码错误。";
                    return(View(loginVM));
                }
            }
            ViewData["LoginStatusString"] = "";
            return(View(loginVM));
        }