Exemple #1
0
        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
            };
        }
Exemple #2
0
        private void ExcuteLoginCommand(object obj)
        {
            try
            {
                var values = (object[])obj;
                var psdBox = values[0] as PasswordBox;

                //Do Validation if not handled on the UI
                if (psdBox != null && psdBox.Password == "")
                {
                    psdBox.Focus();
                    return;
                }

                if (psdBox != null)
                {
                    var us = Membership.ValidateUser(User.UserName, psdBox.Password);

                    if (!us)
                    {
                        MessageBox.Show("Incorrect UserName/Password", "Error Logging",
                                        MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                        User.Password           = "";
                        ServerUpdatesVisibility = "Visible";
                        return;
                    }

                    var userId = WebSecurity.GetUserId(User.UserName);
                    var user   = new UserService(true).GetUser(userId);

                    if (user == null)
                    {
                        MessageBox.Show("Incorrect UserName/Password", "Error Logging",
                                        MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                        User.Password           = "";
                        ServerUpdatesVisibility = "Visible";
                    }
                    else
                    {
                        LockedVisibility   = "Collapsed";
                        UnLockedVisibility = "Visible";
                        //Thread.Sleep(1000);

                        Singleton.User          = user;
                        Singleton.User.Password = psdBox.Password;
                        Singleton.UserRoles     = new UserRolesModel();

                        Singleton.Setting = new UnitOfWork(DbContextUtil.GetDbContextInstance())
                                            .Repository <SettingDTO>()
                                            .FindById(1);

                        if (RememberMe)
                        {
                            var currentSetting = XmlSerializerCustom.GetUserSetting();

                            currentSetting.UserName = User.UserName;
                            currentSetting.Password = psdBox.Password;

                            XmlSerializerCustom.SetUserSetting(currentSetting);
                        }

                        switch (user.Status)
                        {
                        case UserTypes.Waiting:
                            new ChangePassword(psdBox.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;
                        }

                        CloseWindow(values[1]);
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message + Environment.NewLine + exception.InnerException);
            }
        }
        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);
            }
        }