Ejemplo n.º 1
0
        public async Task <ActionResult <TSEmail> > PassRecovery(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "user/passrecovery")] HttpRequest req,
            ILogger log)
        {
            TSEmail tsEmail = await MyFromBody <TSEmail> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum>
            {
                WebApiUserTypesEnum.NotAuthorized,
                WebApiUserTypesEnum.Authorized,
                WebApiUserTypesEnum.Admin
            };

            ClaimsPrincipal User = MyTokenValidator.Authenticate(req, localAllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));


            Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));
            await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "Pass Recovery", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));



            string newPass = GlobalFunctions.GetSalt();

            CosmosDocUser cosmosDocUser = await CosmosAPI.cosmosDBClientUser.FindUserByUserName(tsEmail.To, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            if (cosmosDocUser != null)
            {
                cosmosDocUser.Salt           = GlobalFunctions.GetSalt();
                cosmosDocUser.HashedPassword = GlobalFunctions.CmdHashPasswordBytes(newPass, cosmosDocUser.Salt);

                bool b = await CosmosAPI.cosmosDBClientUser.UpdateUserDoc(cosmosDocUser, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

                if (b)
                {
                    tsEmail.To = cosmosDocUser.Email;
                    TSEmail result = await TodosCosmos.LocalFunctions.SendEmail(tsEmail, string.Empty, newPass, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

                    result.To            = string.Empty;
                    result.OperationCode = 0;

                    return(result);
                }
                else
                {
                    return(new TSEmail {
                        Result = "Error: Could not recover user password"
                    });
                }
            }
            else
            {
                return(new TSEmail {
                    Result = "Error: User not found"
                });
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> AddDefaultCategory(Guid UserID, List <string> CallTrace)
        {
            TSCategory tsCategory = new TSCategory();

            tsCategory.ID     = Guid.NewGuid();
            tsCategory.UserID = UserID;
            tsCategory.Name   = "default";

            return(await AddCategory(tsCategory, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
        }
Ejemplo n.º 3
0
        public async Task <bool> UpdateUserTodosCount(TSUser tsUser, int change, List <string> CallTrace)
        {
            TSUser result = await GetUser(tsUser, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

            result.TodosCount += change;

            await UpdateUser(result, true, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

            return(true);
        }
 public void WithLocalFunctionTest()
 {
     /*
      * One of the useful features of local functions is that they can allow exceptions to surface immediately.
      */
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         IEnumerable <int> oddNumbers = LocalFunctions.OddSequenceWithLocalFunction(10, 109);
     });
 }
 public void CmdDisplayChangePassword()
 {
     if (LocalData.IsAuthenticated)
     {
         LocalFunctions.DisplayModal(ModalForm.ChangePassword);
     }
     else
     {
         LocalFunctions.AddMessage("You are not authenticated!", true, false);
     }
 }
        protected override void OnInitialized()
        {
            if (!LocalData.IsAuthenticated)
            {
                LocalFunctions.CmdNavigate();

                LocalFunctions.AddMessage("Please login", true, false);
            }

            base.OnInitialized();
        }
Ejemplo n.º 7
0
 public void CmdDisplayRegistration()
 {
     if (!LocalData.IsAuthenticated)
     {
         LocalFunctions.DisplayModal(ModalForm.Registration);
     }
     else
     {
         LocalFunctions.AddMessage("Please logout first, to register new user", true, false);
     }
 }
Ejemplo n.º 8
0
 protected void ValidateUserName()
 {
     if (string.IsNullOrEmpty(UserName.Trim()))
     {
         LocalFunctions.AddError("Please enter user name", MethodBase.GetCurrentMethod(), false, false);
     }
     else if (UserName.Trim().Length < 6)
     {
         LocalFunctions.AddError("User name should contain minimum 6 character", MethodBase.GetCurrentMethod(), false, false);
     }
 }
Ejemplo n.º 9
0
 static void Main(string[] args)
 {
     LiteralsDemo.Show();
     OutParametersDemo.Show();
     PatternMatchingDemo.Show();
     TupleDemo.Show();
     LocalFunctions.Show();
     RefLocalsRefReturnsDemo.Show();
     ExpressionBodiedFunctionDemo.Show();
     ThrowExpressionsDemo.Show();
 }
Ejemplo n.º 10
0
 public void CmdDisplayLogin()
 {
     if (!LocalData.IsAuthenticated)
     {
         LocalFunctions.DisplayModal(ModalForm.Login);
     }
     else
     {
         LocalFunctions.AddMessage("You are authenticated already", true, false);
     }
 }
Ejemplo n.º 11
0
        public async Task <ActionResult> ChangePassword(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "user/changepassword")] HttpRequest req,
            ILogger log)
        {
            TSUser tsUser = await MyFromBody <TSUser> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));
            await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "change password", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));


            string MachineID = LocalFunctions.CmdGetValueFromClaim(User.Claims, "MachineID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            string IPAddress = req.HttpContext.Connection.RemoteIpAddress.ToString();



            CosmosEmailedCode emailedCode = await CosmosAPI.cosmosDBClientEmailedCode.FindEmaiedCode(tsUser.Email, IPAddress, MachineID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            if (emailedCode != null)
            {
                if (emailedCode.Code.ToLower().Equals(tsUser.EmailedCode))
                {
                    await CosmosAPI.cosmosDBClientEmailedCode.DeleteEmailedCodes(tsUser.Email, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));


                    TSUser currUser = (await CosmosAPI.cosmosDBClientUser.FindUserByID(UserID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))).toTSUser();

                    currUser.Password = tsUser.Password;


                    if (await CosmosAPI.cosmosDBClientUser.UpdateUser(currUser, false, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())))
                    {
                        return(new OkObjectResult("OK"));
                    }
                    else
                    {
                        return(new OkObjectResult("Error:Can't add new user!"));
                    }
                }
                else
                {
                    return(new OkObjectResult("Error:Emailed code is not correct!"));
                }
            }
            else
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, "EmaiedCode expected but not found", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

                return(new OkObjectResult("Error:Server can't find emailed code to compare!"));
            }
        }
