예제 #1
0
        public async Task <DataToggl <UserDataToggl> > UpdateUserData(EditableUserData editableUserData)
        {
            var response = await BasicAuthorizationRequest <DataToggl <UserDataToggl>, EditableUserData>("https://www.toggl.com/api/v8/me", editableUserData, "PUT");

            userRequestInfo = response.data;
            return(response);
        }
예제 #2
0
        public void SignUp(EditableUserData data, Reactions reactions = null)
        {
            Thread signing = new Thread(() =>
            {
                if (!this.SendMessage("SIGNUP", ("EditableData", data)))
                {
                    goto disconnection;
                }

                reactions?.RequestSentCallback?.Invoke();
                Message message = this.ReceiveMessage();
                if (message == null)
                {
                    goto disconnection;
                }
                reactions?.MessageReceivedCallback?.Invoke(message);
                if (message.Title == "SUCCESS")
                {
                    this.isAuthenticated             = true;
                    LadenEventArgs eventArgs         = new LadenEventArgs();
                    eventArgs.PayloadData["message"] = message;

                    this.Authenticated(this, eventArgs);
                }
                return;

                disconnection: reactions?.DisconnectionErrorCallback?.Invoke();
            });

            signing.Start();
        }
        public bool SignUp(EditableUserData editableUserData)
        {
            SqlCommand command = new SqlCommand("SELECT username FROM users WHERE username=@username;", ReversiDatabaseManager.Database.Connection);

            command.Parameters.AddWithValue("username", editableUserData.Profile.Username);
            bool username_reserved;

            using (SqlDataReader reader = command.ExecuteReader())
            {
                username_reserved = reader.HasRows;
            }

            if (!username_reserved)
            {
                command.CommandText = "INSERT INTO users(username, password, name, surname, email, join_datetime) VALUES(@username, @password, @name, @surname, @email, @join_datetime);";
                //command.Parameters.AddWithValue("username", editable.Profile.Username);
                command.Parameters.AddWithValue("password", editableUserData.Private.Password);
                command.Parameters.AddWithValue("name", editableUserData.Private.Name);
                command.Parameters.AddWithValue("surname", editableUserData.Private.Surname);
                command.Parameters.AddWithValue("email", editableUserData.Private.Email);
                command.Parameters.AddWithValue("join_datetime", DateTime.Now);
                command.ExecuteNonQuery();

                /*command.CommandText = "INSERT INTO profile_images(username, profile_image) VALUES(@username, @profile_image);";
                 * //command.Parameters.AddWithValue("username", editable.Profile.Username);
                 * byte[] image_data = new Serializer().Serialize(editable.Profile.ProfilePhoto);
                 * command.Parameters.AddWithValue("profile_image", image_data);
                 * command.ExecuteNonQuery();*/
                editableUserData.Profile.ProfilePhoto.Save($@"{Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures)}\{editableUserData.Profile.Username}.png");


                this.client.Username = editableUserData.Profile.Username;
                this.MarkOnline();
                client.SendMessage("SUCCESS", ("description", "Account created successfully. You've been automatically logged in"));
                return(true);
            }
            else
            {
                client.SendMessage("FAIL", ("description", "Username is already reserved"));
                return(false);
            }
        }
예제 #4
0
        private void signup_button_Click(object sender, EventArgs e)
        {
            ProfileUserData profile = new ProfileUserData()
            {
                Username     = username_textbox.Text,
                ProfilePhoto = profile_image_picturebox.Image
            };
            PrivateUserData @private = new PrivateUserData()
            {
                Name     = name_textbox.Text,
                Surname  = surname_textbox.Text,
                Password = password_textbox.Text,
                Email    = email_textbox.Text
            };
            EditableUserData data = new EditableUserData {
                Profile = profile, Private = @private
            };

            #region rubbish

            /*if (DataServerDialog.Dialog.State != ConnectionState.Connected)
             * {
             *  MessageBox.Show("No connection");
             * }
             * else if (DataServerDialog.Dialog.SendMessage("SIGNUP", ("EditableData", editable)))
             * {
             *  this.Invoke((MethodInvoker)delegate
             *  {
             *      signup_button.Text = "Connecting...";
             *      signup_button.Enabled = false;
             *      ReversiSerializableTypes.Message message = DataServerDialog.Dialog.ReceiveMessage();
             *      signup_button.Text = "Register";
             *      signup_button.Enabled = true;
             *
             *      MessageBox.Show((string)message.Payload["description"], message.Title);
             *      if (message.Title == "SUCCESS")
             *      {
             *          this.Close();
             *      }
             *  });
             *
             * }*/
            #endregion
            void unmark_waiting()
            {
                this.signup_button.Invoke((MethodInvoker)(() =>
                {
                    signup_button.Text = "Register";
                    signup_button.Enabled = true;
                    this.Cursor = Cursors.Default;
                }));
            }

            Servers.DataServer.SignUp(data, new ServerDialog.Reactions
            {
                RequestSentCallback = () =>
                {
                    signup_button.Invoke((MethodInvoker)(() =>
                    {
                        signup_button.Text = "Waiting...";
                        signup_button.Enabled = false;
                    }));
                },
                MessageReceivedCallback = (message) =>
                {
                    unmark_waiting();
                    this.Invoke((MethodInvoker)(() =>
                    {
                        if (message.Title == "SUCCESS")
                        {
                            this.Close();
                        }
                        else
                        {
                            info1.Show();
                            info1.Text = (string)message.Payload["description"];
                        }
                    }));
                },
                DisconnectionErrorCallback = () =>
                {
                    unmark_waiting();
                    this.Invoke((MethodInvoker)(() =>
                    {
                        info1.Show();
                        info1.Text = "Connection error";
                    }));
                }
            });
        }