Merge lp:~mandel/ubuntuone-windows-installer/use_credentials_provider into lp:ubuntuone-windows-installer/beta

Proposed by Manuel de la Peña
Status: Merged
Approved by: Rick McBride
Approved revision: 92
Merged at revision: 93
Proposed branch: lp:~mandel/ubuntuone-windows-installer/use_credentials_provider
Merge into: lp:ubuntuone-windows-installer/beta
Prerequisite: lp:~mandel/ubuntuone-windows-installer/improve_sso_ui
Diff against target: 770 lines (+292/-136)
18 files modified
src/Canonical.Ubuntu.SSO.Views/Canonical.Ubuntu.SSO.Views.csproj (+9/-0)
src/Canonical.Ubuntu.SSO.Views/LoginDialog.xaml (+2/-2)
src/Canonical.Ubuntu.SSO.Views/LoginDialog.xaml.cs (+38/-8)
src/Canonical.Ubuntu.SSO.Views/objects.xml (+5/-0)
src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj (+3/-0)
src/Canonical.Ubuntu.SSO/ILoginView.cs (+17/-6)
src/Canonical.Ubuntu.SSO/ISSOLoginProcessor.cs (+6/-0)
src/Canonical.Ubuntu.SSO/JsonSSOCredentialsEncoder.cs (+4/-4)
src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs (+80/-2)
src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs (+24/-28)
src/Canonical.Ubuntu.SSO/objects.xml (+3/-1)
src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml (+2/-1)
src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml.cs (+5/-0)
src/Canonical.UbuntuOne.Client/Notification/NotificationIconPresenter.cs (+79/-83)
src/Canonical.UbuntuOne.Client/objects.xml (+2/-1)
src/UbuntuOneClient.Tests/UbuntuOneClient.Tests.csproj (+8/-0)
src/UbuntuOneClient/App.config (+1/-0)
src/UbuntuOneClient/UbuntuOneClient.csproj (+4/-0)
To merge this branch: bzr merge lp:~mandel/ubuntuone-windows-installer/use_credentials_provider
Reviewer Review Type Date Requested Status
Rick McBride (community) Approve
John Lenton (community) Approve
Review via email: mp+37641@code.launchpad.net

Description of the change

