Exemplo n.º 1
0
        public IActionResult About()
        {
            ViewData["StartupTimeDate"] = "";
            ViewData["Alive"]           = "";
            ViewData["Stats"]           = "";
            if (_signInManager.IsSignedIn(User))
            {
                TZone tzone = LocalManager.GetUserTimeZone(HttpContext, User, _userManager, _signInManager, _db)
                              .GetAwaiter().GetResult();

                ViewData["StartupTimeDate"] = "Startup Time " +
                                              tzone.Local(Globals.StartupDateTime).ToShortTimeString()
                                              + " " + tzone.Local(Globals.StartupDateTime).ToShortDateString() +
                                              " " + tzone.Abbreviation;

                TimeSpan timeSpan = Globals.Uptime();

                ViewData["Alive"] = "System up: " + timeSpan.Days + " Days "
                                    + timeSpan.Hours + " Hours " + timeSpan.Minutes + " Minutes "
                                    + timeSpan.Seconds + " Seconds";

                long count     = _db.NoteHeader.Count();
                long basenotes = _db.NoteHeader
                                 .Count(p => p.ResponseOrdinal == 0);

                ViewData["Stats"] = "Base Notes: " + basenotes + ", Responses: " + (count - basenotes) +
                                    ", Total Notes: " + count;
            }
            ViewData["Message"] = "About Notes 2021 : " + ViewData["StartupTimeDate"];

            return(View());
        }
Exemplo n.º 2
0
        // GET: NoteFileList
        /// <summary>
        /// Display list of NoteFiles
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> Index()
        {
            HttpContext.Session.SetInt32("IsSearch", 0);

            TZone tz = await LocalManager.GetUserTimeZone(Request.HttpContext, User, _userManager, _signInManager, _db);

            ViewBag.TZ = tz;

            List <NoteFile> nf = await NoteDataManager.GetNoteFilesOrderedByName(_db);

            return(View(nf));
        }
Exemplo n.º 3
0
        public async Task UpdateHomePageTime(string username, TZone tzone)
        {
            string stuff = tzone.Local(DateTime.Now.ToUniversalTime()).ToShortTimeString() + " " + tzone.Abbreviation + " - " +
                           tzone.Local(DateTime.Now.ToUniversalTime()).ToLongDateString();

            var options = new PusherOptions()
            {
                Encrypted = true,
                Cluster   = Globals.PusherCluster
            };
            Pusher         pusher = new Pusher(Globals.PusherAppId, Globals.PusherKey, Globals.PusherSecret, options);
            var            data   = new { message = stuff };
            ITriggerResult x      = await pusher.TriggerAsync("notes-data-" + username, "update-time", data);

            if (x.StatusCode != System.Net.HttpStatusCode.OK)
            {
                RecurringJob.RemoveIfExists(username);
            }
        }
Exemplo n.º 4
0
        // GET: NoteFileList/Details/5
        /// <summary>
        /// Show some info about the NoteFile
        /// </summary>
        /// <param name="id">NoteFileID</param>
        /// <returns></returns>
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            NoteFile noteFile = await NoteDataManager.GetFileByIdWithOwner(_db, (int)id);

            if (noteFile == null)
            {
                return(NotFound());
            }

            TZone tz = await LocalManager.GetUserTimeZone(Request.HttpContext, User, _userManager, _signInManager, _db);

            ViewBag.TZ = tz;

            ViewBag.BaseNotes = await NoteDataManager.NextBaseNoteOrdinal(_db, (int)id, 0) - 1;

            ViewBag.TotalNotes = await NoteDataManager.GetNumberOfNotes(_db, (int)id, 0);

            return(View(noteFile));
        }
