public LoginViewModel() { LockedVisibility = "Visible"; UnLockedVisibility = "Collapsed"; ServerUpdatesVisibility = "Collapsed"; CleanUp(); Singleton.Agency = new LocalAgencyService(true).GetLocalAgency(); InitializeObjects.InitializeWebSecurity(); _unitOfWork = new UnitOfWork(DbContextUtil.GetDbContextInstance()); var currentSetting = XmlSerializerCustom.GetUserSetting(); User = new UserDTO { UserName = currentSetting.UserName, //Password = Properties.Settings.Default.Password }; }
private void DirectLogin() { try { InitializeObjects.InitializeWebSecurity(); var currentSetting = XmlSerializerCustom.GetUserSetting(); var userDTO = new UserDTO { UserName = currentSetting.UserName, Password = currentSetting.Password }; var userExists = false; if (!string.IsNullOrEmpty(userDTO.UserName) && !string.IsNullOrEmpty(userDTO.Password)) { userExists = Membership.ValidateUser(userDTO.UserName, userDTO.Password); } if (!userExists) { new Login().Show(); } else { Singleton.Agency = new LocalAgencyService(true).GetLocalAgency(); int userId = WebSecurity.GetUserId(userDTO.UserName); UserDTO user = new UserService(true).GetUser(userId); if (user == null) { MessageBox.Show("Incorrect UserName/Password", "Error Logging", MessageBoxButton.OK, MessageBoxImage.Error); userDTO.Password = ""; } else { Singleton.User = user; Singleton.User.Password = userDTO.Password; Singleton.UserRoles = new UserRolesModel(); Singleton.Setting = new UnitOfWork(DbContextUtil.GetDbContextInstance()) .Repository <SettingDTO>() .FindById(1); switch (user.Status) { case UserTypes.Waiting: new ChangePassword(userDTO.Password).Show(); break; case UserTypes.Active: { NotifyUtility.ShowCustomBalloon("PinnaFace", "Welcome to PinnaFace", 4000); new MainWindow().Show(); } break; default: MessageBox.Show("Login Failed", "Error Logging", MessageBoxButton.OK, MessageBoxImage.Error); break; } } } } catch (Exception exception) { MessageBox.Show(exception.Message + Environment.NewLine + exception.InnerException); } }