invites: upload the user's pubkey on invite accept

This commit is contained in:
Hylke Bons 2012-02-17 21:26:13 +01:00
parent 5de4491892
commit 8bed56d707
7 changed files with 79 additions and 31 deletions

View file

@ -626,12 +626,11 @@ namespace SparkleLib {
if (match.Success) {
SparkleChangeSet change_set = new SparkleChangeSet ();
change_set.Folder = Name;
change_set.Revision = match.Groups [1].Value;
change_set.User.Name = match.Groups [2].Value;
change_set.User.Email = match.Groups [3].Value;
change_set.IsMagical = is_merge_commit;
change_set.Url = Url;
change_set.Folder = Name;
change_set.Revision = match.Groups [1].Value;
change_set.User = new SparkleUser (match.Groups [2].Value, match.Groups [3].Value);
change_set.IsMagical = is_merge_commit;
change_set.Url = Url;
change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),

View file

@ -17,6 +17,7 @@ SOURCES = \
SparkleListenerFactory.cs \
SparkleListenerTcp.cs \
SparkleRepoBase.cs \
SparkleUser.cs \
SparkleWatcher.cs

View file

@ -84,22 +84,6 @@ namespace SparkleLib {
}
public class SparkleUser {
public string Name;
public string Email;
public string PublicKey;
public SparkleUser (string name, string email)
{
Name = name;
Email = email;
}
}
public class SparkleFolder {
public string Name;

View file

@ -145,7 +145,16 @@ namespace SparkleLib {
XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()");
string email = email_node.Value;
return new SparkleUser (name, email);
string pubkey_file_path = Path.Combine (
Path.GetDirectoryName (FullPath),
"sparkleshare." + email + ".key.pub"
);
SparkleUser user = new SparkleUser (name, email) {
PublicKey = File.ReadAllText (pubkey_file_path)
};
return user;
}
set {

36
SparkleLib/SparkleUser.cs Normal file
View file

@ -0,0 +1,36 @@
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace SparkleLib {
public class SparkleUser {
public readonly string Name;
public readonly string Email;
public string PublicKey;
public SparkleUser (string name, string email)
{
Name = name;
Email = email;
}
}
}

View file

@ -106,7 +106,7 @@ namespace SparkleShare {
{
}
public virtual void Initialize ()
{
InstallLauncher ();

View file

@ -16,7 +16,9 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using SparkleLib;
@ -77,17 +79,34 @@ namespace SparkleShare {
public bool Accept ()
{
WebClient web_client = new WebClient ();
try {
web_client.DownloadData (AcceptUrl);
SparkleHelpers.DebugInfo ("Invite", "Uploaded public key");
WebRequest request = WebRequest.Create (AcceptUrl);
return true;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string post_data = "pubkey=" + SparkleConfig.DefaultConfig.User.PublicKey;
byte [] post_bytes = Encoding.UTF8.GetBytes (post_data);
request.ContentLength = post_bytes.Length;
Stream data_stream = request.GetRequestStream ();
data_stream.Write (post_bytes, 0, post_bytes.Length);
data_stream.Close ();
WebResponse response = request.GetResponse ();
response.Close ();
if ((response as HttpWebResponse).StatusCode == HttpStatusCode.OK) {
SparkleHelpers.DebugInfo ("Invite", "Uploaded public key to " + AcceptUrl);
return true;
} else {
SparkleHelpers.DebugInfo ("Invite", "Failed uploading public key to " + AcceptUrl);
return false;
}
} catch (WebException e) {
SparkleHelpers.DebugInfo ("Invite",
"Failed uploading public key: " + e.Message);
SparkleHelpers.DebugInfo ("Invite", "Failed uploading public key to " + AcceptUrl + ": " + e.Message);
return false;
}