Ejemplo n.º 1
0
        public IActionResult Login(UserViewModel model, string backto)
        {
            if (bool.TryParse(settings["NoLogin"], out bool noLogin) && noLogin)
            {
                return(NotFound());
            }


            if (!ModelState.IsValid)
            {
                return(View("Bind", model));
            }
            var req = new LoginPasswordRequest()
            {
                Login = model.UserName.Trim(), Password = model.Password.Trim()
            };
            var checkResult = _uniflow.CheckUser(req);

            if (checkResult.Result.Value.Code != "0")
            {
                ModelState.AddModelError("errorMsg", "用户名或密码错误!");
                return(View("Bind", model));
            }

            var bindId   = checkResult.Result.Value.BindId;
            var externId = model.UserName.Trim().ToLower();
            var type     = "LDAPLogin";

            HttpContext.Session.SetExternId(externId, type);

            var bindResult = _uniflow.Bind(
                new BindExternalIdRequest
            {
                ExternalId = externId,
                Type       = type,
                BindId     = bindId,
            });

            _logger.LogInformation("[HomeController] [Login] [Bind] Code:" + bindResult.Result.Value.Code);
            if (bindResult.Result.Value.Code != "0")
            {
                ModelState.AddModelError("errorMsg", bindResult.Result.Value.Message);
                return(View("Bind", model));
            }

            HttpContext.Session.SetBindId(bindId);
            HttpContext.Session.SetLdapLoginId(model.UserName);

            if (!string.IsNullOrEmpty(backto))
            {
                return(Redirect(WebUtility.UrlDecode(backto)));
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <StatusResponse> > Bind(LoginPasswordRequest req)
        {
            var(openId, type) = HttpContext.Session.GetExternId();
            _logger.LogInformation(string.Format("[WeChatAppController] [Bind] OpenId:{0},Type:{1}", openId, type));
            if (string.IsNullOrEmpty(openId))
            {
                return(new StatusResponse
                {
                    Code = Error.Codes.LoginRequired.AsString(),
                    Message = Error.Codes.LoginRequired.AsMessage(),
                });
            }

            var checkResult = await _uniflow.CheckUser(req);

            _logger.LogInformation(string.Format("[WeChatAppController] [Bind] [CheckUser] Code:{0}", checkResult.Value.Code));
            if (checkResult.Value.Code != "0")
            {
                return(new StatusResponse
                {
                    Code = checkResult.Value.Code,
                    Message = checkResult.Value.Message,
                });
            }

            var bindId = checkResult.Value.BindId;

            HttpContext.Session.SetBindId(bindId);

            var bindResult = await _uniflow.Bind(
                new BindExternalIdRequest
            {
                ExternalId = openId,
                Type       = "WeChatAppOpenID",
                BindId     = bindId,
            });

            return(new StatusResponse
            {
                Code = bindResult.Value.Code,
                Message = bindResult.Value.Message,
            });
        }