Skip to content

Commit c151c3a

Browse files
committed
Create FinishRegistrationPage
1 parent 95c15d5 commit c151c3a

File tree

6 files changed

+177
-51
lines changed

6 files changed

+177
-51
lines changed

Signal-Windows/Signal-Windows.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
<Compile Include="Storage\Store.cs" />
187187
<Compile Include="Utils.cs" />
188188
<Compile Include="ViewModels\AddContactPageViewModel.cs" />
189+
<Compile Include="ViewModels\FinishRegistrationPageViewModel.cs" />
189190
<Compile Include="ViewModels\LinkPageViewModel.cs" />
190191
<Compile Include="ViewModels\MainPageViewModel.cs" />
191192
<Compile Include="ViewModels\RegisterFinalizationPageViewModel.cs" />
@@ -195,6 +196,9 @@
195196
<Compile Include="Views\AddContactPage.xaml.cs">
196197
<DependentUpon>AddContactPage.xaml</DependentUpon>
197198
</Compile>
199+
<Compile Include="Views\FinishRegistrationPage.xaml.cs">
200+
<DependentUpon>FinishRegistrationPage.xaml</DependentUpon>
201+
</Compile>
198202
<Compile Include="Views\LinkPage.xaml.cs">
199203
<DependentUpon>LinkPage.xaml</DependentUpon>
200204
</Compile>
@@ -261,6 +265,10 @@
261265
<SubType>Designer</SubType>
262266
<Generator>MSBuild:Compile</Generator>
263267
</Page>
268+
<Page Include="Views\FinishRegistrationPage.xaml">
269+
<SubType>Designer</SubType>
270+
<Generator>MSBuild:Compile</Generator>
271+
</Page>
264272
<Page Include="Views\LinkPage.xaml">
265273
<SubType>Designer</SubType>
266274
<Generator>MSBuild:Compile</Generator>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using GalaSoft.MvvmLight;
8+
using libsignalservice;
9+
using libsignalservice.util;
10+
using Signal_Windows.Models;
11+
using Signal_Windows.Storage;
12+
using Signal_Windows.Views;
13+
using Windows.UI.Popups;
14+
15+
namespace Signal_Windows.ViewModels
16+
{
17+
public class FinishRegistrationPageViewModel : ViewModelBase
18+
{
19+
public FinishRegistrationPage View { get; set; }
20+
21+
internal async Task OnNavigatedTo()
22+
{
23+
try
24+
{
25+
await Task.Run(() =>
26+
{
27+
string SignalingKey = Base64.encodeBytes(Util.getSecretBytes(52));
28+
App.ViewModels.RegisterFinalizationPageInstance.AccountManager.verifyAccountWithCode(
29+
App.ViewModels.RegisterFinalizationPageInstance.VerificationCode,
30+
SignalingKey, App.ViewModels.RegisterFinalizationPageInstance.SignalRegistrationId,
31+
false, false, true);
32+
SignalStore store = new SignalStore()
33+
{
34+
DeviceId = 1,
35+
IdentityKeyPair = Base64.encodeBytes(App.ViewModels.RegisterFinalizationPageInstance.IdentityKeyPair.serialize()),
36+
NextSignedPreKeyId = 1,
37+
Password = App.ViewModels.RegisterFinalizationPageInstance.Password,
38+
PreKeyIdOffset = 1,
39+
Registered = true,
40+
RegistrationId = App.ViewModels.RegisterFinalizationPageInstance.SignalRegistrationId,
41+
SignalingKey = SignalingKey,
42+
Username = App.ViewModels.RegisterPageInstance.FinalNumber,
43+
};
44+
LibsignalDBContext.SaveOrUpdateSignalStore(store);
45+
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
46+
{
47+
App.Store = store;
48+
}).AsTask().Wait();
49+
50+
/* create prekeys */
51+
LibsignalDBContext.RefreshPreKeys(
52+
new SignalServiceAccountManager(App.ServiceUrls, store.Username, store.Password, (int)store.DeviceId, App.USER_AGENT));
53+
54+
/* reload again with prekeys and their offsets */
55+
store = LibsignalDBContext.GetSignalStore();
56+
Debug.WriteLine("success!");
57+
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
58+
{
59+
App.Store = store;
60+
}).AsTask().Wait();
61+
});
62+
View.Frame.Navigate(typeof(MainPage));
63+
}
64+
catch (Exception e)
65+
{
66+
var title = "Verification failed";
67+
var content = "Please enter the correct verification code.";
68+
MessageDialog dialog = new MessageDialog(content, title);
69+
var result = dialog.ShowAsync();
70+
View.Frame.Navigate(typeof(RegisterPage));
71+
}
72+
}
73+
}
74+
}