Ejemplo n.º 12
0
        public async void ComboUILanguageSelectionChanged()
        {
            //BTodosJsInterop.Log("======aaaaaaa=====");
            //var results = await LocalData.indexDbManager.GetRecords<TSUILanguage>("UILanguages");
            //foreach (var item in results)
            //{
            //    BTodosJsInterop.Log(item.Name);
            //    await LocalData.indexDbManager.DeleteRecord("UILanguages", item);
            //}

            //BTodosJsInterop.Log("done");
            //// await LocalData.indexDbManager.ClearStore("UILanguages");

            ////  await LocalData.indexDbManager.ClearStore("UILangDict");

            //return;


            LocalData.uiTranslator.CurrUILanguage = LocalData.uiTranslator.TSUILanguagesList[LocalData.uiTranslator.ComboUILanguagesSelectedIndex];


            if (!LocalData.uiTranslator.CurrUILanguage.Code.Equals("en", StringComparison.InvariantCultureIgnoreCase))
            {
                await LocalFunctions.GetUILangDict();

                //BTodosJsInterop.Log("====================");

                //foreach (var item in LocalData.TSUIWordForeignsList)
                //{
                //    BTodosJsInterop.Log(item.Word);
                //}
            }


            if (LocalData.IsAuthenticated)
            {
                LocalFunctions.CmdNavigate("DesktopPage");
            }
            else
            {
                LocalFunctions.CmdNavigate();
            }


            LocalData.uiTranslator.OnUILanguageChanged?.Invoke();

            LocalData.compHeader.Refresh();



            StateHasChanged();
        }