Correctly use the sso credential provider to tide up the code.

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) :
review: Approve
Revision history for this message
Rick McBride (rmcbride) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Canonical.Ubuntu.SSO.Views/Canonical.Ubuntu.SSO.Views.csproj'
2--- src/Canonical.Ubuntu.SSO.Views/Canonical.Ubuntu.SSO.Views.csproj 2010-10-05 17:20:59 +0000
3+++ src/Canonical.Ubuntu.SSO.Views/Canonical.Ubuntu.SSO.Views.csproj 2010-10-05 17:21:00 +0000
4@@ -95,6 +95,15 @@
5 </None>
6 <AppDesigner Include="Properties\" />
7 </ItemGroup>
8+ <ItemGroup>
9+ <ProjectReference Include="..\Canonical.Ubuntu.SSO\Canonical.Ubuntu.SSO.csproj">
10+ <Project>{9460A771-2589-45DA-9618-9FE8BB7D16E8}</Project>
11+ <Name>Canonical.Ubuntu.SSO</Name>
12+ </ProjectReference>
13+ </ItemGroup>
14+ <ItemGroup>
15+ <EmbeddedResource Include="objects.xml" />
16+ </ItemGroup>
17 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
18 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
19 Other similar extension points exist, see Microsoft.Common.targets.
20
21=== modified file 'src/Canonical.Ubuntu.SSO.Views/LoginDialog.xaml'
22--- src/Canonical.Ubuntu.SSO.Views/LoginDialog.xaml 2010-10-05 17:20:59 +0000
23+++ src/Canonical.Ubuntu.SSO.Views/LoginDialog.xaml 2010-10-05 17:21:00 +0000
24@@ -64,8 +64,8 @@
25 <ColumnDefinition Width="85"/>
26 <ColumnDefinition Width="85"/>
27 </Grid.ColumnDefinitions>
28- <Button Name="LoginButton" Grid.Column="1" Margin="3" Click="LoginButton_Click">Connect</Button>
29- <Button Name="CancelButton" Grid.Column="2" Margin="3" Click="CancelButton_Click">Cancel</Button>
30+ <Button Name="LoginButton" Grid.Column="1" Margin="3" Click="ConnectButtonClick">Connect</Button>
31+ <Button Name="CancelButton" Grid.Column="2" Margin="3" Click="CancelButtonClick">Cancel</Button>
32 </Grid>
33 </Grid>
34 </Window>
35
36=== modified file 'src/Canonical.Ubuntu.SSO.Views/LoginDialog.xaml.cs'
37--- src/Canonical.Ubuntu.SSO.Views/LoginDialog.xaml.cs 2010-10-05 17:20:59 +0000
38+++ src/Canonical.Ubuntu.SSO.Views/LoginDialog.xaml.cs 2010-10-05 17:21:00 +0000
39@@ -15,6 +15,7 @@
40 // along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
41 //
42 // Authors: Manuel de la Peña <manuel.delapena@canonical.com>
43+using System;
44 using System.Windows;
45
46 namespace Canonical.Ubuntu.SSO.Views
47@@ -22,14 +23,43 @@
48 /// <summary>
49 /// Interaction logic for LoginDialog.xaml
50 /// </summary>
51- public partial class LoginDialog : Window
52+ public partial class LoginDialog : Window, ILoginView
53 {
54- public bool WasCanceled { get; set; }
55-
56- public string Email { get { return EmailTextBox.Text; } }
57+ #region Variables
58+
59+ private MessageBoxResult _dialogResult;
60+
61+ #endregion
62+
63+ /// <summary>
64+ /// Gets and sets the email address provided by the user.
65+ /// </summary>
66+ public string EmailAddress { get { return EmailTextBox.Text; } }
67+
68+ /// <summary>
69+ /// Gets and sets the password set by the user.
70+ /// </summary>
71 public string Password { get { return PasswordTextBox.Password; } }
72
73 /// <summary>
74+ /// Gets if the view is visible.
75+ /// </summary>
76+ public bool IsShown
77+ {
78+ get { return IsVisible; }
79+ }
80+
81+ /// <summary>
82+ /// Shows the gui to the user in a dialog mode.
83+ /// </summary>
84+ /// <returns></returns>
85+ public new MessageBoxResult ShowDialog()
86+ {
87+ base.ShowDialog();
88+ return _dialogResult;
89+ }
90+
91+ /// <summary>
92 /// Initializes a new instance of the LoginDialog class.
93 /// </summary>
94 public LoginDialog()
95@@ -37,15 +67,15 @@
96 InitializeComponent();
97 }
98
99- private void LoginButton_Click(object sender, RoutedEventArgs e)
100+ private void ConnectButtonClick(object sender, RoutedEventArgs e)
101 {
102- WasCanceled = false;
103+ _dialogResult = MessageBoxResult.OK;
104 Close();
105 }
106
107- private void CancelButton_Click(object sender, RoutedEventArgs e)
108+ private void CancelButtonClick(object sender, RoutedEventArgs e)
109 {
110- WasCanceled = true;
111+ _dialogResult = MessageBoxResult.Cancel;
112 Close();
113 }
114 }
115
116=== added file 'src/Canonical.Ubuntu.SSO.Views/objects.xml'
117--- src/Canonical.Ubuntu.SSO.Views/objects.xml 1970-01-01 00:00:00 +0000
118+++ src/Canonical.Ubuntu.SSO.Views/objects.xml 2010-10-05 17:21:00 +0000
119@@ -0,0 +1,5 @@
120+<?xml version="1.0" encoding="utf-8" ?>
121+<objects xmlns="http://www.springframework.net">
122+ <object id="LoginView"
123+ type="Canonical.Ubuntu.SSO.Views.LoginDialog , Canonical.Ubuntu.SSO.Views"/>
124+</objects>
125\ No newline at end of file
126
127=== modified file 'src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj'
128--- src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj 2010-10-05 17:20:59 +0000
129+++ src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj 2010-10-05 17:21:00 +0000
130@@ -39,6 +39,9 @@
131 <SpecificVersion>False</SpecificVersion>
132 <HintPath>..\..\lib\JsonNet\Newtonsoft.Json.dll</HintPath>
133 </Reference>
134+ <Reference Include="PresentationFramework">
135+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
136+ </Reference>
137 <Reference Include="System" />
138 <Reference Include="System.Core">
139 <RequiredTargetFramework>3.5</RequiredTargetFramework>
140
141=== modified file 'src/Canonical.Ubuntu.SSO/ILoginView.cs'
142--- src/Canonical.Ubuntu.SSO/ILoginView.cs 2010-09-09 09:11:07 +0000
143+++ src/Canonical.Ubuntu.SSO/ILoginView.cs 2010-10-05 17:21:00 +0000
144@@ -18,6 +18,7 @@
145 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
146 */
147 using System;
148+using System.Windows;
149
150 namespace Canonical.Ubuntu.SSO
151 {
152@@ -27,15 +28,19 @@
153 /// </summary>
154 public interface ILoginView
155 {
156- #region Events
157-
158- event EventHandler<LoginCredentialsEventArgs> OnLogin;
159-
160- #endregion
161-
162 #region Properties
163
164 /// <summary>
165+ /// Gets and sets the email address used to login in Ubuntu One.
166+ /// </summary>
167+ string EmailAddress { get; }
168+
169+ /// <summary>
170+ /// Gets and sets the password used to loign in ubuntu one.
171+ /// </summary>
172+ string Password { get; }
173+
174+ /// <summary>
175 /// Gets if the view is visible.
176 /// </summary>
177 bool IsShown { get; }
178@@ -46,5 +51,11 @@
179 /// Shows the gui to the user.
180 /// </summary>
181 void Show();
182+
183+ /// <summary>
184+ /// Shows the gui to the user in a dialog mode.
185+ /// </summary>
186+ /// <returns></returns>
187+ MessageBoxResult ShowDialog();
188 }
189 }
190
191=== modified file 'src/Canonical.Ubuntu.SSO/ISSOLoginProcessor.cs'
192--- src/Canonical.Ubuntu.SSO/ISSOLoginProcessor.cs 2010-09-20 11:21:19 +0000
193+++ src/Canonical.Ubuntu.SSO/ISSOLoginProcessor.cs 2010-10-05 17:21:00 +0000
194@@ -26,6 +26,12 @@
195 public interface ISSOLoginProcessor
196 {
197 /// <summary>
198+ /// Gets and sets the credential encoder that will be used to encode the oauth credentials
199+ /// before they are saved in the keyring.
200+ /// </summary>
201+ ISSOCredentialsEncoder SSOCredentialsEncoder { get; set; }
202+
203+ /// <summary>
204 /// Generates a new captha and stores it in the passed file path.
205 /// </summary>
206 /// <param name="filePath">The path in which the captcha should be stored.</param>
207
208=== modified file 'src/Canonical.Ubuntu.SSO/JsonSSOCredentialsEncoder.cs'
209--- src/Canonical.Ubuntu.SSO/JsonSSOCredentialsEncoder.cs 2010-10-05 17:20:59 +0000
210+++ src/Canonical.Ubuntu.SSO/JsonSSOCredentialsEncoder.cs 2010-10-05 17:21:00 +0000
211@@ -36,10 +36,10 @@
212 public string Encode(string token, string tokenSecret, string consumerKey, string consumerSecret)
213 {
214 var jobject = new JObject();
215- jobject["consumer_key"] = "";
216- jobject["consumer_secret"] = "";
217- jobject["token"] = "";
218- jobject["token_secret"] = "";
219+ jobject["consumer_key"] = consumerKey;
220+ jobject["consumer_secret"] = consumerSecret;
221+ jobject["token"] = token;
222+ jobject["token_secret"] = tokenSecret;
223 return jobject.ToString();
224 }
225
226
227=== modified file 'src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs'
228--- src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-10-05 17:20:59 +0000
229+++ src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-10-05 17:21:00 +0000
230@@ -18,6 +18,9 @@
231 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
232 */
233 using System;
234+using System.Collections.Generic;
235+using System.Windows;
236+using Canonical.UbuntuOne.Common;
237 using Canonical.UbuntuOne.Common.Aop;
238
239 namespace Canonical.Ubuntu.SSO
240@@ -28,10 +31,25 @@
241 /// </summary>
242 public class SSOCredentialsProvider : ISSOCredentialsProvider
243 {
244+ private const string ApplicationTokenName = "Ubuntu One @ {0} (Windows)";
245+ internal const string KeyringName = "Default";
246+ internal const string ApplicationName = "UbuntuOne";
247+
248 #region DI properties
249
250+ /// <summary>
251+ /// Gets and sets the view that is used to tell the user to provide his login details.
252+ /// </summary>
253 public ILoginView LoginView { get; set; }
254
255+ /// <summary>
256+ /// Gets and sets the processor that is used to login the user to the SSO service.
257+ /// </summary>
258+ public ISSOLoginProcessor SSOLoginProcessor { get; set; }
259+
260+ /// <summary>
261+ /// Gets and sets the keyring that will be used to store the secrets.
262+ /// </summary>
263 public IKeyring Keyring { get; set; }
264
265 #endregion
266@@ -55,8 +73,68 @@
267 [DebugLogged]
268 public void LoginToGetCredentials()
269 {
270- // try to get the credentials from the keyring
271-
272+ try
273+ {
274+ // try to get the credentials from the keyring
275+ var secret = Keyring.GetSecretByName(KeyringName, ApplicationName);
276+ if (secret == null)
277+ {
278+ // we need to use the processor to get the login info
279+ if (LoginView.IsShown)
280+ return;
281+
282+ if(LoginView.ShowDialog() != MessageBoxResult.Cancel)
283+ {
284+ var tokenName = string.Format(ApplicationTokenName, Environment.MachineName);
285+ secret = SSOLoginProcessor.Login(LoginView.EmailAddress, LoginView.Password, tokenName);
286+ // save the credentials in the keyring
287+ Keyring.CreateSecret(KeyringName, ApplicationName, secret);
288+ }
289+ else
290+ {
291+ if (OnCredetialsDenied != null)
292+ {
293+ OnCredetialsDenied(this, new CredentialsDeniedEventArgs(ApplicationName));
294+ }
295+ return;
296+ }
297+
298+ }
299+ // we execute the credentials found event
300+ if(!string.IsNullOrEmpty(secret) && OnCredentialsFound != null)
301+ {
302+ string token;
303+ string tokenSecret;
304+ string consumerKey;
305+ string consumerSecret;
306+ SSOLoginProcessor.SSOCredentialsEncoder.Decode(secret, out token, out tokenSecret, out consumerKey, out consumerSecret);
307+ var credentials = new Dictionary<string, string>
308+ {
309+ {"Token", token},
310+ {"TokenSecret", tokenSecret},
311+ {"ConsumerKey", consumerKey},
312+ {"ConsumerSecret", consumerSecret}
313+ };
314+ OnCredentialsFound(this, new CredentialsFoundEventArgs(ApplicationName, credentials));
315+ }
316+ }
317+ catch (SSOLoginException e)
318+ {
319+ if (OnCredetialsDenied != null)
320+ {
321+ OnCredetialsDenied(this, new CredentialsDeniedEventArgs(ApplicationName));
322+ }
323+ }
324+ catch (Exception e)
325+ {
326+ // we have an error, therefore we will execute the OnCredentialsError
327+ if (OnCredentialsError != null)
328+ {
329+ OnCredentialsError(this, new CredentialsErrorEventArgs(ApplicationName, e.Message, e.StackTrace));
330+ }
331+ }
332+
333+
334 }
335
336 /// <summary>
337
338=== modified file 'src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs'
339--- src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs 2010-10-05 17:20:59 +0000
340+++ src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs 2010-10-05 17:21:00 +0000
341@@ -185,36 +185,32 @@
342 /// <returns>A string with the sso credentials.</returns>
343 public string Login(string email, string password, string tokenName)
344 {
345- var secret = Keyring.GetSecretByName(KeyringName, ApplicationName);
346- if (secret == null)
347+
348+ try
349 {
350- try
351- {
352- // credentials are not present in the keyring, therefore we will have to get them from the
353- // rest service
354- string token;
355- string tokenSecret;
356- string consumerKey;
357- string consumerSecret;
358+ // credentials are not present in the keyring, therefore we will have to get them from the
359+ // rest service
360+ string token;
361+ string tokenSecret;
362+ string consumerKey;
363+ string consumerSecret;
364
365- // the rest server returns json, we need to parse it.
366- ParseCredentials(Authentications.Authenticate(email, password, tokenName),
367- out consumerKey, out consumerSecret, out token, out tokenSecret);
368- secret = SSOCredentialsEncoder.Encode(token, tokenSecret, consumerKey, consumerSecret);
369- // ping the service to make it download the tokens
370- PingUbuntuOneServer(email, consumerKey, consumerKey, token, tokenSecret);
371- Keyring.CreateSecret(KeyringName, ApplicationName, secret);
372- }
373- catch (WebException e)
374- {
375- throw new SSOLoginException("Unable to login", e);
376- }
377- catch (Exception e)
378- {
379- throw new SSOLoginException("Unable to login", e);
380- }
381- }
382- return secret;
383+ // the rest server returns json, we need to parse it.
384+ ParseCredentials(Authentications.Authenticate(email, password, tokenName),
385+ out consumerKey, out consumerSecret, out token, out tokenSecret);
386+ var secret = SSOCredentialsEncoder.Encode(token, tokenSecret, consumerKey, consumerSecret);
387+ // ping the service to make it download the tokens
388+ PingUbuntuOneServer(email, consumerKey, consumerSecret, token, tokenSecret);
389+ return secret;
390+ }
391+ catch (WebException e)
392+ {
393+ throw new SSOLoginException("Unable to login", e);
394+ }
395+ catch (Exception e)
396+ {
397+ throw new SSOLoginException("Unable to login", e);
398+ }
399 }
400
401 /// <summary>
402
403=== modified file 'src/Canonical.Ubuntu.SSO/objects.xml'
404--- src/Canonical.Ubuntu.SSO/objects.xml 2010-10-05 17:20:59 +0000
405+++ src/Canonical.Ubuntu.SSO/objects.xml 2010-10-05 17:21:00 +0000
406@@ -32,6 +32,8 @@
407
408 <object id="SSOCredentialsProvider"
409 type="Canonical.Ubuntu.SSO.SSOCredentialsProvider , Canonical.Ubuntu.SSO"
410- autowire="autodetect"/>
411+ autowire="autodetect">
412+ <property name="LoginView" ref="LoginView"/>
413+ </object>
414
415 </objects>
416\ No newline at end of file
417
418=== modified file 'src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml'
419--- src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml 2010-08-28 19:55:55 +0000
420+++ src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml 2010-10-05 17:21:00 +0000
421@@ -68,7 +68,8 @@
422 Header="{x:Static resx:Resources.MoreSpace}"/>
423 <MenuItem x:Uid="ExitMenuItem"
424 Name="ExitMenuItem"
425- Header="{x:Static resx:Resources.Exit}" />
426+ Header="{x:Static resx:Resources.Exit}"
427+ Click="OnExitMenuItemClick"/>
428 </ContextMenu>
429 </FrameworkElement.ContextMenu>
430 </av:NotifyIcon>
431
432=== modified file 'src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml.cs'
433--- src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml.cs 2010-08-30 17:30:31 +0000
434+++ src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml.cs 2010-10-05 17:21:00 +0000
435@@ -90,5 +90,10 @@
436 {
437 NotificationIconPresenter.ManualSync();
438 }
439+
440+ private void OnExitMenuItemClick(object sender, System.Windows.RoutedEventArgs e)
441+ {
442+ NotificationIconPresenter.Exit();
443+ }
444 }
445 }
446
447=== modified file 'src/Canonical.UbuntuOne.Client/Notification/NotificationIconPresenter.cs'
448--- src/Canonical.UbuntuOne.Client/Notification/NotificationIconPresenter.cs 2010-10-05 17:20:59 +0000
449+++ src/Canonical.UbuntuOne.Client/Notification/NotificationIconPresenter.cs 2010-10-05 17:21:00 +0000
450@@ -19,16 +19,12 @@
451 using System;
452 using System.Diagnostics;
453 using System.IO;
454-using System.Net;
455-using System.Windows;
456 using Canonical.Ubuntu.SSO;
457-using Canonical.Ubuntu.SSO.Service;
458-using Canonical.Ubuntu.SSO.Views;
459 using Canonical.UbuntuOne.Client.Preferences;
460+using Canonical.UbuntuOne.Common;
461 using Canonical.UbuntuOne.Common.Aop;
462 using Canonical.UbuntuOne.Common.Utils;
463 using log4net;
464-using Newtonsoft.Json.Linq;
465
466 namespace Canonical.UbuntuOne.Client.Notification
467 {
468@@ -53,9 +49,11 @@
469 private static readonly string SharesLocation = "";
470 private static readonly string SyncsLocation = "";
471 private ISyncDaemonClientNotifier _clientNotifier;
472+ private ISSOCredentialsProvider _ssoProvider;
473 private ILog _logger;
474 private readonly object _loggerLock = new object();
475
476+
477 #endregion
478
479 #region Di properties
480@@ -92,6 +90,26 @@
481 public IApplication Application { get; set; }
482
483 /// <summary>
484+ /// Gets and sets the message box used to send messages to the user.
485+ /// </summary>
486+ public IMessageBox MessageBox { get; set; }
487+ /// <summary>
488+ /// Gets and sets the provider that will return the credentials used in ubuntu one.
489+ /// </summary>
490+ public ISSOCredentialsProvider SSOCredentialsProvider
491+ {
492+ get { return _ssoProvider; }
493+ set
494+ {
495+ if (value == null) return;
496+ _ssoProvider = value;
497+ _ssoProvider.OnCredentialsFound += OnCredentialsFound;
498+ _ssoProvider.OnCredentialsError += OnCredentialsError;
499+ _ssoProvider.OnCredetialsDenied += OnCredentialsDenied;
500+ }
501+ }
502+
503+ /// <summary>
504 /// Gets and sets the notifier that will ensure that the presenter know about changes in the
505 /// sync daemon.
506 /// </summary>
507@@ -147,26 +165,6 @@
508
509 #region Helper methods
510
511- public HttpWebRequest MakeRequest(string uri, string consumerKey, string consumerSecret, string token, string tokenSecret)
512- {
513- // Form the full REST request url
514- Uri url = new Uri(uri);
515-
516- // Instantiate OAuthBase and declare variables
517- var oAuth = new OAuth();
518-
519- var normUrl = string.Empty;
520- var normParams = string.Empty;
521-
522- var authHeader = oAuth.GenerateHeaderWithSignature(url, string.Empty, consumerKey, consumerSecret,
523- token, tokenSecret, "GET", oAuth.GenerateTimeStamp(), oAuth.GenerateNonce(), OAuth.SignatureTypes.HMACSHA1,
524- out normUrl, out normParams);
525-
526- var request = WebRequest.Create(normUrl) as HttpWebRequest;
527- request.Headers.Add(authHeader.Key, authHeader.Value);
528- return request;
529- }
530-
531 /// <summary>
532 /// Helper method that will ensure that when the state of the sync daemon changes this change
533 /// is correctly reflected in the View.
534@@ -215,63 +213,30 @@
535 NotificationIconView.Notification = e.Message;
536 }
537
538- #endregion
539-
540- #region Implementation of INotificationIconPresenter
541-
542 /// <summary>
543- /// When implemented this method should for the sync of the ubuntu one folder.
544+ /// Helper method executed when the provider did return new credentials.
545 /// </summary>
546- public void ManualSync()
547+ /// <param name="sender"></param>
548+ /// <param name="args"></param>
549+ [DebugLogged]
550+ private void OnCredentialsFound(object sender, CredentialsFoundEventArgs args)
551 {
552- // TODO: use the oauth code from the provider not here!
553- var keyring = new Keyring();
554- keyring.DataProtector = new DPAPIDataProtector();
555- var secret = keyring.GetSecretByName("Default", "UbuntuOne");
556- if (secret == null)
557- {
558- var dialog = new LoginDialog();
559- dialog.ShowDialog();
560- if (dialog.WasCanceled)
561- {
562- MessageBox.Show("You need to login to be able to sync your files.");
563- return;
564- }
565- try
566- {
567- var auth = new Authentications();
568- var credentials = JObject.Parse(auth.Authenticate(dialog.Email, dialog.Password, "Ubuntu One @ Windows"));
569- secret = string.Format("{0}:{1}:{2}:{3}",
570- (string)credentials["token"],
571- (string)credentials["token_secret"],
572- (string)credentials["consumer_key"],
573- (string)credentials["consumer_secret"]);
574- // TODO: Move this out of here!!! put it in the correct location, like the SSOProvider!!
575- // ping the service to make it download the tokens
576- var pingRequest = MakeRequest(Constants.PingUrl + dialog.Email, (string) credentials["consumer_key"],
577- (string) credentials["consumer_secret"],
578- (string) credentials["token"], (string) credentials["token_secret"]);
579- var pingRepomse = pingRequest.GetResponse();
580- keyring.CreateSecret("Default", "UbuntuOne", secret);
581- }
582- catch (Exception e)
583- {
584- MessageBox.Show("You provided the wrong credentials.");
585- return;
586- }
587- }
588-
589- // TODO: Use the service rather than do it here.
590- // TODO: This has to be fixed, we should not call the command directly, user the
591- // process dispatcher to prepare for the syncdaemon!!!!
592- // TODO: Do not hardcode the folder, use an object to store that
593-
594+ // check if the credentials are for us
595+ if (args.ApplicationName != "UbuntuOne") return;
596+ Logger.Info("Got the UbuntuOne credentials!");
597+ // get the string used to pass the credentials to the python code.
598+ var tokens = string.Format("{0}:{1}:{2}:{3}",
599+ args.Credentials["Token"],
600+ args.Credentials["TokenSecret"],
601+ args.Credentials["ConsumerKey"],
602+ args.Credentials["ConsumerSecret"]);
603 var oneDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
604- "UbuntuOne");
605+ "UbuntuOne");
606 // ensure that the path can be handled by the python code
607 oneDir = oneDir.Replace("\\", "\\\\");
608 if (!Directory.Exists(oneDir))
609 {
610+ Logger.InfoFormat("Creating dir '{0}'", oneDir);
611 Directory.CreateDirectory(oneDir);
612 }
613
614@@ -284,18 +249,22 @@
615 {
616 WorkingDirectory = @"C:\Program Files\Canonical\UbuntuOne\Client\U1Sync",
617 FileName = @"C:\Program Files\Canonical\UbuntuOne\Client\U1Sync\main.exe",
618- Arguments = String.Format(" --init \"{0}\" --oauth {1}",
619- oneDir, secret),
620+ Arguments = String.Format(" --init \"{0}\" --oauth {1}", oneDir, tokens),
621 UseShellExecute = false,
622- RedirectStandardOutput = false,
623- RedirectStandardError = false,
624+ RedirectStandardOutput = true,
625+ RedirectStandardError = true,
626 CreateNoWindow = true,
627 WindowStyle = ProcessWindowStyle.Hidden
628+
629 }
630 };
631+ Logger.InfoFormat("Executing u1sync with args: {0}", init.StartInfo.Arguments);
632 init.Start();
633 init.WaitForExit();
634+ Logger.InfoFormat("StandarOutput from u1sync is: {0}", init.StandardOutput.ReadToEnd());
635+ Logger.ErrorFormat("StandardError from u1sync is: {0}", init.StandardError.ReadToEnd());
636 init.Close();
637+
638 }
639
640 var proc = new Process
641@@ -304,17 +273,41 @@
642 {
643 WorkingDirectory = @"C:\Program Files\Canonical\UbuntuOne\Client\U1Sync",
644 FileName = @"C:\Program Files\Canonical\UbuntuOne\Client\U1Sync\main.exe",
645- Arguments = String.Format("\"{0}\" --oauth {1}",
646- oneDir, secret),
647+ Arguments = String.Format("\"{0}\" --oauth {1}", oneDir, tokens),
648 UseShellExecute = false,
649- RedirectStandardOutput = false,
650- RedirectStandardError = false,
651+ RedirectStandardOutput = true,
652+ RedirectStandardError = true,
653 CreateNoWindow = true,
654 WindowStyle = ProcessWindowStyle.Hidden
655 }
656 };
657 proc.Start();
658-
659+ }
660+
661+ [DebugLogged]
662+ private void OnCredentialsDenied(object sender, CredentialsDeniedEventArgs args)
663+ {
664+
665+ MessageBox.ShowWarning("You need to login to be able to sync your files.");
666+ }
667+
668+ [DebugLogged]
669+ private void OnCredentialsError(object sender, CredentialsErrorEventArgs args)
670+ {
671+ MessageBox.ShowError("An error courred when trying to retrieve your credentials.");
672+ }
673+
674+ #endregion
675+
676+ #region Implementation of INotificationIconPresenter
677+
678+ /// <summary>
679+ /// When implemented this method should for the sync of the ubuntu one folder.
680+ /// </summary>
681+ public void ManualSync()
682+ {
683+ // we get the credentials, because we have register an action to the credetials aquired, we do nothing besides this
684+ SSOCredentialsProvider.LoginToGetCredentials();
685 }
686
687 /// <summary>
688@@ -366,6 +359,7 @@
689 /// <summary>
690 /// Opens the location used to provide help to the user.
691 /// </summary>
692+ [DebugLogged]
693 public void OpenHelp()
694 {
695 Webbrowser.LauncWebpage(HelpUrl);
696@@ -374,6 +368,7 @@
697 /// <summary>
698 /// Opens the location used to upgrade the account of the user.
699 /// </summary>
700+ [DebugLogged]
701 public void OpenUpgradeOption()
702 {
703 Webbrowser.LauncWebpage(UpgradeUrl);
704@@ -382,6 +377,7 @@
705 /// <summary>
706 /// Close the client and the daemon.
707 /// </summary>
708+ [DebugLogged]
709 public void Exit()
710 {
711 Application.Exit();
712
713=== modified file 'src/Canonical.UbuntuOne.Client/objects.xml'
714--- src/Canonical.UbuntuOne.Client/objects.xml 2010-08-30 17:31:04 +0000
715+++ src/Canonical.UbuntuOne.Client/objects.xml 2010-10-05 17:21:00 +0000
716@@ -2,5 +2,6 @@
717 <objects xmlns="http://www.springframework.net">
718 <!-- Define the different presenters to be used -->
719 <object id="NotificationIconPresenter"
720- type="Canonical.UbuntuOne.Client.Notification.NotificationIconPresenter, Canonical.UbuntuOne.Client" />
721+ type="Canonical.UbuntuOne.Client.Notification.NotificationIconPresenter, Canonical.UbuntuOne.Client"
722+ autowire="autodetect"/>
723 </objects>
724\ No newline at end of file
725
726=== modified file 'src/UbuntuOneClient.Tests/UbuntuOneClient.Tests.csproj'
727--- src/UbuntuOneClient.Tests/UbuntuOneClient.Tests.csproj 2010-08-02 14:31:39 +0000
728+++ src/UbuntuOneClient.Tests/UbuntuOneClient.Tests.csproj 2010-10-05 17:21:00 +0000
729@@ -76,6 +76,14 @@
730 <Compile Include="SetupClass.cs" />
731 </ItemGroup>
732 <ItemGroup>
733+ <ProjectReference Include="..\Canonical.Ubuntu.SSO.Views\Canonical.Ubuntu.SSO.Views.csproj">
734+ <Project>{33187F40-201E-4429-B299-E582CF114E28}</Project>
735+ <Name>Canonical.Ubuntu.SSO.Views</Name>
736+ </ProjectReference>
737+ <ProjectReference Include="..\Canonical.Ubuntu.SSO\Canonical.Ubuntu.SSO.csproj">
738+ <Project>{9460A771-2589-45DA-9618-9FE8BB7D16E8}</Project>
739+ <Name>Canonical.Ubuntu.SSO</Name>
740+ </ProjectReference>
741 <ProjectReference Include="..\Canonical.UbuntuOne.Client.Views\Canonical.UbuntuOne.Client.Views.csproj">
742 <Project>{1F0E3DAF-F22F-4B0C-8039-118B082DA237}</Project>
743 <Name>Canonical.UbuntuOne.Client.Views</Name>
744
745=== modified file 'src/UbuntuOneClient/App.config'
746--- src/UbuntuOneClient/App.config 2010-10-05 17:20:59 +0000
747+++ src/UbuntuOneClient/App.config 2010-10-05 17:21:00 +0000
748@@ -34,6 +34,7 @@
749 <context>
750 <resource uri="assembly://UbuntuOneClient/UbuntuOneClient/objects.xml" />
751 <resource uri="assembly://Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO/objects.xml" />
752+ <resource uri="assembly://Canonical.Ubuntu.SSO.Views/Canonical.Ubuntu.SSO.Views/objects.xml" />
753 <resource uri="assembly://Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client/objects.xml" />
754 <resource uri="assembly://Canonical.UbuntuOne.Client.Views/Canonical.UbuntuOne.Client.Views/objects.xml" />
755 <resource uri="assembly://Canonical.UbuntuOne.Common/Canonical.UbuntuOne.Common/objects.xml" />
756
757=== modified file 'src/UbuntuOneClient/UbuntuOneClient.csproj'
758--- src/UbuntuOneClient/UbuntuOneClient.csproj 2010-10-05 17:20:59 +0000
759+++ src/UbuntuOneClient/UbuntuOneClient.csproj 2010-10-05 17:21:00 +0000
760@@ -96,6 +96,10 @@
761 <AppDesigner Include="Properties\" />
762 </ItemGroup>
763 <ItemGroup>
764+ <ProjectReference Include="..\Canonical.Ubuntu.SSO.Views\Canonical.Ubuntu.SSO.Views.csproj">
765+ <Project>{33187F40-201E-4429-B299-E582CF114E28}</Project>
766+ <Name>Canonical.Ubuntu.SSO.Views</Name>
767+ </ProjectReference>
768 <ProjectReference Include="..\Canonical.Ubuntu.SSO\Canonical.Ubuntu.SSO.csproj">
769 <Project>{9460A771-2589-45DA-9618-9FE8BB7D16E8}</Project>
770 <Name>Canonical.Ubuntu.SSO</Name>

Subscribers

People subscribed via source and target branches

to all changes: