Esempio n. 1
0
        private async Task ExecuteLogonRemoteAsync(LogonViewModel viewModel)
        {
            var intAccMngr = new AccountManager()
            {
                Adapter = Adapters.AdapterType.Controller
            };
            var extAccMngr = new AccountManager()
            {
                Adapter = Adapters.AdapterType.Service, BaseUri = viewModel.IdentityUrl
            };

            try
            {
                var externLogin = await extAccMngr.LogonAsync(viewModel.Email, viewModel.Password).ConfigureAwait(false);

                var internLogin = await intAccMngr.LogonAsync(externLogin.JsonWebToken).ConfigureAwait(false);

                var loginSession = new LoginSession();

                loginSession.CopyProperties(internLogin);
                SessionWrapper.LoginSession = loginSession;
                await extAccMngr.LogoutAsync(externLogin.SessionToken).ConfigureAwait(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
        public static async Task <ILoginSession> TryLogonAsync(string identityUri, string email, string password)
        {
            var trAccMngr = new AccountManger
            {
                BaseUri = BaseUri,
                Adapter = Adapters.AdapterType.Service,
            };
            ILoginSession tryLogin;

            if (identityUri.HasContent())
            {
                var idAccMngr = new AccountManger
                {
                    BaseUri = identityUri,
                    Adapter = Adapters.AdapterType.Service,
                };
                var idLogin = await idAccMngr.LogonAsync(email, password).ConfigureAwait(false);

                tryLogin = await trAccMngr.LogonAsync(idLogin.JsonWebToken).ConfigureAwait(false);

                await idAccMngr.LogoutAsync(idLogin.SessionToken).ConfigureAwait(false);
            }
            else
            {
                tryLogin = await trAccMngr.LogonAsync(email, password).ConfigureAwait(false);
            }
            return(tryLogin);
        }
Esempio n. 3
0
        public async Task <IActionResult> ResetPasswordAsync(ResetPasswordViewModel viewModel)
        {
            if (ModelState.IsValid == false)
            {
                return(View(viewModel));
            }
            bool handled  = false;
            var  viewName = "ConfirmationResetPassword";

            BeforeDoResetPassword(viewModel, ref handled);
            if (SessionWrapper.LoginSession == null ||
                SessionWrapper.LoginSession.LogoutTime.HasValue)
            {
                return(RedirectToAction("Logon", new { returnUrl = "ResetPassword" }));
            }

            try
            {
                var accMngr = new AccountManager();

                await accMngr.ChangePasswordForAsync(SessionWrapper.SessionToken, viewModel.Email, viewModel.ConfirmPassword).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                viewModel.ActionError = GetExceptionError(ex);
                return(View("ResetPassword", viewModel));
            }
            AfterDoResetPassword(viewModel, ref viewName);
            return(View(viewName));
        }
Esempio n. 4
0
        static async Task ImportProperties(string filePath, string user, string password)
        {
            QnSProjectAward.Adapters.Factory.Adapter = QnSProjectAward.Adapters.AdapterType.Controller;

            var accMngr = new QnSProjectAward.Adapters.Modules.Account.AccountManager();
            var login   = await accMngr.LogonAsync(user, password);

            using var ctrl = QnSProjectAward.Adapters.Factory.Create <QnSProjectAward.Contracts.Persistence.Configuration.ISetting>(login.SessionToken);
            var importProperties = File.ReadAllLines(filePath, Encoding.Default).Skip(1).Select(l => ToProperty(l, ";"));
            var existsProperties = await ctrl.QueryAllAsync("AppName.Equals(\"QnSProjectAward\")").ConfigureAwait(false);

            foreach (var item in importProperties)
            {
                var key   = $"{item.ComponentName}.{item.MemberName}{(string.IsNullOrEmpty(item.Attribute) ? string.Empty : $".{item.Attribute}")}";
                var entry = existsProperties.SingleOrDefault(e => e.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase));

                if (entry == null)
                {
                    var newEntry = await ctrl.CreateAsync().ConfigureAwait(false);

                    newEntry.AppName = item.AppName;
                    newEntry.Key     = key;
                    newEntry.Value   = item.Value;
                    await ctrl.InsertAsync(newEntry).ConfigureAwait(false);
                }
                else
                {
                    entry.Value = item.Value;
                    await ctrl.UpdateAsync(entry).ConfigureAwait(false);
                }
            }
Esempio n. 5
0
        static async Task ImportTranslations(string filePath, string user, string password)
        {
            QnSProjectAward.Adapters.Factory.Adapter = QnSProjectAward.Adapters.AdapterType.Controller;

            var accMngr = new QnSProjectAward.Adapters.Modules.Account.AccountManager();
            var login   = await accMngr.LogonAsync(user, password);

            using var ctrl = QnSProjectAward.Adapters.Factory.Create <QnSProjectAward.Contracts.Persistence.Language.ITranslation>(login.SessionToken);
            var importTranslations = File.ReadAllLines(filePath, Encoding.Default).Skip(1).Select(l => ToTranslation(l, ";"));
            var existsTranslations = await ctrl.QueryAllAsync("AppName.Equals(\"QnSProjectAward\")").ConfigureAwait(false);

            foreach (var item in importTranslations)
            {
                var keyLanguage = (LanguageCode)Enum.Parse(typeof(LanguageCode), item.KeyLanguage);
                var entry       = existsTranslations.SingleOrDefault(e => e.KeyLanguage == keyLanguage && e.Key.Equals(item.Key));

                if (entry == null)
                {
                    var newEntry = await ctrl.CreateAsync().ConfigureAwait(false);

                    newEntry.AppName       = item.AppName;
                    newEntry.KeyLanguage   = (LanguageCode)Enum.Parse(typeof(LanguageCode), item.KeyLanguage);
                    newEntry.Key           = item.Key;
                    newEntry.ValueLanguage = (LanguageCode)Enum.Parse(typeof(LanguageCode), item.ValueLanguage);
                    newEntry.Value         = item.Value;
                    await ctrl.InsertAsync(newEntry).ConfigureAwait(false);
                }
                else
                {
                    entry.Value = item.Value;
                    await ctrl.UpdateAsync(entry).ConfigureAwait(false);
                }
            }
            await accMngr.LogoutAsync(login.SessionToken);
        }
Esempio n. 6
0
        private static async Task <IAppAccess> AddAppAccessAsync(string user, string email, string pwd, bool enableJwtAuth, params string[] roles)
        {
            var accMngr = new AccountManager();
            var login   = await accMngr.LogonAsync(SaEmail, SaPwd, string.Empty).ConfigureAwait(false);

            using var ctrl = Adapters.Factory.Create <IAppAccess>(login.SessionToken);
            var entity = await ctrl.CreateAsync();

            entity.OneItem.Name          = user;
            entity.OneItem.Email         = email;
            entity.OneItem.Password      = pwd;
            entity.OneItem.EnableJwtAuth = enableJwtAuth;

            foreach (var item in roles)
            {
                var role = entity.CreateManyItem();

                role.Designation = item;
                entity.AddManyItem(role);
            }
            var identity = await ctrl.InsertAsync(entity).ConfigureAwait(false);

            await accMngr.LogoutAsync(login.SessionToken).ConfigureAwait(false);

            return(identity);
        }
Esempio n. 7
0
        public static Task LogoutAsync(ILoginSession login)
        {
            login.CheckArgument(nameof(login));

            var trAccMngr = new AccountManger
            {
                BaseUri = BaseUri,
                Adapter = Adapters.AdapterType.Service,
            };

            return(trAccMngr.LogoutAsync(login.SessionToken));
        }
Esempio n. 8
0
        public async Task <IActionResult> LogoutAsync()
        {
            if (SessionWrapper.LoginSession != null)
            {
                bool handled = false;

                BeforeLogout(ref handled);
                if (handled == false)
                {
                    var accMngr = new AccountManager();

                    await accMngr.LogoutAsync(SessionWrapper.LoginSession.SessionToken).ConfigureAwait(false);

                    SessionWrapper.LoginSession = null;
                }
                AfterLogout();
            }
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 9
0
        private async Task ExecuteLogonAsync(LogonViewModel viewModel)
        {
            var intAccMngr = new AccountManager()
            {
                Adapter = Adapters.AdapterType.Controller
            };

            try
            {
                var internLogin = await intAccMngr.LogonAsync(viewModel.Email, viewModel.Password).ConfigureAwait(false);

                var loginSession = new LoginSession();

                loginSession.CopyProperties(internLogin);
                SessionWrapper.LoginSession = loginSession;
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 10
0
        private static async Task Main(string[] args)
        {
            await Task.Run(() => Console.WriteLine("QnSProjectAward"));

            Console.WriteLine(DateTime.Now);
            BeforeExecuteMain(args);

            var rmAccountManager = new AccountManager
            {
                //                BaseUri = "http://localhost:5000/api",
                BaseUri = "http://localhost:5000/api",
                Adapter = Adapters.AdapterType.Service,
            };
            var appAccountManager = new AccountManager
            {
                BaseUri = "http://localhost:5000/api",
                Adapter = Adapters.AdapterType.Controller,
            };

            Adapters.Factory.BaseUri = "http://localhost:5000/api";
            Adapters.Factory.Adapter = Adapters.AdapterType.Controller;

            try
            {
                await InitAppAccessAsync().ConfigureAwait(false);
                await AddAppAccessAsync(AaUser, AaEmail, AaPwd, AaEnableJwt, AaRole).ConfigureAwait(false);

                //await appAccountManager.LogoutAsync(appLogin.SessionToken);
                //await rmAccountManager.LogoutAsync(rmLogin.SessionToken);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error in {MethodBase.GetCurrentMethod().Name}: {ex.Message}");
            }

            EndExecuteMain();
            Console.WriteLine(DateTime.Now);
            Console.WriteLine("Press any key to end!");
            Console.ReadKey();
        }