Esempio n. 1
0
        public async Task <ActionResult> Login(LoginEditModel model)
        {
            string modelName = Request.Browser.IsMobileDevice ? "MobileLogin" : "Login";


            if (!ModelState.IsValid)
            {
                return(View(modelName, model));
            }
            string message    = string.Empty;
            var    userAdjust = _userService.FindByTrueName(model.UserName);

            if (userAdjust == null)
            {
                AddError("用户名或密码错误");
                return(View(modelName, model));
            }
            if (userAdjust.IsBlackUser == true)
            {
                AddError("该用户已被列为黑名单");
            }
            else
            {
                if (string.IsNullOrEmpty(model.Password))
                {
                    AddError("请输入密码");
                    return(View(modelName, model));
                }
                var getUser = await _userService.FindAsync(model.UserName, model.Password);

                //var result = await _userService.AddLoginAsync(getUser.Id, new UserLoginInfo("loginProvider", "providerKey"));//通过User添加登录信息
                if (getUser != null)
                {
                    _signInService.SetCurrentUser(getUser);
                    await _signInService.SignInAsync(getUser, isPersistent : false, rememberBrowser : false);

                    if (!string.IsNullOrEmpty(model.ReturnUrl) && Request.ApplicationPath != model.ReturnUrl)
                    {
                        return(Redirect(WebHelper.ResolveUrl("~/" + model.ReturnUrl)));
                    }
                    return(RedirectToAction("Index", "Admin"));
                }
                AddError("用户名或密码错误");
            }
            if (Request.Browser.IsMobileDevice)
            {
                return(View(modelName, model));
            }
            return(View(modelName, model));
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> WebPortalLogin(webLoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var getUser = await _userService.FindAsync(model.username, model.password);

            if (getUser != null)
            {
                _signInService.SetCurrentUser(getUser);
                await _signInService.SignInAsync(getUser, isPersistent : false, rememberBrowser : false);

                return(Ok("/swagger"));
            }
            return(Ok("success"));
        }