Ejemplo n.º 1
0
        // GET: /Account/LogOff
        public ActionResult LogOff(string returnUrl)
        {
            int userPK = SecurityHelper.GetUserPKFromCookie();

            FormsAuthentication.SignOut();

            if (Session != null)
            {
                Session.Abandon();

                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, "");
                cookie.Expires = DateTime.Now.AddYears(-1);
                Response.Cookies.Add(cookie);
            }

            IUserActivitiesRepository userActivitiesRepository = new UserActivitiesRepository(db);

            if (userPK != 0)
            {
                UserActivity userActivity = UserActivityView.LogUserActivity(userPK, "Izlazak iz sustava.", DateTime.Now);

                userActivitiesRepository.Add(userActivity);
                userActivitiesRepository.SaveChanges();
            }

            return(RedirectToAction("Index", "Account", new { returnUrl = returnUrl }));
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            IUserActivitiesRepository userActivitiesRepository = new UserActivitiesRepository(db);
            IUsersRepository          usersRepository          = new UsersRepository(db);

            int    page       = !String.IsNullOrWhiteSpace(Request.QueryString["page"]) ? Convert.ToInt32(Request.QueryString["page"]) : 1;
            int    pageSize   = !String.IsNullOrWhiteSpace(Request.QueryString["pageSize"]) ? Convert.ToInt32(Request.QueryString["pageSize"]) : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ResultsPerPage"]);
            string sortOrder  = !String.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC";
            string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "UserActivityPK";
            string ordering   = sortColumn + " " + sortOrder;

            ordering = ordering.Trim();

            int numberOfRecords = 0;
            IQueryable <UserActivityView> userActivities = UserActivityView.GetHomeView(userActivitiesRepository.GetValid(), usersRepository.GetValid())
                                                           .OrderBy(ordering);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"].ToString();
                userActivities = userActivities.Where(ua => ua.ActivityDescription.Contains(searchString) || ua.UserFullName.Contains(searchString));
            }

            numberOfRecords = userActivities.Count();
            userActivities  = userActivities.Page(page, pageSize);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"].ToString();
                ViewData["numberOfRecords"] = numberOfRecords;
            }
            else
            {
                ViewData["numberOfRecords"] = numberOfRecords;
            }

            int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize;

            if (page > numberOfPages)
            {
                string url = LinkHelper.getQueryStringArray(new string[] { "page" });
                return(Redirect("UserActivity?" + url + "page=" + numberOfPages));
            }
            else
            {
                return(View("Index", userActivities.ToList()));
            }
        }
Ejemplo n.º 3
0
        public ActionResult LogOn(LogOn model, string returnUrl)
        {
            IUsersRepository usersRepository = new UsersRepository(db);
            IRolesRepository rolesRepository = new RolesRepository(db);

            if (ModelState.IsValid)
            {
                if (usersRepository.ValidateUser(model.UserName, model.Password))
                {
                    string[] roles    = rolesRepository.GetRoleNamesByUsername(model.UserName);
                    string   userData = String.Join(", ", roles);

                    User user = usersRepository.GetUserByUsername(model.UserName);

                    userData += "|" + user.UserPK;

                    double sessionMinutes = ((SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState")).Timeout.TotalMinutes;

                    FormsAuthenticationTicket fAuthTicket = new FormsAuthenticationTicket(1, user.Username, DateTime.Now, DateTime.Now.AddMinutes(sessionMinutes), model.RememberMe, userData, FormsAuthentication.FormsCookiePath);
                    string     hashCookies = FormsAuthentication.Encrypt(fAuthTicket);
                    HttpCookie cookie      = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);
                    Response.Cookies.Add(cookie);

                    IUserActivitiesRepository userActivitiesRepository = new UserActivitiesRepository(db);

                    UserActivity userActivity = UserActivityView.LogUserActivity(user.UserPK, "Ulazak u sustav.", DateTime.Now);

                    userActivitiesRepository.Add(userActivity);
                    userActivitiesRepository.SaveChanges();

                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "ToDoList"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Kriva kombinacija korisničkog imena i lozinke.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 4
0
        private string GetContactActivityPage(UserActivityView ctrlUserActivity, Contact contact, int messageCount)
        {
            var page = new Page();
            var form = new HtmlForm {
                EnableViewState = false
            };

            ctrlUserActivity = (UserActivityView)page.LoadControl(PathProvider.GetFileStaticRelativePath("SocialMedia/UserActivityView.ascx"));
            InitTwitter(ctrlUserActivity, contact);
            if (ctrlUserActivity.TwitterInformation.UserAccounts.Count == 0)
            {
                page.Controls.Add(new EmptyScreenControl
                {
                    ImgSrc     = WebImageSupplier.GetAbsoluteWebPath("empty_screen_twitter.png", ProductEntryPoint.ID),
                    Header     = CRMSocialMediaResource.EmptyContentTwitterAccountsHeader,
                    Describe   = CRMSocialMediaResource.EmptyContentTwitterAccountsDescribe,
                    ButtonHTML = String.Format(@"<a class='linkAddMediumText' href='javascript:void(0);'
                                                    onclick='ASC.CRM.SocialMedia.FindTwitterProfiles(jq(this),""{0}"", 1, 9);'>{1}</a>",
                                               contact is Company ? "company" : "people",
                                               CRMSocialMediaResource.LinkTwitterAccount)
                });

                return(RenderPage(page));
            }

            ctrlUserActivity.MessageCount = messageCount;
            form.Controls.Add(ctrlUserActivity);
            page.Controls.Add(form);

            var executedPage = RenderPage(page);

            if (ctrlUserActivity.LoadedMessageCount == 0 && ctrlUserActivity.LastException == null)
            {
                page = new Page();

                //TODO
                page.Controls.Add(new EmptyScreenControl
                {
                    Header = CRMCommonResource.NoLoadedMessages,
                });
                executedPage = RenderPage(page);
            }

            return(executedPage);
        }
Ejemplo n.º 5
0
        public string GetContactActivity(int contactID, int messageCount)
        {
            UserActivityView ctrlUserActivity = null;

            try
            {
                //Process authorization
                if (!ProcessAuthorization(HttpContext.Current))
                {
                    AccessDenied(HttpContext.Current);
                    return(null);
                }

                var contact = Global.DaoFactory.GetContactDao().GetByID(contactID);
                return(GetContactActivityPage(ctrlUserActivity, contact, messageCount));
            }
            catch (Exception ex)
            {
                throw ProcessError(ctrlUserActivity.LastException ?? ex, "GetContactActivity");
            }
        }
Ejemplo n.º 6
0
        private void InitTwitter(UserActivityView ctrlUserActivity, Contact contact)
        {
            ctrlUserActivity.TwitterInformation = new UserActivityView.TwitterInfo();

            var twitterAccounts = Global.DaoFactory.GetContactInfoDao().GetList(contact.ID, ContactInfoType.Twitter, null, null);

            if (twitterAccounts.Count == 0)
            {
                return;
            }


            foreach (var twitterAccount in twitterAccounts)
            {
                ctrlUserActivity.TwitterInformation.UserAccounts.Add(new UserActivityView.UserAccountInfo {
                    ScreenName = twitterAccount.Data
                });
            }

            ctrlUserActivity.TwitterInformation.ApiInfo = TwitterApiHelper.GetTwitterApiInfoForCurrentUser();
            ctrlUserActivity.SelectedSocialNetworks.Add(SocialNetworks.Twitter);
        }