Signal-Windows/ViewModels/RegisterFinalizationPageViewModel.cs

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public string VerificationCode
3030
set { _VerificationCode = value; RaisePropertyChanged(nameof(VerificationCode)); }
3131
}
3232

33-
private SignalServiceAccountManager AccountManager;
34-
private string Password;
35-
private uint SignalRegistrationId;
36-
private IdentityKeyPair IdentityKeyPair;
33+
internal SignalServiceAccountManager AccountManager { get; private set; }
34+
internal string Password { get; private set; }
35+
internal uint SignalRegistrationId { get; private set; }
36+
internal IdentityKeyPair IdentityKeyPair { get; private set; }
3737
private CancellationTokenSource CancelSource;
3838
private bool _UIEnabled;
3939
public bool UIEnabled
@@ -49,53 +49,9 @@ public bool UIEnabled
4949
}
5050
}
5151

52-
internal async void FinishButton_Click()
52+
internal void FinishButton_Click()
5353
{
54-
try
55-
{
56-
await Task.Run(() =>
57-
{
58-
string SignalingKey = Base64.encodeBytes(Util.getSecretBytes(52));
59-
AccountManager.verifyAccountWithCode(VerificationCode, SignalingKey, SignalRegistrationId, false, false, true);
60-
SignalStore store = new SignalStore()
61-
{
62-
DeviceId = 1,
63-
IdentityKeyPair = Base64.encodeBytes(IdentityKeyPair.serialize()),
64-
NextSignedPreKeyId = 1,
65-
Password = Password,
66-
PreKeyIdOffset = 1,
67-
Registered = true,
68-
RegistrationId = SignalRegistrationId,
69-
SignalingKey = SignalingKey,
70-
Username = App.ViewModels.RegisterPageInstance.FinalNumber,
71-
};
72-
LibsignalDBContext.SaveOrUpdateSignalStore(store);
73-
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
74-
{
75-
App.Store = store;
76-
}).AsTask().Wait();
77-
78-
/* create prekeys */
79-
LibsignalDBContext.RefreshPreKeys(new SignalServiceAccountManager(App.ServiceUrls, store.Username, store.Password, (int)store.DeviceId, App.USER_AGENT));
80-
81-
/* reload again with prekeys and their offsets */
82-
store = LibsignalDBContext.GetSignalStore();
83-
Debug.WriteLine("success!");
84-
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
85-
{
86-
App.Store = store;
87-
}).AsTask().Wait();
88-
});
89-
View.Frame.Navigate(typeof(MainPage));
90-
}
91-
catch (Exception e)
92-
{
93-
var title = "Verification failed";
94-
var content = "Please enter the correct verification code.";
95-
MessageDialog dialog = new MessageDialog(content, title);
96-
var result = dialog.ShowAsync();
97-
View.Frame.Navigate(typeof(RegisterPage));
98-
}
54+
View.Frame.Navigate(typeof(FinishRegistrationPage));
9955
}
10056

