Ejemplo n.º 1
0
        public async static void Authorize(string ParUserName, string ParPassword)
        {
            LocalData.CurrJWT = string.Empty;

            BlazorTimeAnalyzer.DevelopmentMode = !LocalData.ProductionOrDevelopmentMode;
            BlazorTimeAnalyzer.Reset();
            BlazorTimeAnalyzer.LogAllAddition = true;

            BlazorTimeAnalyzer.Add("A1", MethodBase.GetCurrentMethod());

            timerHelper.Stop();

            if (await WebApi.CmdGetJWT(GlobalFunctions.ConvertToSecureString(ParUserName), GlobalFunctions.ConvertToSecureString(ParPassword), WebApiUserTypesEnum.Authorized))
            {
                BlazorTimeAnalyzer.Add("A2", MethodBase.GetCurrentMethod());
                TSUser tmpTSUser = new TSUser
                {
                    UserName = ParUserName,
                    Password = ParPassword,
                };

                BlazorTimeAnalyzer.Add("A2", MethodBase.GetCurrentMethod());
                LocalData.CurrTSUser = await WebApiFunctions.CmdTSUserAuthorize(tmpTSUser);

                BlazorTimeAnalyzer.Add("A3", MethodBase.GetCurrentMethod());

                if (LocalData.CurrTSUser.UserName.ToLower().Equals("error!"))
                {
                    LocalData.AppHasGlobalError = true;
                    AddError(LocalData.CurrTSUser.FullName, MethodBase.GetCurrentMethod(), true, false);
                }
                else
                {
                    LocalData.IsAuthenticated = !LocalData.CurrTSUser.ID.Equals(Guid.Empty);

                    if (LocalData.IsAuthenticated)
                    {
                        timerHelper.OnTick = TimerTick;
                        timerHelper.Start(1, 10000);

                        BlazorTimeAnalyzer.Add("A4", MethodBase.GetCurrentMethod());
                        await WebApiFunctions.CmdGetFeedback();

                        BlazorTimeAnalyzer.Add("A5", MethodBase.GetCurrentMethod());
                        await WebApiFunctions.CmdGetReaction();

                        BlazorTimeAnalyzer.Add("A6", MethodBase.GetCurrentMethod());

                        LocalData.LoginLogout = LocalData.CurrTSUser.UserName;

                        LocalData.btModal.Close();

                        CmdNavigate("DesktopPage");

                        LocalData.EventConsumerName = "TodosPage";
                        LocalData.componentBridge.InvokeRefresh();

                        LocalData.compHeader.Refresh();

                        LocalData.AppHasGlobalError = false;
                        BlazorTimeAnalyzer.Add("A7", MethodBase.GetCurrentMethod());
                    }
                    else
                    {
                        bool b = await WebApi.CmdGetJWT(LocalData.ServerNotAuthorizedUserName, LocalData.ServerNotAuthorizedUserPass, WebApiUserTypesEnum.NotAuthorized);

                        if (b)
                        {
                            timerHelper.OnTick = TimerTick;
                            timerHelper.Start(1, 10000);
                        }

                        LocalData.AppHasGlobalError = true;
                    }
                }
            }

            BlazorTimeAnalyzer.LogAll();
        }