Ejemplo n.º 1
0
        public void RefreshVisitList()
        {
            CRM_VisitLogic    cvs   = new CRM_VisitLogic();
            SystemUserLogic   sul   = new SystemUserLogic();
            CRM_CustomerLogic ccusl = new CRM_CustomerLogic();
            CRM_ContactLogic  cconl = new CRM_ContactLogic();
            var showvisitlist       = from visit in cvs.GetAll()
                                      join customer in ccusl.GetAll()
                                      on visit.CusId equals customer.Id
                                      join user in sul.GetAllUsers()
                                      on visit.VSuperiorId equals user.Id
                                      join contact in cconl.GetAll()
                                      on visit.ConId equals contact.Id
                                      select new
            {
                Id                  = visit.Id,
                CusCode             = customer.CusCode,
                CusName             = customer.CusName,
                UserName            = user.UserName,
                ContactName         = contact.Name,
                VTitle              = visit.VTitle,
                VContent            = visit.VContent,
                VType               = visit.VType,
                VPlanDate           = visit.VPlanDate,
                VCompleteDate       = visit.VCompleteDate,
                VSuperiorDate       = visit.VSuperiorDate,
                VSuperiorSuggestion = visit.VSuperiorSuggestion,
                VStatus             = visit.VStatus
            };

            this.dgvVisitInfo.DataSource = showvisitlist.ToList();
        }
