Ejemplo n.º 1
0
        /// <summary>
        /// 登录接口
        /// </summary>
        /// <param name="auth">参数</param>
        public IHttpActionResult Post([FromBody] dynamic auth)
        {
            BaseResponse <LTCUserData> response = new BaseResponse <LTCUserData>();

            if (auth == null)
            {
                response.ResultCode    = 0;
                response.IsSuccess     = false;
                response.ResultMessage = "输入的参数不正确";
                return(Ok(response));
            }
            string uid = auth.uid.Value;
            string pwd = auth.pwd.Value;

            User user = null;

            if (userCheck(uid, pwd, "", ref user))
            {
                LTCUserData clientUserData = new LTCUserData()
                {
                    UserId      = user.UserId,
                    LoginName   = user.LogonName,
                    EmpNo       = user.EmpNo,
                    EmpName     = user.EmpName,
                    EmpGroup    = user.EmpGroup,
                    JobTitle    = user.JobTitle,
                    JobType     = user.JobType,
                    OrgId       = user.OrgId,
                    RoleId      = user.RoleId,
                    RoleType    = user.RoleType,
                    SysType     = user.SysType,
                    LTCRoleType = user.LTCRoleType,
                    DCRoleType  = user.DCRoleType
                };
                response.IsSuccess     = true;
                response.ResultCode    = 200;
                response.ResultMessage = "登录成功";
                response.Data          = clientUserData;

                //生成Token
                var jwtcreated = Math.Round((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds + 5);
                var payload    = new Dictionary <string, dynamic>
                {
                    { "iss", uid },
                    { "iat", jwtcreated }
                };
                string token = JWT.JsonWebToken.Encode(payload, KMHC.SLTC.Business.Entity.Constants.SecretKey, JWT.JwtHashAlgorithm.HS256);
                response.Token = token;
            }
            else
            {
                response.IsSuccess     = false;
                response.ResultCode    = 0;
                response.ResultMessage = "输入的用户名或密码不正确";
                return(Ok(response));
            }

            return(Ok(response));
        }
Ejemplo n.º 2
0
        public void SignIn(LTCUserData clientUserData, bool createPersistentCookie)
        {
            var    now      = DateTime.Now.ToLocalTime();
            string userData = JsonConvert.SerializeObject(clientUserData);

            var ticket = new FormsAuthenticationTicket(
                1 /*version*/,
                clientUserData.UserId.ToString(),
                now,
                now.Add(ExpirationTimeSpan),
                createPersistentCookie,
                userData,
                FormsAuthentication.FormsCookiePath);

            var encryptedTicket = FormsAuthentication.Encrypt(ticket);

            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
            {
                HttpOnly = true,
                Secure   = FormsAuthentication.RequireSSL,
                Path     = FormsAuthentication.FormsCookiePath
            };

            var httpContext = HttpContext.Current;

            if (FormsAuthentication.CookieDomain != null)
            {
                cookie.Domain = FormsAuthentication.CookieDomain;
            }

            if (createPersistentCookie)
            {
                cookie.Expires = ticket.Expiration;
            }

            httpContext.Response.Cookies.Add(cookie);

            _isAuthenticated = true;
            ICustomPrincipal user = new ICustomPrincipal(clientUserData);

            _signedInUser    = user;
            httpContext.User = user;
        }
Ejemplo n.º 3
0
        void Application_PostAuthenticateRequest(object sender, EventArgs e)
        {
            System.Web.HttpContext.Current.SetSessionStateBehavior(
                SessionStateBehavior.Required);

            HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authCookie != null)
            {
                LTCUserData clientUserData = null;
                try
                {
                    FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
                    clientUserData = JsonConvert.DeserializeObject <LTCUserData>(authTicket.UserData);
                }
                catch {
                }
                if (HttpContext.Current != null && clientUserData != null)
                {
                    HttpContext.Current.User = new ICustomPrincipal(clientUserData);
                }
            }
        }