Exemplo n.º 5
0
        public static async Task <TZone> GetUserTimeZone(HttpContext httpContext,
                                                         ClaimsPrincipal userx, UserManager <IdentityUser> userManager,
                                                         SignInManager <IdentityUser> signInManager, NotesDbContext db)
        {
            TZone tz = SessionExtensionsLocal.GetObject <TZone>(httpContext.Session, "TZone");

            if (tz != null)
            {
                return(SessionExtensionsLocal.GetObject <TZone>(httpContext.Session, "TZone"));
            }

            int tzid = Globals.TimeZoneDefaultID;

            if (signInManager.IsSignedIn(userx))
            {
                try
                {
                    string userId = userManager.GetUserId(userx);
                    tzid = GetUserData(userManager, userx, db).TimeZoneID;  // get users timezoneid
                }
                catch
                {
                    // ignored
                }
            }
            if (tzid < 1)
            {
                tzid = Globals.TimeZoneDefaultID;
            }

            var tz2 = await db.TZone.SingleAsync(p => p.Id == tzid);

            SessionExtensionsLocal.SetObject(httpContext.Session, "TZone", tz2);

            return(SessionExtensionsLocal.GetObject <TZone>(httpContext.Session, "TZone"));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Index()
        {
            if (!_roleManager.Roles.Any())
            {
                await _roleManager.CreateAsync(new IdentityRole { Name = "User" });

                await _roleManager.CreateAsync(new IdentityRole { Name = "Admin" });
            }

            TZone tzone = await LocalManager.GetUserTimeZone(HttpContext, User, _userManager, _signInManager, _db);

            HomePageModel myModel = new HomePageModel
            {
                Tzone       = tzone,
                UpdateClock = false
            };


beyond:

            if (_signInManager.IsSignedIn(User))
            {
                IdentityUser usr;
                try
                {
                    usr = await _userManager.GetUserAsync(User);
                }
                catch
                {
                    await _signInManager.SignOutAsync();

                    goto beyond;
                }

                if (!User.IsInRole("User"))
                {
                    await _userManager.AddToRoleAsync(usr, "User");
                }

                if (_userManager.Users.Count() == 1 && !User.IsInRole("Admin"))
                {
                    // Only/First user - Make an Admin!
                    await _userManager.AddToRoleAsync(usr, "Admin");
                }

                UserData aux = NoteDataManager.GetUserData(_userManager, User, _db);
                HttpContext.Session.SetInt32("HideNoteMenu", Convert.ToInt32(aux.Pref1));
                HttpContext.Session.SetInt32("ArchiveID", Convert.ToInt32(0));
                string uName = NoteDataManager.GetSafeUserDisplayName(_userManager, User, _db);

                //Jobs job = new Jobs();
                //if (user.Pref2)
                //{
                //    myModel.UpdateClock = true;
                //    RecurringJob.AddOrUpdate(uName, () => job.UpdateHomePageTime(uName, tzone), Cron.Minutely);
                //    RecurringJob.AddOrUpdate("delete_" + uName, () => job.CleanupHomePageTime(uName), Cron.Daily);
                //}
                //else
                //{
                //    RecurringJob.RemoveIfExists(uName);
                //}

                HttpContext.Session.SetInt32("IsSearch", 0);    // clear the searching flag
                try
                {
                    // if this user has a searchView row in the DB, delete it

                    Search searchView = await NoteDataManager.GetUserSearch(_db, aux.UserId);

                    if (searchView != null)
                    {
                        _db.Search.Remove(searchView);
                        await _db.SaveChangesAsync();
                    }
                }
                catch
                {
                    // if we cannot talk to the DB, route the user to the setup directions
                    //return RedirectToAction("SetUp");
                }

                //Direct link to 3 important files

                myModel.IFiles = await _db.NoteFile
                                 .Where(p => p.NoteFileName == "announce" || p.NoteFileName == "pbnotes" || p.NoteFileName == "noteshelp")
                                 .OrderBy(p => p.NoteFileName)
                                 .ToListAsync();

                // History files

                myModel.HFiles = await _db.NoteFile
                                 .Where(p => p.NoteFileName == "Gnotes" || p.NoteFileName == "Opbnotes")
                                 .OrderBy(p => p.NoteFileName)
                                 .ToListAsync();

                // Get a list of all file names for dropdown
                IEnumerable <SelectListItem> items = LocalManager.GetFileNameSelectList(_db);
                List <SelectListItem>        list2 = new List <SelectListItem>();
                list2.AddRange(items);

                myModel.AFiles = list2;

                // Get a list of all file titles for dropdown
                items = LocalManager.GetFileTitleSelectList(_db);
                list2 = new List <SelectListItem>();
                list2.AddRange(items);
                myModel.ATitles = list2;

                HomePageMessage mess = await _db.HomePageMessage.OrderByDescending(p => p.Id).FirstOrDefaultAsync();

                myModel.Message = mess != null ? mess.Message : "";
            }

            ViewData["MyName"] = NoteDataManager.GetUserDisplayName(_userManager, User, _db);
            return(View(_userManager, myModel));
        }