invites: upload the user's pubkey on invite accept
This commit is contained in:
parent
85d33dd135
commit
c1d54929a4
|
@ -626,12 +626,11 @@ namespace SparkleLib {
|
||||||
if (match.Success) {
|
if (match.Success) {
|
||||||
SparkleChangeSet change_set = new SparkleChangeSet ();
|
SparkleChangeSet change_set = new SparkleChangeSet ();
|
||||||
|
|
||||||
change_set.Folder = Name;
|
change_set.Folder = Name;
|
||||||
change_set.Revision = match.Groups [1].Value;
|
change_set.Revision = match.Groups [1].Value;
|
||||||
change_set.User.Name = match.Groups [2].Value;
|
change_set.User = new SparkleUser (match.Groups [2].Value, match.Groups [3].Value);
|
||||||
change_set.User.Email = match.Groups [3].Value;
|
change_set.IsMagical = is_merge_commit;
|
||||||
change_set.IsMagical = is_merge_commit;
|
change_set.Url = Url;
|
||||||
change_set.Url = Url;
|
|
||||||
|
|
||||||
change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
|
change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
|
||||||
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),
|
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),
|
||||||
|
|
|
@ -17,6 +17,7 @@ SOURCES = \
|
||||||
SparkleListenerFactory.cs \
|
SparkleListenerFactory.cs \
|
||||||
SparkleListenerTcp.cs \
|
SparkleListenerTcp.cs \
|
||||||
SparkleRepoBase.cs \
|
SparkleRepoBase.cs \
|
||||||
|
SparkleUser.cs \
|
||||||
SparkleWatcher.cs
|
SparkleWatcher.cs
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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 class SparkleFolder {
|
||||||
|
|
||||||
public string Name;
|
public string Name;
|
||||||
|
|
|
@ -145,7 +145,16 @@ namespace SparkleLib {
|
||||||
XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()");
|
XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()");
|
||||||
string email = email_node.Value;
|
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 {
|
set {
|
||||||
|
|
36
SparkleLib/SparkleUser.cs
Normal file
36
SparkleLib/SparkleUser.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -106,7 +106,7 @@ namespace SparkleShare {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public virtual void Initialize ()
|
public virtual void Initialize ()
|
||||||
{
|
{
|
||||||
InstallLauncher ();
|
InstallLauncher ();
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
|
||||||
using SparkleLib;
|
using SparkleLib;
|
||||||
|
@ -77,17 +79,34 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public bool Accept ()
|
public bool Accept ()
|
||||||
{
|
{
|
||||||
WebClient web_client = new WebClient ();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
web_client.DownloadData (AcceptUrl);
|
WebRequest request = WebRequest.Create (AcceptUrl);
|
||||||
SparkleHelpers.DebugInfo ("Invite", "Uploaded public key");
|
|
||||||
|
|
||||||
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) {
|
} catch (WebException e) {
|
||||||
SparkleHelpers.DebugInfo ("Invite",
|
SparkleHelpers.DebugInfo ("Invite", "Failed uploading public key to " + AcceptUrl + ": " + e.Message);
|
||||||
"Failed uploading public key: " + e.Message);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue