private void GetClients() { try { Clients.Clear(); var service = Infrastructure.Container.GetInstance <IVtsWebService>(); if (LoggedUserContext.LoggedUser == null) { return; } foreach (UserDto userDto in service.GetClientsForPartner( LoggedUserContext.LoggedUser.Login, LoggedUserContext.LoggedUser.PasswordHash)) { User user = UserAssembler.FromDtoToDomainObject(userDto); clients.Add(new UserViewModel(user)); } } catch (Exception e) { const string msg = "Could not retrieve clients"; Log.Error(e, msg); ErrorWindow w = new ErrorWindow(e, msg); w.Owner = MainWindowKeeper.MainWindowInstance as Window; w.ShowDialog(); } }
static StoredSettings() { TranslationManager.Instance.LanguageChanged += OnLanguageChanged; IVtsWebService client = Infrastructure.Container.GetInstance <IVtsWebService>(); try { if (client.CheckConnection() == "ok") { string login = AgentIsolatedStorageHelper.Login; string passwordHash = AgentIsolatedStorageHelper.PasswordHash; if (String.IsNullOrEmpty(login) || String.IsNullOrEmpty(passwordHash)) { return; } UserDto userDto = client.AuthenticateUser(login, passwordHash); if (userDto != null) { storedUser = UserAssembler.FromDtoToDomainObject(userDto); } else { Log.Warn("Could not log on with stored credentials!"); } TranslationManager.Instance.CurrentLanguageEnum = AgentIsolatedStorageHelper.Language; } } catch (Exception p) { Log.Error(p.Message); } }
/// <summary> /// Action uset lo log in a user after he has entered his credentials. /// </summary> public ActionResult Signin(string emailOrLogin, string password, string language) { string passwordHash = Sha256Hash.Calculate(password); UserDto user = service.AuthenticateUser(emailOrLogin, passwordHash); if (user == null) { TempData["LogonFailed"] = true; return(View("Logon")); } Session["User"] = UserAssembler.FromDtoToDomainObject(user); Session["Lang"] = LangConverter.Convert(language); return(RedirectToAction("Index", "Vehicles")); }
public ActionResult LogOn(LogOnModel model) { if (ModelState.IsValid) { VtsWebServiceClient service = new VtsWebServiceClient(); UserDto userDto = service.AuthenticateUser( model.Username, Sha256Hash.Calculate(model.Password)); if (userDto != null) { FormsAuthentication.SetAuthCookie(model.Username, false); SiteSession siteSession = new SiteSession(); siteSession.User = UserAssembler.FromDtoToDomainObject(userDto); Session["SiteSession"] = siteSession; return(RedirectToAction("Index", "AdminConsole")); } ModelState.AddModelError("", Resource.LogOnErrorMessage); return(View(model)); } return(View(model)); }
private void GoForward() { if (IsRegister) { User user = new User(); user.Login = Username; user.PasswordHash = Sha256Hash.Calculate(PasswordText); user.Role = UserRole.Partner; user.RegisteredDate = DateTime.Now; user.Email = Email; user.Name = "???"; user.Phone = "???"; user.Profile = null; user.Surname = "???"; UserDto userDto = UserAssembler.FromDomainObjectToDto(user); IVtsWebService service = Infrastructure.Container.GetInstance <IVtsWebService>(); try { service.RegisterUser(userDto); UserDto userDtoNew = service.AuthenticateUser(Username, Sha256Hash.Calculate(PasswordText)); User userNew = UserAssembler.FromDtoToDomainObject(userDtoNew); LoggedUserContext.LoggedUser = userNew; StoredSettings.Current = userNew; } catch (Exception e) { Log.Error(e, e.Message); ErrorWindow wnd = new ErrorWindow(e.Message); wnd.Owner = MainWindowKeeper.MainWindowInstance as Window; wnd.ShowDialog(); } } else if (IsLogon) { VtsWebServiceClient service = new VtsWebServiceClient(); try { UserDto userDto = service.AuthenticateUser(Username, Sha256Hash.Calculate(PasswordText)); if (userDto != null) { User user = UserAssembler.FromDtoToDomainObject(userDto); LoggedUserContext.LoggedUser = user; StoredSettings.Current = user; } else { ShowIncorrectCredentialsText(); } } catch (Exception e) { Log.Error(e, e.Message); ErrorWindow wnd = new ErrorWindow(e.Message); wnd.Owner = MainWindowKeeper.MainWindowInstance as Window; wnd.ShowDialog(); } } }