コード例 #1
0
        /// <summary>
        /// Form constructor.
        /// Grabs handles to all the important controls and builds
        /// the auth websocket
        /// </summary>
        public Login()
        {
            this.DataContext = this;
            InitializeComponent();
            Text_Failed.Visibility         = Visibility.Hidden;
            Spinner_Login.Visibility       = Visibility.Hidden;
            Text_RegisterResult.Visibility = Visibility.Hidden;
            Spinner_Register.Visibility    = Visibility.Hidden;

            this.AddProcessor(typeof(ANWI.Messaging.LoginResponse),
                              Login_Response);
            this.AddProcessor(typeof(ANWI.Messaging.RegisterResponse),
                              Register_Response);


            // Load credentials
            if (Appdata.CheckFileExists(credentialsFile))
            {
                try {
                    JObject root
                        = Appdata.OpenJSONFileEncrypted(credentialsFile);


                    Textbox_Username.Text         = (string)root["username"];
                    Textbox_Password.Password     = (string)root["password"];
                    Checkbox_RememberMe.IsChecked = true;
                } catch (Exception e) {
                    // Delete the credentials file so we don't fail again
                    Appdata.DeleteFile(credentialsFile);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Sends the login message to the server
        /// Also records credentials to file if checkbox is clicked
        /// </summary>
        /// <param name="uname"></param>
        /// <param name="pass"></param>
        /// <param name="remember"></param>
        private void SendLogin(string uname, string pass, bool remember)
        {
            // Make sure fields have text
            if (uname != "" && pass != "")
            {
                MessageRouter.Instance.Connect(MessageRouter.Service.Auth);

                // Send message to login server
                MessageRouter.Instance.Send(
                    MessageRouter.Service.Auth,
                    new ANWI.Messaging.LoginRequest(
                        CommonData.version,
                        uname,
                        pass),
                    this
                    );

                // Save credentials
                if (remember)
                {
                    try {
                        JObject root = new JObject(
                            new JProperty("username", uname),
                            new JProperty("password", pass));

                        Appdata.WriteFileEncrypted(
                            credentialsFile, root.ToString());
                    } catch (Exception e) {
                        // Fail silently, just prevent crashes
                    }
                }
            }
        }