Example #1
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);
        }
Example #2
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;
            }
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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));
        }
Example #6
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"));
        }