Ejemplo n.º 2
0
        public ActionResult ApiLogin(string userCode, string password)
        {
            if (string.IsNullOrEmpty(userCode) || string.IsNullOrEmpty(password))
            {
                return(Unauthorized("账号和密码没有输入!"));
            }
            try
            {
                byte[] buffer          = Convert.FromBase64String(password);
                string decodedPasswrod = System.Text.Encoding.ASCII.GetString(buffer);

                SecurityTokenDescriptor tokenDescriptor = SystemUserLogic.LoginWithApi(userCode, decodedPasswrod, this.HttpContext);
                var tokenHandler = new JwtSecurityTokenHandler();
                var token        = tokenHandler.CreateToken(tokenDescriptor);
                var tokenString  = tokenHandler.WriteToken(token);

                HttpContext.Response.Headers.Add("Authorization", "Bearer " + tokenString);
                return(Ok(new
                {
                    access_token = tokenString,
                    token_type = "Bearer",
                    profile = new
                    {
                        sid = userCode,
                        name = userCode,
                        auth_time = new DateTimeOffset(tokenDescriptor.Expires.Value.AddDays(-7)).ToUnixTimeSeconds(),
                        expires_at = new DateTimeOffset(tokenDescriptor.Expires.Value).ToUnixTimeSeconds()
                    }
                }));
            }
            catch (Exception ex)
            {
                return(Unauthorized(ex.Message));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 初始化用户列表显示
        /// </summary>
        public void DisplayUserList()
        {
            //设置属性对应的字段
            SystemUserLogic sul2 = new SystemUserLogic();

            //填充数据
            dgvUserSetting.DataSource = sul2.GetAllUsers();
        }
Ejemplo n.º 4
0
        private void LoginWithBackgroundService()
        {
            SystemUser user = new SystemUser();

            user.UserCode = Guid.NewGuid().ToString();
            user.Email    = "*****@*****.**";
            user.UserName = "******";
            SecurityTokenDescriptor tokenDescriptor = SystemUserLogic.CreateDescriptor(user);
            var tokenHandler = new JwtSecurityTokenHandler();
            var token        = tokenHandler.CreateToken(tokenDescriptor);

            _BackgroundTokenString = tokenHandler.WriteToken(token);
        }
Ejemplo n.º 5
0
        public ActionResult Login(string userCode, string password)
        {
            if (string.IsNullOrEmpty(userCode) || string.IsNullOrEmpty(password))
            {
                this.TempData[LoginController.ID_ERROR_MESSAGE] = "账号和密码都必须输入!";
                return(RedirectToAction("Index"));
            }
            try
            {
                SecurityTokenDescriptor tokenDescriptor = SystemUserLogic.LoginWithApi(userCode, password, this.HttpContext);
                var tokenHandler = new JwtSecurityTokenHandler();
                var token        = tokenHandler.CreateToken(tokenDescriptor);
                var tokenString  = tokenHandler.WriteToken(token);
                HttpContext.Session.Set(GlobalConstants.AUTHROIZATION_SESSION_KEY, System.Text.Encoding.UTF8.GetBytes(tokenString));

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                this.TempData[ID_ERROR_MESSAGE] = ex.Message;
                return(RedirectToAction("Index"));
            }
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string authenticationTokenHeaderIndex = "authenticationToken";
            string deviceUUIDHeaderIndex          = "deviceUUID";
            string environmentHeaderIndex         = "environment";

            bool isAjax = true;

            if (!isAjax)
            {
            }
            else
            {
                string authenticationToken = "";
                string deviceUUID          = "";
                string urlBit      = "";
                string environment = "MobileApp";
                if (HttpContext.Current.Request.HttpMethod == "GET")
                {
                    environment = "WebApp";
                }
                string declarationsCycleMode = "current";
                string feedBackMessage       = "Invalid User Access.";
                bool   isValid = true;

                string usercode = "Unknown";
                string username = "******";

                try
                {
                    urlBit = (filterContext.RouteData.Route as System.Web.Routing.Route).Url;
                    if (HttpContext.Current.Request.Headers[authenticationTokenHeaderIndex] != null)
                    {
                        authenticationToken = HttpContext.Current.Request.Headers[authenticationTokenHeaderIndex].ToString();
                    }
                    if (HttpContext.Current.Request.Headers[deviceUUIDHeaderIndex] != null)
                    {
                        deviceUUID = HttpContext.Current.Request.Headers[deviceUUIDHeaderIndex].ToString();
                    }
                    if (HttpContext.Current.Request.Headers[environmentHeaderIndex] != null)
                    {
                        environment = HttpContext.Current.Request.Headers[environmentHeaderIndex].ToString();
                    }
                    if ((authenticationToken.Trim() == "" || deviceUUID.Trim() == "") && (environment == "MobileApp"))
                    {
                        isValid         = false;
                        feedBackMessage = "Invalid User Access.";
                    }
                    if (isValid)
                    {
                        AuthenticatedUserModel user = null;

                        if (user == null)
                        {
                            isValid = true;
                        }
                        else
                        {
                            var prmList = filterContext.ActionParameters;
                            foreach (var prm in prmList)
                            {
                                var prmObj = prm.Value as GenericRequestModel;
                                if (prmObj != null)
                                {
                                    usercode = user.LoginUserName;
                                    username = user.FullName;

                                    prmObj.SessionUserName  = user.FullName;
                                    prmObj.SessionUserId    = user.UserId;
                                    prmObj.DeviceIdentifier = deviceUUID;
                                    prmObj.RootWebFolder    = HttpContext.Current.Server.MapPath("~");
                                    prmObj.RootAPIURL       = HttpContext.Current.Request.Url.AbsoluteUri.Replace(
                                        HttpContext.Current.Request.RawUrl, "");
                                    if (!prmObj.RootAPIURL.EndsWith("/"))
                                    {
                                        prmObj.RootAPIURL += "/";
                                    }
                                    if (prmObj.RootAPIURL.Contains("localhost"))
                                    {
                                    }
                                    else if (prmObj.RootAPIURL.Contains("testza"))
                                    {
                                    }
                                    else
                                    {
                                        prmObj.RootAPIURL += "api";
                                    }

                                    prmObj.Environment = environment;
                                }
                            }
                            if (IsOpenMethod)
                            {
                                isValid = IsOpenMethod;
                            }
                            else
                            {
                                isValid = SystemUserLogic.UserHasAccessToLocation(user, Roles);
                            }
                        }
                    }
                }
                catch (Exception error)
                {
                    isValid         = false;
                    feedBackMessage = error.ToString();
                }

                if (!isValid)
                {
                    GenericResultModel result = new GenericResultModel()
                    {
                        HasError = true, Feedback = feedBackMessage, IsValidationError = false,
                        IsAuthenticationError = true, FullName = username, WindowsUser = usercode
                    };
                    filterContext.Result = new JsonResult
                    {
                        Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                }
                else
                {
                    base.OnActionExecuting(filterContext);
                }
            }
        }