Ejemplo n.º 13
0
        // [Inject] IndexedDBManager indexedDbManager { get; set; }

        protected override void OnInitialized()
        {
            if (!LocalData.ProductionOrDevelopmentMode)
            {
                if (!BlazorWindowHelper.BWHJsInterop.IsReady)
                {
                    BlazorWindowHelper.BWHJsInterop.jsRuntime = jsRuntime;
                    BlazorWindowHelper.BWHJsInterop.IsReady   = true;
                }
            }


            if (WebApiFunctions.httpClient is null)
            {
                WebApiFunctions.httpClient = httpClient;
            }

            if (LocalFunctions.navigationManager is null)
            {
                LocalFunctions.navigationManager = navigationManager;
            }

            if (BTodosJsInterop.jsRuntime is null)
            {
                BTodosJsInterop.jsRuntime = jsRuntime;
            }

            if (LocalData.UsingIndexedDb)
            {
                if (LocalData.indexedDbManager is null)
                {
                    //LocalData.indexedDbManager = indexedDbManager;
                }
            }


            if (!navigationManager.BaseUri.Equals(navigationManager.Uri))
            {
                navigationManager.NavigateTo("/");
            }


            LocalData.mainLayout = this;



            LocalFunctions.CmdPrepare();



            base.OnInitialized();
        }
        public async Task <bool> AddEmailedCode(CosmosEmailedCode tsEmailedCode, List <string> CallTrace)
        {
            try
            {
                return(await cosmosDBClientBase.AddItemAsync(tsEmailedCode, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(false);
            }
        }
Ejemplo n.º 15
0
        public void CmdRecoverPass()
        {
            ValidateUserName();

            if (LocalFunctions.HasError())
            {
                LocalFunctions.DisplayErrors();
            }
            else
            {
                LocalFunctions.DisplayConfirm("LoginDialog", "Are you sure to recover password?");
            }
        }
Ejemplo n.º 16
0
        private static void LocalFunctionsDemo()
        {
            LocalFunctions localFunctions = new LocalFunctions();

            Console.WriteLine("Step 1.");

            // IEnumerable<int> sum = localFunctions.LocalFunctionsDemo(new[] {10, 20, 30}, new[] {1, 2, 3});
            IEnumerable <int> sum = localFunctions.LocalFunctionsDemo(new[] { 10, 20, 30 }, null);

            Console.WriteLine("Step 2.");

            Console.WriteLine(string.Join(",", sum));
            Console.WriteLine("Step 3.");
        }
Ejemplo n.º 17
0
        public async Task <ActionResult <IEnumerable <TSCategory> > > GetAll(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "category/getall")] HttpRequest req,
            ILogger log)
        {
            ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            await CosmosAPI.cosmosDBClientActivity.AddActivityLog(Guid.Empty, "Requested public data", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));

            await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "Requested Categories", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            return(await CosmosAPI.cosmosDBClientCategory.GetAllCategories(UserID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));
        }
Ejemplo n.º 18
0
 protected void CmdOnMouseUp(MouseEventArgs e)
 {
     if (LocalData.bcMenu.ID > -1)
     {
         if (e.ClientX < LocalData.bcMenu.X || e.ClientX > LocalData.bcMenu.X + LocalData.bcMenu.width)
         {
             LocalFunctions.ContextMenu_Hide();
         }
         else if (e.ClientY < LocalData.bcMenu.Y || e.ClientY > LocalData.bcMenu.Y + LocalData.bcMenu.height)
         {
             LocalFunctions.ContextMenu_Hide();
         }
     }
 }
