예제 #1
0
        public ResultDTO wfkLoginForDebug(LogonInfo logonInfo)
        {
            ResultDTO result = new ResultDTO();

            SSOTicket ssoTicket = GetSSOTicketFromCookie();

            logonInfo.IsSSOTicketAleadyExisted = true;

            try
            {
                string url = new SSOAuthentication().LogonWithPortalUrl(logonInfo);
                if (url == null)
                {
                    result.success = false;
                    result.message = "user name or password error!";//MessageUserPasswordError;
                }
                else
                {
                    result.success = true;
                    result.data    = url;
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
            }

            return(result);
        }
예제 #2
0
        public ResultDTO wfkLogin(string userName, string password, string productId, string productName, string orgId, string orgName, string domain, bool isInternal, string language)
        {
            ResultDTO result = new ResultDTO();

            SSOTicket ssoTicket = GetSSOTicketFromCookie();

            LogonInfo logonInfo = new LogonInfo();

            logonInfo.SSORequest  = _SSORequest;
            logonInfo.IsNT        = isInternal;
            logonInfo.OrgID       = Guid.Parse(orgId);
            logonInfo.OrgName     = orgName;
            logonInfo.ProductID   = Guid.Parse(productId);
            logonInfo.ProductName = productName;

            logonInfo.UserName = userName;

            if (ssoTicket == null &&
                _SSORequest.LoginType != LoginTypeEnum.AdminSimulate &&
                _SSORequest.LoginType != LoginTypeEnum.Debug)
            {
                logonInfo.Password = password;
                if (logonInfo.IsNT)
                {
                    logonInfo.Domain = domain;
                }
            }
            else
            {
                logonInfo.IsSSOTicketAleadyExisted = true;
            }
            logonInfo.Language = language;

            try
            {
                string url = new SSOAuthentication().LogonWithPortalUrl(logonInfo);
                if (url == null)
                {
                    result.success = false;
                    result.message = "user name or password error!";//MessageUserPasswordError;
                }
                else
                {
                    result.success = true;
                    result.data    = url;
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
            }

            return(result);
        }
예제 #3
0
        private void InitializeSSORequest()
        {
            string encrypedSSORequest = Request.QueryString["SSORequest"];
            string encryptedSSOTicket = Request.QueryString["SSOTicket"];

            if (!string.IsNullOrEmpty(encryptedSSOTicket))
            {
                try
                {
                    SSOTicket ssoTicket = _SSOHelper.DecryptSSOTicket(encryptedSSOTicket);
                    _SSOHelper.SaveSSOTicket(ssoTicket);
                    //_SSOAuth.RedirectToOnSuccessUrl(ssoTicket, _SSOAuth.GetSSOPortalUrl(ssoTicket));
                }
                catch (System.Exception ex)
                {
                    Response.Write(ex.Message);
                }
                Response.End();
            }

            if (!string.IsNullOrEmpty(encrypedSSORequest))
            {
                _SSORequest = _SSOHelper.DecryptSSORequest(encrypedSSORequest);
            }
            else
            {
                _SSORequest = null;
            }

            if (_SSORequest == null &&
                !string.IsNullOrEmpty(Request.QueryString["FromExternalSystemCall"]))
            {
                _SSORequest             = new SSORequest();
                _SSORequest.LoginType   = LoginTypeEnum.AutoLogon;
                _SSORequest.RequestDate = DateTime.UtcNow;
                if (Request.UrlReferrer != null)
                {
                    _SSORequest.ReturnUrl = Request.UrlReferrer.ToString();
                    //_SSORequest.ReturnUrl = "http://aic0-s2.qcs.qcorp.com/PermissionManagement/OrgUser/Department/DepartmentInquiry.aspx";
                }
            }

            if (_SSORequest == null ||
                _SSORequest.LoginType == LoginTypeEnum.Logout)
            {
                _SSORequest             = new SSORequest();
                _SSORequest.LoginType   = LoginTypeEnum.DirectLogin;
                _SSORequest.RequestDate = DateTime.UtcNow;
                _SSORequest.ReturnUrl   = "";
            }
        }
        //public ActionResult png()
        //{
        //     //public void ShowAuthCode(Stream stream, out string code)

        //    //Random random = new Random();
        //    //code = random.Next(1000, 9999).ToString();

        //    //Bitmap bitmap = CreateAuthCode(code);
        //    //bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Gif);

        //    var iCount = 4;
        //    var number=0;
        //    var checkCode = String.Empty;
        //    var iSeed = DateTime.Now.Millisecond;
        //    var random = new Random(iSeed);
        //    for (int i = 0; i < iCount; i++)
        //    {
        //        number = random.Next(10);
        //        checkCode += number.ToString();
        //    }
        //    Session["CheckCode"] = checkCode;
        //    if (checkCode == null || checkCode.Trim() == String.Empty)
        //        return View();
        //    int iWordWidth = 15;
        //    int iImageWidth = checkCode.Length * iWordWidth;
        //    Bitmap image = new Bitmap(iImageWidth, 20);
        //    Graphics g = Graphics.FromImage(image);
        //    try
        //    {
        //        //生成随机生成器
        //        random = new Random();
        //        //清空图片背景色
        //        g.Clear(Color.White);

        //        //画图片的背景噪音点
        //        for (int i = 0; i < 20; i++)
        //        {
        //            int x1 = random.Next(image.Width);
        //            int x2 = random.Next(image.Width);
        //            int y1 = random.Next(image.Height);
        //            int y2 = random.Next(image.Height);
        //            g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
        //        }

        //        //画图片的背景噪音线
        //        for (int i = 0; i < 2; i++)
        //        {
        //            int x1 = 0;
        //            int x2 = image.Width;
        //            int y1 = random.Next(image.Height);
        //            int y2 = random.Next(image.Height);
        //            if (i == 0)
        //            {
        //                g.DrawLine(new Pen(Color.Gray, 2), x1, y1, x2, y2);
        //            }
        //        }
        //        for (int i = 0; i < checkCode.Length; i++)
        //        {

        //            string Code = checkCode[i].ToString();
        //            int xLeft = iWordWidth * (i);
        //            random = new Random(xLeft);
        //            iSeed = DateTime.Now.Millisecond;
        //            int iValue = random.Next(iSeed) % 4;
        //            if (iValue == 0)
        //            {
        //                Font font = new Font("Arial", 13, (FontStyle.Bold | System.Drawing.FontStyle.Italic));
        //                Rectangle rc = new Rectangle(xLeft, 0, iWordWidth, image.Height);
        //                LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Blue, Color.Red, 1.5f, true);
        //                g.DrawString(Code, font, brush, xLeft, 2);
        //            }
        //            else if (iValue == 1)
        //            {
        //                Font font = new System.Drawing.Font("楷体", 13, (FontStyle.Bold));
        //                Rectangle rc = new Rectangle(xLeft, 0, iWordWidth, image.Height);
        //                LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Blue, Color.DarkRed, 1.3f, true);
        //                g.DrawString(Code, font, brush, xLeft, 2);
        //            }
        //            else if (iValue == 2)
        //            {
        //                Font font = new System.Drawing.Font("宋体", 13, (System.Drawing.FontStyle.Bold));
        //                Rectangle rc = new Rectangle(xLeft, 0, iWordWidth, image.Height);
        //                LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Green, Color.Blue, 1.2f, true);
        //                g.DrawString(Code, font, brush, xLeft, 2);
        //            }
        //            else if (iValue == 3)
        //            {
        //                Font font = new System.Drawing.Font("黑体", 13, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Bold));
        //                Rectangle rc = new Rectangle(xLeft, 0, iWordWidth, image.Height);
        //                LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Blue, Color.Green, 1.8f, true);
        //                g.DrawString(Code, font, brush, xLeft, 2);
        //            }
        //        }
        //        //////画图片的前景噪音点
        //        //for (int i = 0; i < 8; i++)
        //        //{
        //        //    int x = random.Next(image.Width);
        //        //    int y = random.Next(image.Height);
        //        //    image.SetPixel(x, y, Color.FromArgb(random.Next()));
        //        //}
        //        //画图片的边框线
        //        g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
        //        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        //        image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
        //        Response.ClearContent();
        //        Response.BinaryWrite(ms.ToArray());
        //    }
        //    finally
        //    {
        //        g.Dispose();
        //        image.Dispose();
        //    }



        //    //private Bitmap CreateAuthCode(string str)

        //    //Font fn = new Font("宋体", 12);
        //    //Brush forecolor = Brushes.Black;
        //    //Brush bgcolor = Brushes.White;
        //    //PointF pf = new PointF(5, 5);
        //    //Bitmap bitmap = new Bitmap(100, 25);
        //    //Rectangle rec = new Rectangle(0, 0, 100, 25);
        //    //Graphics gh = Graphics.FromImage(bitmap);
        //    //gh.FillRectangle(bgcolor, rec);
        //    //gh.DrawString(str, fn, forecolor, pf);
        //    //return bitmap;

        //    return View();
        //}
        public ActionResult TiackLogin(string ticket)
        {
            if (!string.IsNullOrEmpty(ticket))
            {
                string     validationTicket = new SSOService().TicketValidation(ticket);
                SSOTicket  resTicket        = JsonConvert.DeserializeObject <SSOTicket>(validationTicket);
                string     loginName        = resTicket.loginname;
                string     orgCoding        = resTicket.orgcoding;
                string     realName         = resTicket.username;
                string     userInfo         = new SSOService().GetUserInfo(loginName, orgCoding);
                YHUserInfo yhUser           = JsonConvert.DeserializeObject <YHUserInfo>(userInfo);
                if (yhUser == null)
                {
                    return(RedirectToAction("Login", "Account"));
                }
                string    orgStr  = new SSOService().GetOrgInfo(orgCoding);
                YHOrgInfo orgInfo = JsonConvert.DeserializeObject <YHOrgInfo>(orgStr);
                if (orgInfo == null)
                {
                    return(RedirectToAction("Login", "Account"));
                }
                string         orgname     = orgInfo.orgname;
                string         headpicture = yhUser.headpicture;
                LoginViewModel loginModel  = new LoginViewModel();
                loginModel.UserName = "******";
                loginModel.Password = "******";
                using (var authService = HostContext.ResolveService <AuthenticateService>(base.HttpContext))
                {
                    #region 登陆
                    var response = authService.Authenticate(new Authenticate
                    {
                        UserName   = loginModel.UserName,
                        Password   = loginModel.Password,
                        RememberMe = true
                    });
                    var session = base.SessionAs <UserSession>();
                    session.headpicture = headpicture;
                    session.orgname     = orgname;
                    session.yhRealName  = realName;
                    var authTicket = new FormsAuthenticationTicket(loginModel.UserName, loginModel.RememberMe, 120);
                    var cookie     = new HttpCookie(FormsAuthentication.FormsCookieName,
                                                    FormsAuthentication.Encrypt(authTicket));
                    cookie.HttpOnly = true;
                    cookie.Expires  = loginModel.RememberMe ? DateTime.Now.AddDays(2d) : DateTime.Now.AddMinutes(120);
                    Response.Cookies.Add(cookie);

                    if (Url.IsLocalUrl(""))
                    {
                        return(Redirect(Dy.Common.UrlHelper.Decode("")));
                    }
                    else if (loginModel.Password != ((int)GrassrootsFloodCtrlEnums.InitialPasswordEnums.初始密码).ToString() || loginModel.UserName == "dxz")
                    {
                        var userrole = HostContext.Resolve <SysService>().GET(new GetUserByIdOrUserName()
                        {
                            UserName = loginModel.UserName
                        });
                        if (null != userrole && userrole.RoleID == (int)GrassrootsFloodCtrlEnums.RoleEnums.县级用户)
                        {
                            return(RedirectToAction("CountyIndex", "Audit"));
                        }
                        else if (null != userrole && userrole.RoleID == (int)GrassrootsFloodCtrlEnums.RoleEnums.市级用户)
                        {
                            return(RedirectToAction("CityIndex", "Audit"));
                        }
                        else if (null != userrole && userrole.RoleID == (int)GrassrootsFloodCtrlEnums.RoleEnums.省级用户)
                        {
                            return(Redirect("/Leader/Index"));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        return(RedirectToAction("ModificationPsaaword", "Home"));
                    }
                    #endregion
                }
            }
            return(RedirectToAction("Login", "Account"));
        }
예제 #5
0
        private SSOTicket GetSSOTicketFromCookie()
        {
            SSOTicket ssoTicket = _SSOHelper.LoadSSOTicket(Config.Global.SSOTicketName);

            return(ssoTicket);
        }