示例#1
0
        public ActionResult GetProjectsByUsername([DataSourceRequest] DataSourceRequest request, string username = "")
        {
            var projectMainViewModel = new ProjectMainViewModel();

            PopulateDataIntoViewModel(projectMainViewModel);

            ViewBag.AdminMenuVisibilty = false;

            string userName = _cookieHelper.GetCookie("userid");

            if (username != "")
            {
                userName = username;
            }

            var projects = this._projectService.GetProjectsByUsername(userName).ToList();

            var projectViewModels = new List <ProjectViewModel>();

            foreach (var project in projects)
            {
                var projectSummary = GetProjectSummaryDetails(project.ProjectId);
                projectSummary.UserName = username;
                projectViewModels.Add(projectSummary);
            }

            return(Json(projectViewModels.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public IActionResult Cart()
        {
            CartViewModel model = new CartViewModel();
            List <CartServiceViewModel> cartServiceViewModels = new List <CartServiceViewModel>();
            var cartCookie = _cookieHelper.GetCookie("_cart");

            if (cartCookie != null)
            {
                cartServiceViewModels = (List <CartServiceViewModel>)cartCookie;
            }
            model.cartServiceViewModels = cartServiceViewModels;
            return(PartialView(model));
        }
 public OrdersController(IWebApiCaller webApiCaller, ICookieHelper cookieHelper, ISecurityHelper securityHelper)
 {
     WebApiCaller   = webApiCaller;
     CookieHelper   = cookieHelper;
     SecurityHelper = securityHelper;
     CurrentUser    = SecurityHelper.GetSessionUser(CookieHelper.GetCookie <string>("CurrentUser"));
 }
示例#4
0
        // DELETE api/<CoursesController>/5



        private ResultState CheckCookie()
        {
            string getToken = _helper.GetCookie("token");

            if (getToken == null)
            {
                return(new ResultState(false, "请登录", 0, null));
            }
            var devidedToken = getToken.Split(",");

            try
            {
                var student = _context.students.Find(int.Parse(devidedToken[0]));
                if (student != null)
                {
                    int isAdmin = student.isAdmin + 1;
                    return(new ResultState(true, "验证成功", isAdmin, null));
                }
                else
                {
                    return(new ResultState(true, "无效Cookie", 0, null));
                }
            }
            catch (Exception)
            {
                return(new ResultState(false, "无效Cookie", 0, null));
            }
        }
        public async Task Invoke(HttpContext context)
        {
            try
            {
                IHeaderDictionary headers       = context.Request.Headers;
                ICookieHelper     _cookieHelper = context.GetInstanceFromContext <ICookieHelper>();
                IJWTHelper        _JWTHelper    = context.GetInstanceFromContext <IJWTHelper>();
                ICryptoHelper     _cryptoHelper = context.GetInstanceFromContext <ICryptoHelper>();

                string cookie = _cookieHelper.GetCookie(_cookieHelper.GetCookieName());

                // Get JWT from request header.
                string hdrJWT = _JWTHelper.getBearerHeaderValue(headers);

                // If header doesn't have a JWT but the cookie does, add the cookie's JWT to the header.
                if (String.IsNullOrEmpty(hdrJWT) && !String.IsNullOrEmpty(cookie))
                {
                    string decryptedJWTToken = _cryptoHelper.decrypt(cookie);
                    _JWTHelper.setClaimsFromCookie(decryptedJWTToken);
                    string bearerToken = string.Format("Bearer {0}", cookie);
                    headers.SetCommaSeparatedValues("Authorization", bearerToken);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                await _next.Invoke(context);
            }
        }
示例#6
0
        public ViewResult UpdateProfile(UpdateProfileModel viewModel)
        {
            var currentUser = CookieHelper.GetCookie <string>("CurrentUser");

            var updateProfileModel = WebApiCaller.PostAsync <UpdateProfileModel>("WebApi:Authenticate:FindUserProfile", new FindUserRequestModel {
                Username = currentUser
            });

            return(View("ChangePassword", updateProfileModel));
        }
示例#7
0
        public ViewResult ChangePasswordIndex(AuthenticateViewModel viewModel)
        {
            var loggedInUser = CookieHelper.GetCookie <UserModel>("LoggedInUser");

            if (loggedInUser != null)
            {
                return(View("ChangePassword", viewModel));
            }

            return(View("Index", viewModel)); // Login screen
        }
示例#8
0
        public ActionResult CreateProject(ProjectViewModel projectViewModel, string StatusId)
        {
            string userName = _cookieHelper.GetCookie("userid");

            if (projectViewModel != null && ModelState.IsValid)
            {
                var project = new Project()
                {
                    ProjectId          = projectViewModel.ProjectId,
                    ProjectName        = projectViewModel.ProjectName,
                    StartDate          = projectViewModel.StartDate,
                    PlannedEndDate     = projectViewModel.PlannedEndDate,
                    IsActive           = projectViewModel.IsActive,
                    ProjectDescription = projectViewModel.ProjectDescription
                };

                var projectMainViewModel = new ProjectMainViewModel();
                PopulateDataIntoViewModel(projectMainViewModel);

                int projectId = this._projectService.AddProject(project, userName);

                if (projectId == 0)
                {
                    ModelState.AddModelError("DuplicateProjectName", "Please enter a unique name for the project.");
                    return(PartialView("_CreateProject", projectViewModel));
                }
                else if (projectId == -1)
                {
                    ModelState.AddModelError("SaveError", "Error in Saving Data.");
                    return(PartialView("_CreateProject", projectViewModel));
                }

                return(Json(new { Status = "Success", Message = "Project created successfully." }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(PartialView("_CreateProject", projectViewModel));
            }
        }
示例#9
0
        public T PostAsync <T>(string urlConfig, object requestModel)
        {
            if (Convert.ToBoolean(Configuration["MockData.Enabled"]))
            {
                MockWebApi = new MockWebApi();

                var incoming  = JsonConvert.SerializeObject(requestModel).ToUpper();
                var responses = JsonConvert.SerializeObject(MockWebApi.Responses.First(x => x.WepApiUrl == urlConfig).RequestModel).ToUpper();

                if (MockWebApi.Responses.Any(x => x.WepApiUrl == urlConfig))
                {
                    return((T)MockWebApi.Responses.FirstOrDefault(x => x.WepApiUrl == urlConfig && JsonConvert.SerializeObject(x.RequestModel).ToUpper() == JsonConvert.SerializeObject(requestModel).ToUpper()).ResponseContent);
                }
            }

            var webApiUrl = Configuration[urlConfig];

            var CurrentUser = SecurityHelper.GetSessionUser(CookieHelper.GetCookie <UserModel>("CurrentUser"));

            if (CurrentUser != null)
            {
                webApiUrl += "?token=" + CurrentUser.ApiSessionToken;
            }

            var webApiResponse = PostRequest(webApiUrl, requestModel);

            Exception innerException = null;

            try
            {
                innerException = JsonConvert.DeserializeObject <Exception>(webApiResponse.Result.ResponseContent);
            }
            catch { }

            if (webApiResponse.Result.ResponseCode != ((int)HttpStatusCode.OK).ToString())
            {
                throw new Exception("Error occurred at " + urlConfig.ToLower() + " - " + innerException?.Message, innerException);
            }

            return(JsonConvert.DeserializeObject <T>(webApiResponse.Result.ResponseContent));
        }
示例#10
0
        public ActionResult Login(string returnUrl)
        {
            using (var context = _dataContextFactory.Create(ConnectionType.Ip))
            {
                context.Query <Organization>().Count();
            }


            string name = string.Empty;

            name = _cookieHelper.GetCookie("userid");

            if (name != null && name != string.Empty)
            {
                string role = this._activeDirectoryService.VerifyGroupPolicy(name);

                if (role == Constants.AdminRole)
                {
                    return(RedirectToLocal(returnUrl, Constants.AdminRole));
                }
                // check if user is member of that user group
                else if (role == Constants.UserRole)
                {
                    return(RedirectToLocal(returnUrl, Constants.UserRole));
                }
                else
                {
                    // user does not belong to active directory
                    _logger.Log(string.Format("User is not found in the active directory: {0}", name), LogCategory.Warning, GetUserIdentifiableString(name));
                }
            }
            else
            {
                _logger.Log(string.Format("Failed login attempt for user : {0}", name), LogCategory.Information, GetUserIdentifiableString(name));
            }

            return(View());
        }
 public RolesController(IWebApiCaller webApiCaller, ICookieHelper cookieHelper)
 {
     WebApiCaller = webApiCaller;
     CookieHelper = cookieHelper;
     CurrentUser  = CookieHelper.GetCookie <UserModel>("LoggedInUser");
 }
 public string GetCookid()
 {
     return(_helper.GetCookie("cookieHelperKey"));
 }