Ejemplo n.º 19
0
        public async Task CmdAddOrUpdateCategory()
        {
            IsButtonDisabled = true;
            StateHasChanged();


            if (LocalFunctions.Validate(LocalData.currCategory))
            {
                if (!LocalData.currCategoryName.Equals(LocalData.currCategory.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    string a = string.Empty;

                    if (LocalData.AddOrUpdateMode)
                    {
                        LocalData.currCategory.UserID = LocalData.CurrTSUser.ID;
                        a = await WebApiFunctions.CmdAddCategory(LocalData.currCategory);
                    }
                    else
                    {
                        a = await WebApiFunctions.CmdUpdateCategory(LocalData.currCategory);
                    }

                    if (a.Equals("OK"))
                    {
                        LocalData.TSCategoriesList       = new List <TSCategoryEx>();
                        LocalData.TSCategoriesDictionary = new Dictionary <Guid, string>();


                        LocalData.TsTodosList = new List <TSTodoEx>();


                        LocalData.btModal.Close();

                        //LocalFunctions.CmdNavigate("CategoriesPage");
                        LocalData.EventConsumerName = "CategoriesPage";
                        LocalData.componentBridge.InvokeRefresh();
                    }
                    else
                    {
                        LocalFunctions.AddError(a, MethodBase.GetCurrentMethod(), true, false);
                    }
                }
                else
                {
                    LocalFunctions.AddMessage("Category name not updated", true, false);
                }
            }

            IsButtonDisabled = false;
        }
Ejemplo n.º 20
0
        protected void CmdRegister()
        {
            LocalData.btModal.Close();


            if (!LocalData.IsAuthenticated)
            {
                LocalFunctions.DisplayModal(ModalForm.Registration);
            }
            else
            {
                LocalFunctions.AddMessage("Please logout first, to register new user", true, false);
            }
        }
        public async Task <bool> SendTodoReminders(List <string> CallTrace)
        {
            try
            {
                IEnumerable <CosmosDocTodo> result = await cosmosDBRepo.GetItemsAsync(x => x.DocType == (int)DocTypeEnum.Todo &&
                                                                                      x.UserID != CosmosAPI.DemoUserID && !x.IsReminderEmailed &&
                                                                                      x.HasRemindDate && x.RemindDate < DateTime.Now,
                                                                                      LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));



                if (result.Any())
                {
                    bool   b    = false;
                    string body = string.Empty;
                    foreach (var item in result)
                    {
                        TSUser currUser = await CosmosAPI.cosmosDBClientUser.GetUser(item.UserID, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                        if (currUser != null)
                        {
                            item.IsReminderEmailed = true;


                            TSEmail tmpEmail = new TSEmail()
                            {
                                To            = currUser.Email,
                                OperationCode = 4,
                            };

                            body     = "Name - " + item.Name + "\n\nDescription - " + item.Description + "\n\nDuedate - " + item.DueDate.ToString("MM/dd/yyyy HH:mm:ss.fff") + ".";
                            tmpEmail = LocalFunctions.SendEmail(tmpEmail, string.Empty, body,
                                                                LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())).Result;


                            b = UpdateTodoEntity(item, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())).Result;
                        }
                    }
                }
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(false);
            }


            return(true);
        }
Ejemplo n.º 22
0
        public void CmdAdd()
        {
            LocalData.AddOrUpdateMode = true;
            LocalData.CurrTodo        = new TSTodo
            {
                DueDate    = LocalFunctions.ToLocalDate(DateTime.Now).AddDays(7),
                RemindDate = LocalFunctions.ToLocalDate(DateTime.Now),
                Priority   = 1,
                CategoryID = Guid.Empty
            };

            LocalData.BeforeUpdateTodo = new TSTodo();
            LocalData.compAddOrUpdateTodo.Bootstrap();
            LocalFunctions.DisplayModal(ModalForm.AddOrUpdateTodo);
        }
