private void ChangePasswordSync(ChangePasswordViewModel viewModel, string baseUri) { if (SessionWrapper.LoginSession == null || SessionWrapper.LoginSession.LogoutTime.HasValue == false) { var intAccMngr = new AccountManager() { Adapter = Adapters.AdapterType.Controller }; var extAccMngr = new AccountManager() { Adapter = Adapters.AdapterType.Service, BaseUri = baseUri }; try { AsyncHelper.RunSync(() => intAccMngr.ChangePasswordAsync(SessionWrapper.SessionToken, viewModel.OldPassword, viewModel.NewPassword)); var externLogin = AsyncHelper.RunSync(() => extAccMngr.LogonAsync(viewModel.Email, viewModel.OldPassword)); AsyncHelper.RunSync(() => extAccMngr.ChangePasswordAsync(externLogin.SessionToken, viewModel.OldPassword, viewModel.NewPassword)); AsyncHelper.RunSync(() => extAccMngr.LogoutAsync(externLogin.SessionToken)); } catch (Exception ex) { throw ex; } } }
private void LogonRemote(LogonViewModel viewModel) { var intAccMngr = new AccountManager() { Adapter = Adapters.AdapterType.Controller }; var extAccMngr = new AccountManager() { Adapter = Adapters.AdapterType.Service, BaseUri = viewModel.IdentityUrl }; try { var externLogin = AsyncHelper.RunSync(() => extAccMngr.LogonAsync(viewModel.Email, viewModel.Password)); var internLogin = AsyncHelper.RunSync(() => intAccMngr.LogonAsync(externLogin.JsonWebToken)); var loginSession = new LoginSession(); loginSession.CopyProperties(internLogin); SessionWrapper.LoginSession = loginSession; AsyncHelper.RunSync(() => extAccMngr.LogoutAsync(externLogin.SessionToken)); } catch (Exception ex) { throw ex; } }
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 ex) { throw ex; } }
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)); }
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")); }
static async Task Main(string[] args) { await Task.Run(() => Console.WriteLine("QnSContactManager")); var rmAccountManager = new AccountManager { // BaseUri = "https://*****:*****@gmx.com", "Passme1234!", AaEnableJwt); await AddAppAccessAsync("schueler2", "*****@*****.**", "Passme1234!", AaEnableJwt); await AddAppAccessAsync("schueler3", "*****@*****.**", "Passme1234!", AaEnableJwt); //var rmLogin = await rmAccountManager.LogonAsync("*****@*****.**", "Passme123!"); //var appLogin = await appAccountManager.LogonAsync(rmLogin.JsonWebToken); //await appAccountManager.LogoutAsync(appLogin.SessionToken); //await rmAccountManager.LogoutAsync(rmLogin.SessionToken); } catch (Exception ex) { Console.WriteLine($"Error in {MethodBase.GetCurrentMethod().Name}: {ex.Message}"); } Console.WriteLine("Press any key to end!"); Console.ReadKey(); }
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 ex) { throw ex; } }
private static async Task AddAppAccessAsync(string user, string email, string pwd, bool enableJwtAuth, params string[] roles) { var accMngr = new AccountManager(); var login = await accMngr.LogonAsync(SaEmail, SaPwd); using var ctrl = Adapters.Factory.Create <Contracts.Business.Account.IAppAccess>(login.SessionToken); var entity = await ctrl.CreateAsync(); entity.Identity.Name = user; entity.Identity.Email = email; entity.Identity.Password = pwd; entity.Identity.EnableJwtAuth = enableJwtAuth; foreach (var item in roles) { var role = entity.CreateRole(); role.Designation = item; entity.AddRole(role); } await ctrl.InsertAsync(entity); await accMngr.LogoutAsync(login.SessionToken); }