private void GotoTimeline(UserLoginSetting userlogin)
        {
            if (clientProcess != null && !clientProcess.HasExited)
            {
                Debug.Assert(userlogin != null, "param userlogin cannot be empty when timeline opened");

                if (userlogin.Email == userloginContainer.GetLastUserLogin().Email)
                {
                    IntPtr handle = Win32Helper.FindWindow(null, CLIENT_TITLE);
                    Win32Helper.SetForegroundWindow(handle);
                    Win32Helper.ShowWindow(handle, 1);
                    return;
                }
                else
                {
                    uictrlWavefaceClient.Terminate();
                }
            }

            if (userlogin != null && userlogin.RememberPassword)
            {
                LaunchWavefaceClient(userlogin);
                Close();
                return;
            }

            GotoTabPage(tabSignIn, userlogin);
        }
Exemple #2
0
        public void UpsertUserLoginSetting(UserLoginSetting userlogin)
        {
            lock (cs)
            {
                bool duplicated = false;

                foreach (UserLoginSetting oldUserlogin in settings.Users)
                {
                    if (oldUserlogin.Email == userlogin.Email)
                    {
                        oldUserlogin.Password         = userlogin.Password;
                        oldUserlogin.RememberPassword = userlogin.RememberPassword;
                        duplicated = true;
                    }
                }

                if (!duplicated)
                {
                    settings.Users.Add(userlogin);
                }

                settings.LastLogin = userlogin.Email;
                settings.Save();
            }
        }
        private void menuSwitchUser_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem menu = (ToolStripMenuItem)sender;

            UserLoginSetting userlogin = userloginContainer.GetUserLogin(menu.Text);

            GotoTimeline(userlogin);
        }
        private void LaunchWavefaceClient(UserLoginSetting userlogin)
        {
            if (userlogin == null)
            {
                userlogin = userloginContainer.GetLastUserLogin();
            }

            uictrlWavefaceClient.PerformAction(userlogin);
        }
        private void cmbEmail_SelectionChangeCommitted(object sender, EventArgs e)
        {
            UserLoginSetting userlogin = userloginContainer.GetUserLogin((string)cmbEmail.SelectedItem);

            if (userlogin.RememberPassword)
            {
                txtPassword.Text = SecurityHelper.DecryptPassword(userlogin.Password);
            }
            else
            {
                txtPassword.Text = string.Empty;
            }
            chkRememberPassword.Checked = userlogin.RememberPassword;
        }
        protected override object Action(object obj)
        {
            lock (cs)
            {
                UserLoginSetting userlogin = (UserLoginSetting)obj;
                string           execPath  = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                                          "WavefaceWindowsClient.exe");
                mainform.clientProcess = Process.Start(execPath, userlogin.Email + " " + SecurityHelper.DecryptPassword(userlogin.Password));

                if (mainform.clientProcess != null)
                {
                    mainform.clientProcess.WaitForExit();
                }

                int exitCode = mainform.clientProcess.ExitCode;
                mainform.clientProcess = null;

                return(exitCode);
            }
        }
        private void RefreshUserList()
        {
            cmbEmail.Items.Clear();
            try
            {
                menuGotoTimeline.DropDownItems.Remove(menuNewUser);
                menuGotoTimeline.DropDownItems.Clear();

                List <UserLoginSetting> userlogins = new List <UserLoginSetting>();
                bool addSeparator      = false;
                ListDriverResponse res = StationController.ListUser();
                foreach (Driver driver in res.drivers)
                {
                    UserLoginSetting userlogin = userloginContainer.GetUserLogin(driver.email);
                    if (userlogin != null)
                    {
                        if (!addSeparator)
                        {
                            menuGotoTimeline.DropDownItems.Insert(0, new ToolStripSeparator());
                            addSeparator = true;
                        }
                        cmbEmail.Items.Add(userlogin.Email);
                        ToolStripMenuItem menu = new ToolStripMenuItem(userlogin.Email, null, menuSwitchUser_Click);
                        menu.Name = userlogin.Email;
                        menuGotoTimeline.DropDownItems.Insert(0, menu);
                        userlogins.Add(userlogin);
                    }
                }

                if (userlogins.Count > 0)
                {
                    string lastlogin = userloginContainer.GetLastUserLogin().Email;
                    userloginContainer.ResetUserLoginSetting(userlogins, lastlogin);
                }
            }
            finally
            {
                menuGotoTimeline.DropDownItems.Add(menuNewUser);
            }
        }
        private void btnSignIn_Click(object sender, EventArgs e)
        {
            if ((cmbEmail.Text == string.Empty) || (txtPassword.Text == string.Empty))
            {
                MessageBox.Show(I18n.L.T("FillAllFields"), "Waveface", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!TestEmailFormat(cmbEmail.Text))
            {
                MessageBox.Show(I18n.L.T("InvalidEmail"), "Waveface", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                Cursor = Cursors.WaitCursor;
                UserLoginSetting userlogin = userloginContainer.GetUserLogin(cmbEmail.Text);
                if (userlogin == null)
                {
                    AddUserResult res = StationController.AddUser(cmbEmail.Text.ToLower(), txtPassword.Text);

                    userlogin = new UserLoginSetting
                    {
                        Email            = cmbEmail.Text.ToLower(),
                        Password         = SecurityHelper.EncryptPassword(txtPassword.Text),
                        RememberPassword = chkRememberPassword.Checked
                    };
                    userloginContainer.UpsertUserLoginSetting(userlogin);
                    RefreshUserList();

                    if (res.IsPrimaryStation)
                    {
                        GotoTabPage(tabMainStationSetup, userlogin);
                    }
                    else
                    {
                        LaunchWavefaceClient(userlogin);
                        Close();
                    }
                }
                else
                {
                    StationController.StationOnline(userlogin.Email, txtPassword.Text);

                    userlogin.Password         = SecurityHelper.EncryptPassword(txtPassword.Text);
                    userlogin.RememberPassword = chkRememberPassword.Checked;
                    userloginContainer.UpsertUserLoginSetting(userlogin);
                    RefreshUserList();

                    LaunchWavefaceClient(userlogin);

                    Close();
                }
            }
            catch (AuthenticationException)
            {
                MessageBox.Show(I18n.L.T("AuthError"), "Waveface", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                txtPassword.Text = string.Empty;
                txtPassword.Focus();
            }
            catch (StationServiceDownException)
            {
                MessageBox.Show(I18n.L.T("StationDown"), "Waveface", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch (Exception)
            {
                MessageBox.Show(I18n.L.T("UnknownSigninError"), "Waveface", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
        private void GotoTabPage(TabPage tabpage, UserLoginSetting userlogin)
        {
            if (m_SignUpDialog != null)
            {
                m_SignUpDialog.Dispose();
                m_SignUpDialog = null;
            }

            tabControl.SelectedTab = tabpage;

            if (this.WindowState == FormWindowState.Minimized)
            {
                this.WindowState   = FormWindowState.Normal;
                this.ShowInTaskbar = true;
            }

            uint foreThread = Win32Helper.GetWindowThreadProcessId(Win32Helper.GetForegroundWindow(), IntPtr.Zero);
            uint appThread  = Win32Helper.GetCurrentThreadId();

            if (foreThread != appThread)
            {
                Win32Helper.AttachThreadInput(foreThread, appThread, true);
                Win32Helper.BringWindowToTop(this.Handle);
                Show();
                Win32Helper.AttachThreadInput(foreThread, appThread, false);
            }
            else
            {
                Win32Helper.BringWindowToTop(this.Handle);
                Show();
            }
            Activate();

            if (tabpage == tabSignIn)
            {
                if (userlogin == null)
                {
                    cmbEmail.Text               = string.Empty;
                    iscmbEmailFirstChanged      = false;
                    txtPassword.Text            = string.Empty;
                    chkRememberPassword.Checked = false;
                }
                else
                {
                    cmbEmail.Text          = userlogin.Email;
                    iscmbEmailFirstChanged = true;
                    if (userlogin.RememberPassword)
                    {
                        txtPassword.Text = SecurityHelper.DecryptPassword(userlogin.Password);
                    }
                    else
                    {
                        txtPassword.Text = string.Empty;
                    }
                    chkRememberPassword.Checked = userlogin.RememberPassword;
                }

                if (string.IsNullOrEmpty(cmbEmail.Text))
                {
                    cmbEmail.Select();
                }
                else if (string.IsNullOrEmpty(txtPassword.Text))
                {
                    txtPassword.Select();
                }
                else
                {
                    btnSignIn.Select();
                }

                this.AcceptButton = btnSignIn;
            }
            else if (tabpage == tabMainStationSetup)
            {
                btnOK.Tag = userlogin;
                btnOK.Select();
                this.AcceptButton = btnOK;
            }
        }