Ejemplo n.º 23
0
        public async Task <T> GetItemAsync(Guid id, Guid UserID, string pkPrefix, List <string> CallTrace)
        {
            try
            {
                string pkValue = PartitionKeyGenerator.Create(pkPrefix, id.ToString());

                return(await cosmosDBRepo.GetItemAsync(id.ToString(), pkValue, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(UserID, ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(null);
            }
        }
Ejemplo n.º 24
0
        public async Task <CosmosDocUIWordForeign> Find(string SearchCrtiteria, string column, List <string> CallTrace)
        {
            try
            {
                QueryDefinition sql = new QueryDefinition("SELECT * FROM c WHERE c.DocType = " + (int)DocTypeEnum.UIWordForeign + " and c." + column + "='" + SearchCrtiteria + "'");

                return(await cosmosDBRepo.FindFirstItemsAsync(sql, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(null);
            }
        }
Ejemplo n.º 25
0
        public async Task <bool> UpdateItemAsync(T item, List <string> CallTrace)
        {
            try
            {
                await cosmosDBRepo.UpdateItemAsync(item, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(true);
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(GetProperty(item, "UserID", LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())), ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(false);
            }
        }
Ejemplo n.º 26
0
        public void WithoutLocalFunctionTest()
        {
            IEnumerable <int> oddNumbers = LocalFunctions.OddSequence(10, 109);

            /*
             * (w/o local functions) For method iterators, exceptions are surfaced only when the returned sequence is enumerated, and not when the iterator is retrieved.
             */
            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                foreach (var item in oddNumbers)
                {
                    Debug.Print(item.ToString());
                }
            });
        }
 public void CmdAddOrUpdateFeedback()
 {
     if (LocalData.currFeedback.UserID.Equals(Guid.Empty))
     {
         LocalData.AddOrUpdateMode = true;
         LocalData.compAddOrUpdateFeedback.Bootstrap();
         LocalFunctions.DisplayModal(ModalForm.AddOrUpdateFeedback);
     }
     else
     {
         LocalData.AddOrUpdateMode = false;
         LocalData.compAddOrUpdateFeedback.Bootstrap();
         LocalFunctions.DisplayModal(ModalForm.AddOrUpdateFeedback);
     }
 }
        public void ComboOptionsSelectionChanged(ChangeEventArgs e)
        {
            NumbersList = new List <int>();

            if (byte.TryParse(e.Value.ToString(), out byte index))
            {
                OptionsSelectedIndex = index;
                switch (OptionsSelectedIndex)
                {
                case 0:     //minute
                    AddNumber(1, MinutesEnd);
                    AddNumber(2, MinutesEnd);
                    AddNumber(3, MinutesEnd);
                    AddNumber(4, MinutesEnd);
                    for (int i = 5; i <= MinutesEnd; i += 5)
                    {
                        NumbersList.Add(i);
                    }
                    break;

                case 1:     //hour
                    for (int i = 1; i <= HoursEnd; i++)
                    {
                        NumbersList.Add(i);
                    }
                    break;

                case 2:     //day
                    AddNumber(1, DaysEnd);
                    AddNumber(2, DaysEnd);
                    AddNumber(3, DaysEnd);
                    AddNumber(4, DaysEnd);
                    for (int i = 5; i <= DaysEnd; i += 5)
                    {
                        NumbersList.Add(i);
                    }
                    break;

                default:
                    break;
                }
            }

            LocalData.CurrTodo.RemindDate = LocalFunctions.ToLocalDate(DateTime.Now);


            StateHasChanged();
        }
Ejemplo n.º 29
0
        public async Task <ActionResult <TSStat> > Get(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "stat")] HttpRequest req,
            ILogger log)
        {
            await CosmosAPI.cosmosDBClientSetting.SetSetting(Guid.Empty, "LatsStatRequest", "ts", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            if (User != null)
            {
                Guid   userID   = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));
                string userName = LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

                if (!userID.Equals(Guid.Empty))
                {
                    if (!userName.Equals("demouser"))
                    {
                        TSUser tsUser = await CosmosAPI.cosmosDBClientUser.GetUser(new TSUser { ID = userID }, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

                        if (tsUser != null)
                        {
                            if (!tsUser.IsLive)
                            {
                                tsUser.IsLive = true;
                                await CosmosAPI.cosmosDBClientUser.UpdateUser(tsUser, true, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));
                            }
                        }
                    }
                }
            }

            TSStat stat = new TSStat
            {
                IPsCount       = await GetStat("IPAddressesCount"),
                VisitsCount    = await GetStat("VisitsCount"),
                UsersCount     = await GetStat("UsersCount"),
                LiveUsersCount = await GetStat("LiveUsersCount"),
                TodosCount     = await GetStat("TodosCount"),
                LikesCount     = await GetStat("LikesCount"),
                DislikesCount  = await GetStat("DislikesCount"),
                FeedbackCount  = await GetStat("FeedbackCount"),
            };



            return(stat);
            // return new OkObjectResult(JsonSerializer.ToString(stat));
        }
Ejemplo n.º 30
0
        public async Task CmdGetAllCategories()
        {
            try
            {
                await LocalFunctions.GetTodosAndCategories();

                CategoriesListCount = LocalData.uiTranslator.Translate("Categories list") + " (" + LocalData.TSCategoriesList.Count + ")";


                StateHasChanged();
            }
            catch (Exception ex)
            {
                LocalFunctions.AddError(ex.Message, MethodBase.GetCurrentMethod(), true, false);
            }
        }