Ejemplo n.º 4
0
        private void SetCustomPrincipal(ICustomPrincipal principal)
        {
            IAuthenticationService authenticationService = IOCContainer.Instance.Resolve <IAuthenticationService>();
            LTCUserData            clientUserData        = new LTCUserData()
            {
                UserId          = principal.UserId,
                LoginName       = principal.LoginName,
                EmpNo           = principal.EmpNo,
                EmpName         = principal.EmpName,
                EmpGroup        = principal.EmpGroup,
                JobTitle        = principal.JobTitle,
                JobType         = principal.JobType,
                OrgId           = principal.OrgId,
                GovId           = principal.GovId,
                RoleId          = principal.RoleId,
                RoleType        = principal.RoleType,
                SysType         = principal.SysType,
                CurrentLoginSys = principal.CurrentLoginSys,
                LTCRoleType     = principal.LTCRoleType,
                DCRoleType      = principal.DCRoleType
            };

            authenticationService.SignIn(clientUserData, true);
        }
Ejemplo n.º 5
0
        public ActionResult login(string name, string pwd, string code, string orgId)
        {
            IOrganizationManageService organizationManageService = IOCContainer.Instance.Resolve <IOrganizationManageService>();

            ViewBag.Msg = "";
            User user = null;

            // 临时去掉验证码检验
            code = "1234";
            Session["CheckCode"] = code.ToUpper();
            BaseRequest <OrganizationFilter> request = new BaseRequest <OrganizationFilter>();

            request.PageSize = 0;
            var response = organizationManageService.QueryOrg(request);

            if (response.ResultCode == 0)
            {
                ViewBag.OrgList = response.Data;
            }
            else
            {
                ViewBag.OrgList = new List <Organization>();
            }
            //if(Constants.ServerIdentify.ContainsKey(Computer.DiskID)&&Constants.ServerIdentify[Computer.DiskID]==Computer.MacAddress)

            #region Add By Duke 为机构添加Cookies(1)

            if (Request.Cookies["orgId"] != null)
            {
                ViewBag.OrgId = Request.Cookies["orgId"].Value;
            }


            #endregion
            //if (Constants.ServerIdentify.ContainsKey(Computer.DiskID) && Constants.ServerIdentify[Computer.DiskID] == Computer.MacAddress)
            if (true)
            {
                if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(pwd) && !string.IsNullOrEmpty(orgId) && !string.IsNullOrEmpty(code) && userCheck(name, pwd, orgId, ref user) &&
                    Session["CheckCode"] != null && code.ToUpper() == Session["CheckCode"].ToString().ToUpper())
                {
                    IAuthenticationService authenticationService = IOCContainer.Instance.Resolve <IAuthenticationService>();
                    LTCUserData            clientUserData        = new LTCUserData()
                    {
                        UserId      = user.UserId,
                        LoginName   = user.LogonName,
                        EmpNo       = user.EmpNo,
                        EmpName     = user.EmpName,
                        EmpGroup    = user.EmpGroup,
                        JobTitle    = user.JobTitle,
                        JobType     = user.JobType,
                        OrgId       = user.OrgId,
                        GovId       = user.GovId,
                        RoleId      = user.RoleId,
                        RoleType    = user.RoleType,
                        SysType     = user.SysType,
                        LTCRoleType = user.LTCRoleType,
                        DCRoleType  = user.DCRoleType
                    };

                    authenticationService.SignIn(clientUserData, true);

                    if (!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
                    {
                        return(Redirect(HttpUtility.UrlDecode(Request.QueryString["ReturnUrl"])));
                    }
                    if (Array.Exists(clientUserData.SysType, e => e.Equals("LC")))
                    {
                        if (Array.Exists(clientUserData.SysType, e => e.Equals("DC")))
                        {
                            return(Redirect("/Home/NavigationForm"));
                        }
                        #region Add By Duke 为机构添加Cookies(2)
                        Response.Cookies["orgId"].Value = orgId;
                        //设置过期时间为1个月
                        Response.Cookies["orgId"].Expires = DateTime.Now.AddMonths(1);
                        #endregion
                        return(Redirect("/Home/Index"));
                    }
                    else if (Array.Exists(clientUserData.SysType, e => e.Equals("DC")))
                    {
                        return(Redirect("/Home/DCIndex"));
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(name))
                    {
                        ViewBag.Msg = "请输入正确信息";
                    }
                }
            }
            else
            {
                ViewBag.Msg = "机器未注册,请联系管理员";
            }
            return(View());
        }