10157
internal async Task OnNavigatedTo()
@@ -124,7 +80,7 @@ internal async Task OnNavigatedTo()
12480
private SignalServiceAccountManager InitRegistration(bool voice)
12581
{
12682
LibsignalDBContext.PurgeAccountData();
127-
SignalServiceAccountManager accountManager = new SignalServiceAccountManager(App.ServiceUrls, App.ViewModels.RegisterPageInstance.FinalNumber, Password, 1, App.USER_AGENT);
83+
SignalServiceAccountManager accountManager = new SignalServiceAccountManager(App.ServiceUrls, App.ViewModels.RegisterPageInstance.FinalNumber, Password, 1 /*device id isn't actually used*/, App.USER_AGENT);
12884
if (voice)
12985
{
13086
accountManager.requestVoiceVerificationCode();

Signal-Windows/ViewModels/ViewModelLocator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public ViewModelLocator()
3333
SimpleIoc.Default.Register<RegisterPageViewModel>();
3434
SimpleIoc.Default.Register<RegisterFinalizationPageViewModel>();
3535
SimpleIoc.Default.Register<LinkPageViewModel>();
36+
SimpleIoc.Default.Register<FinishRegistrationPageViewModel>();
3637
}
3738

3839
// <summary>
@@ -89,6 +90,11 @@ public LinkPageViewModel LinkPageInstance
8990
}
9091
}
9192

93+
public FinishRegistrationPageViewModel FinishRegistrationPageInstance
94+
{
95+
get { return ServiceLocator.Current.GetInstance<FinishRegistrationPageViewModel>(); }
96+
}
97+
9298
// <summary>
9399
// The cleanup.
94100
// </summary>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Page
2+
x:Class="Signal_Windows.Views.FinishRegistrationPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Signal_Windows.Views"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d"
9+
DataContext="{Binding FinishRegistrationPageInstance, Source={StaticResource Locator}}">
10+
11+
<Page.Resources>
12+
<ResourceDictionary>
13+
<ResourceDictionary.ThemeDictionaries>
14+
<ResourceDictionary x:Key="Default">
15+
<Color x:Key="SystemAltHighColor">#2190EA</Color>
16+
<SolidColorBrush x:Key="ApplicationPageBackgroundThemeBrush" Color="{ThemeResource SystemAltHighColor}" />
17+
</ResourceDictionary>
18+
<ResourceDictionary x:Key="Dark">
19+
<Color x:Key="SystemAltHighColor">#2190EA</Color>
20+
<SolidColorBrush x:Key="ApplicationPageBackgroundThemeBrush" Color="{ThemeResource SystemAltHighColor}" />
21+
</ResourceDictionary>
22+
</ResourceDictionary.ThemeDictionaries>
23+
</ResourceDictionary>
24+
</Page.Resources>
25+
26+
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
27+
<Grid.RowDefinitions>
28+
<RowDefinition Height="*"/>
29+
<RowDefinition Height="*"/>
30+
</Grid.RowDefinitions>
31+
<TextBlock Grid.Row="0" x:Name="TitleTextBlock" Text="Finishing up" FontSize="46" FontWeight="Light" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
32+
<ProgressRing Grid.RowSpan="2" Foreground="White" IsActive="True" Width="75" Height="75"/>
33+
</Grid>
34+
</Page>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Signal_Windows.ViewModels;
7+
using Windows.Foundation;
8+
using Windows.Foundation.Collections;
9+
using Windows.UI.Xaml;
10+
using Windows.UI.Xaml.Controls;
11+
using Windows.UI.Xaml.Controls.Primitives;
12+
using Windows.UI.Xaml.Data;
13+
using Windows.UI.Xaml.Input;
14+
using Windows.UI.Xaml.Media;
15+
using Windows.UI.Xaml.Navigation;
16+
17+
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
18+
19+
namespace Signal_Windows.Views
20+
{
21+
/// <summary>
22+
/// An empty page that can be used on its own or navigated to within a Frame.
23+
/// </summary>
24+
public sealed partial class FinishRegistrationPage : Page
25+
{
26+
public FinishRegistrationPage()
27+
{
28+
this.InitializeComponent();
29+
Vm.View = this;
30+
}
31+
32+
public FinishRegistrationPageViewModel Vm
33+
{
34+
get { return (FinishRegistrationPageViewModel)DataContext; }
35+
}
36+
37+
protected override async void OnNavigatedTo(NavigationEventArgs e)
38+
{
39+
base.OnNavigatedTo(e);
40+
await Vm.OnNavigatedTo();
41+
}
42+
43+
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
44+
{
45+
base.OnNavigatingFrom(e);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)