From c666f92e359061c0a4c133ba090832a059298782 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Fri, 22 Sep 2017 15:33:09 -0700 Subject: new startup process UI for Windows --- windows/WinUI/APIHandler.cs | 12 + windows/WinUI/CentralAPI.cs | 245 +++++++++++++++++++++ windows/WinUI/CentralLogin.cs | 30 +++ windows/WinUI/CentralNetwork.cs | 48 ++++ windows/WinUI/CentralServer.cs | 23 ++ windows/WinUI/CentralToken.cs | 21 ++ windows/WinUI/CentralUser.cs | 51 +++++ windows/WinUI/ISwitchable.cs | 13 ++ windows/WinUI/NetworkNameGenerator.cs | 201 +++++++++++++++++ windows/WinUI/OnboardProcess/CreateAccount.xaml | 38 ++++ windows/WinUI/OnboardProcess/CreateAccount.xaml.cs | 66 ++++++ windows/WinUI/OnboardProcess/CreateOrJoin.xaml | 49 +++++ windows/WinUI/OnboardProcess/CreateOrJoin.xaml.cs | 98 +++++++++ windows/WinUI/OnboardProcess/EnterToken.xaml | 29 +++ windows/WinUI/OnboardProcess/EnterToken.xaml.cs | 57 +++++ windows/WinUI/OnboardProcess/Finished.xaml | 27 +++ windows/WinUI/OnboardProcess/Finished.xaml.cs | 37 ++++ windows/WinUI/OnboardProcess/LogIn.xaml | 35 +++ windows/WinUI/OnboardProcess/LogIn.xaml.cs | 57 +++++ windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml | 27 +++ .../WinUI/OnboardProcess/RegisterOrLogIn.xaml.cs | 48 ++++ windows/WinUI/PageSwitcher.xaml | 13 ++ windows/WinUI/PageSwitcher.xaml.cs | 56 +++++ windows/WinUI/PreferencesView.xaml | 23 +- windows/WinUI/PreferencesView.xaml.cs | 42 +++- windows/WinUI/Switcher.cs | 24 ++ windows/WinUI/Themes/Generic.xaml | 1 - windows/WinUI/ToolbarItem.xaml.cs | 23 +- windows/WinUI/WinUI.csproj | 63 ++++++ 29 files changed, 1443 insertions(+), 14 deletions(-) create mode 100644 windows/WinUI/CentralAPI.cs create mode 100644 windows/WinUI/CentralLogin.cs create mode 100644 windows/WinUI/CentralNetwork.cs create mode 100644 windows/WinUI/CentralServer.cs create mode 100644 windows/WinUI/CentralToken.cs create mode 100644 windows/WinUI/CentralUser.cs create mode 100644 windows/WinUI/ISwitchable.cs create mode 100644 windows/WinUI/NetworkNameGenerator.cs create mode 100644 windows/WinUI/OnboardProcess/CreateAccount.xaml create mode 100644 windows/WinUI/OnboardProcess/CreateAccount.xaml.cs create mode 100644 windows/WinUI/OnboardProcess/CreateOrJoin.xaml create mode 100644 windows/WinUI/OnboardProcess/CreateOrJoin.xaml.cs create mode 100644 windows/WinUI/OnboardProcess/EnterToken.xaml create mode 100644 windows/WinUI/OnboardProcess/EnterToken.xaml.cs create mode 100644 windows/WinUI/OnboardProcess/Finished.xaml create mode 100644 windows/WinUI/OnboardProcess/Finished.xaml.cs create mode 100644 windows/WinUI/OnboardProcess/LogIn.xaml create mode 100644 windows/WinUI/OnboardProcess/LogIn.xaml.cs create mode 100644 windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml create mode 100644 windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml.cs create mode 100644 windows/WinUI/PageSwitcher.xaml create mode 100644 windows/WinUI/PageSwitcher.xaml.cs create mode 100644 windows/WinUI/Switcher.cs (limited to 'windows') diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs index 80515e5b..015415c3 100644 --- a/windows/WinUI/APIHandler.cs +++ b/windows/WinUI/APIHandler.cs @@ -26,6 +26,8 @@ namespace WinUI public delegate void NetworkListCallback(List networks); public delegate void StatusCallback(ZeroTierStatus status); + private string ZeroTierAddress = ""; + public static APIHandler Instance { get @@ -170,6 +172,11 @@ namespace WinUI try { status = JsonConvert.DeserializeObject(responseText); + + if (ZeroTierAddress != status.Address) + { + ZeroTierAddress = status.Address; + } } catch (JsonReaderException e) { @@ -442,5 +449,10 @@ namespace WinUI } } } + + public string NodeAddress() + { + return ZeroTierAddress; + } } } diff --git a/windows/WinUI/CentralAPI.cs b/windows/WinUI/CentralAPI.cs new file mode 100644 index 00000000..fc37aedf --- /dev/null +++ b/windows/WinUI/CentralAPI.cs @@ -0,0 +1,245 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace WinUI +{ + class CentralAPI + { + private static volatile CentralAPI instance; + private static object syncRoot = new Object(); + + private CookieContainer cookieContainer; + private HttpClientHandler clientHandler; + private HttpClient client; + + private CentralServer server; + public CentralServer Central + { + get + { + return this.server; + } + set + { + this.server = value; + WriteCentralConfig(); + UpdateRequestHeaders(); + } + } + + public static CentralAPI Instance + { + get + { + if (instance == null) + { + lock (syncRoot) + { + if (instance == null) + { + instance = new CentralAPI(); + } + } + } + + return instance; + } + } + + + + private CentralAPI() + { +#if DEBUG + ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; +#endif + cookieContainer = new CookieContainer(); + clientHandler = new HttpClientHandler + { + AllowAutoRedirect = true, + UseCookies = true, + CookieContainer = cookieContainer + }; + + client = new HttpClient(clientHandler); + + string centralConfigPath = CentralConfigFile(); + if (File.Exists(centralConfigPath)) + { + byte[] tmp = File.ReadAllBytes(centralConfigPath); + string json = Encoding.UTF8.GetString(tmp).Trim(); + Central = JsonConvert.DeserializeObject(json); + } + else + { + Central = new CentralServer(); + } + } + + public bool HasAccessToken() + { + if (Central == null) + return false; + + return !string.IsNullOrEmpty(Central.APIKey); + } + + private string ZeroTierDir() + { + return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ZeroTier\\One"; + } + + private string CentralConfigFile() + { + return ZeroTierDir() + "\\central.conf"; + } + + public void WriteCentralConfig() + { + string json = JsonConvert.SerializeObject(Central); + byte[] tmp = Encoding.UTF8.GetBytes(json); + File.WriteAllBytes(CentralConfigFile(), tmp); + } + + private void UpdateRequestHeaders() + { + if (client.DefaultRequestHeaders.Contains("Authorization")) + { + client.DefaultRequestHeaders.Remove("Authorization"); + } + + if (!string.IsNullOrEmpty(Central.APIKey)) + { + client.DefaultRequestHeaders.Add("Authorization", "bearer " + Central.APIKey); + } + } + + public async Task Login(string email, string password, bool isNewUser) + { + string postURL = Central.ServerURL + "/api/_auth/local"; + CentralLogin login = new CentralLogin(email, password, isNewUser); + var content = new StringContent(JsonConvert.SerializeObject(login), Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PostAsync(postURL, content); + + if (!response.IsSuccessStatusCode) + { + return false; + } + + string resContent = await response.Content.ReadAsStringAsync(); + + CentralUser user = JsonConvert.DeserializeObject(resContent); + + if (user.Tokens.Count == 0) + { + // create token + user = await CreateAuthToken(user); + } + + Central.APIKey = user.Tokens[0]; + + UpdateRequestHeaders(); + WriteCentralConfig(); + + return true; + } + + public async Task CreateAuthToken(CentralUser user) + { + string randomTokenURL = Central.ServerURL + "/api/randomToken"; + HttpResponseMessage response = await client.GetAsync(randomTokenURL); + + if (!response.IsSuccessStatusCode) + { + // TODO: throw an error + return null; + } + + string resContent = await response.Content.ReadAsStringAsync(); + + CentralToken t = JsonConvert.DeserializeObject(resContent); + + user.Tokens.Add(t.Token); + + string tokenObj = "{ \"tokens\": " + JsonConvert.SerializeObject(user.Tokens) + " } "; + + string postURL = Central.ServerURL + "/api/user/" + user.Id; + var postContent = new StringContent(tokenObj, Encoding.UTF8, "application/json"); + response = await client.PostAsync(postURL, postContent); + + if (!response.IsSuccessStatusCode) + { + // TODO: thrown an error + return null; + } + + resContent = await response.Content.ReadAsStringAsync(); + user = JsonConvert.DeserializeObject(resContent); + + return user; + } + + public async Task> GetNetworkList() + { + string networkURL = Central.ServerURL + "/api/network"; + + HttpResponseMessage response = await client.GetAsync(networkURL); + + if (!response.IsSuccessStatusCode) + { + // TODO: Throw Error + return new List(); + } + + string resContent = await response.Content.ReadAsStringAsync(); + + List networkList = JsonConvert.DeserializeObject>(resContent); + + return networkList; + } + + public async Task CreateNewNetwork() + { + string networkURL = Central.ServerURL + "/api/network/"; + CentralNetwork network = new CentralNetwork(); + network.Config = new CentralNetwork.CentralNetworkConfig(); + network.Config.Name = NetworkNameGenerator.GenerateName(); + string jsonNetwork = JsonConvert.SerializeObject(network); + var postContent = new StringContent(jsonNetwork, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PostAsync(networkURL, postContent); + + if (!response.IsSuccessStatusCode) + { + return null; + } + + string resContent = await response.Content.ReadAsStringAsync(); + + CentralNetwork newNetwork = JsonConvert.DeserializeObject(resContent); + + return newNetwork; + } + + public async Task AuthorizeNode(string nodeAddress, string networkId) + { + string json = "{ \"config\": { \"authorized\": true } }"; + string postURL = Central.ServerURL + "/api/network/" + networkId + "/member/" + nodeAddress; + var postContent = new StringContent(json, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PostAsync(postURL, postContent); + + if (response.IsSuccessStatusCode) + { + return true; + } + + return false; + } + } +} diff --git a/windows/WinUI/CentralLogin.cs b/windows/WinUI/CentralLogin.cs new file mode 100644 index 00000000..97265dcf --- /dev/null +++ b/windows/WinUI/CentralLogin.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace WinUI +{ + class CentralLogin + { + + + public CentralLogin(string email, string password, bool isNew) + { + Login = email; + Password = password; + IsNew = isNew; + } + + [JsonProperty("login")] + public string Login { get; set; } + + [JsonProperty("password")] + public string Password { get; set; } + + [JsonProperty("register")] + public bool IsNew { get; set; } + } +} diff --git a/windows/WinUI/CentralNetwork.cs b/windows/WinUI/CentralNetwork.cs new file mode 100644 index 00000000..26ad5234 --- /dev/null +++ b/windows/WinUI/CentralNetwork.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace WinUI +{ + class CentralNetwork + { + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("clock")] + public UInt64 Clock { get; set; } + + [JsonProperty("rulesSource")] + public string RulesSource { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("ownerId")] + public string OwnerID { get; set; } + + [JsonProperty("onlineMemberCount")] + public int OnlineMemberCount { get; set; } + + [JsonProperty("config")] + public CentralNetworkConfig Config { get; set; } + + public class CentralNetworkConfig + { + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("nwid")] + public string NetworkID { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + } + } +} diff --git a/windows/WinUI/CentralServer.cs b/windows/WinUI/CentralServer.cs new file mode 100644 index 00000000..8e268653 --- /dev/null +++ b/windows/WinUI/CentralServer.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace WinUI +{ + class CentralServer + { + public CentralServer() + { + ServerURL = "https://my.zerotier.com"; + } + + [JsonProperty("server_url")] + public string ServerURL { get; set; } + + [JsonProperty("api_key")] + public string APIKey { get; set; } + } +} diff --git a/windows/WinUI/CentralToken.cs b/windows/WinUI/CentralToken.cs new file mode 100644 index 00000000..1db548aa --- /dev/null +++ b/windows/WinUI/CentralToken.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace WinUI +{ + class CentralToken + { + [JsonProperty("token")] + public string Token { get; set; } + + [JsonProperty("clock")] + public UInt64 Clock { get; set; } + + [JsonProperty("raw")] + public string Raw { get; set; } + } +} diff --git a/windows/WinUI/CentralUser.cs b/windows/WinUI/CentralUser.cs new file mode 100644 index 00000000..8a8945a2 --- /dev/null +++ b/windows/WinUI/CentralUser.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace WinUI +{ + class CentralUser + { + public class CentralGlobalPermissions + { + [JsonProperty("a")] + public bool Administrator { get; set; } + + [JsonProperty("d")] + public bool Delete { get; set; } + + [JsonProperty("m")] + public bool Modify { get; set; } + + [JsonProperty("r")] + public bool Read { get; set; } + } + + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("clock")] + public UInt64 Clock { get; set; } + + [JsonProperty("globalPermissions")] + public CentralGlobalPermissions GlobalPermissions { get; set; } + + [JsonProperty("displayName")] + public string DisplayName { get; set; } + + [JsonProperty("email")] + public string Email { get; set; } + + [JsonProperty("smsNumber")] + public string SmsNumber { get; set; } + + [JsonProperty("tokens")] + public List Tokens { get; set; } + } +} diff --git a/windows/WinUI/ISwitchable.cs b/windows/WinUI/ISwitchable.cs new file mode 100644 index 00000000..e485a14c --- /dev/null +++ b/windows/WinUI/ISwitchable.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinUI +{ + interface ISwitchable + { + void UtilizeState(object state); + } +} diff --git a/windows/WinUI/NetworkNameGenerator.cs b/windows/WinUI/NetworkNameGenerator.cs new file mode 100644 index 00000000..8a75936d --- /dev/null +++ b/windows/WinUI/NetworkNameGenerator.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinUI +{ + class NetworkNameGenerator + { + public static string GenerateName() + { + Random r = new Random(DateTime.Now.Millisecond); + int firstIndex = r.Next(0, FIRST.Length); + int secondIndex = r.Next(0, SECOND.Length); + return FIRST[firstIndex] + "_" + SECOND[secondIndex]; + } + + private static string[] FIRST = + { + "admiring", + "adoring", + "agitated", + "amazing", + "angry", + "awesome", + "berserk", + "big", + "clever", + "compassionate", + "cranky", + "crazy", + "desperate", + "determined", + "distracted", + "dreamy", + "ecstatic", + "elated", + "elegant", + "fervent", + "focused", + "furious", + "gigantic", + "gloomy", + "goofy", + "grave", + "happy", + "high", + "hopeful", + "hungry", + "insane", + "jolly", + "jovial", + "lonely", + "loving", + "modest", + "nostalgic", + "pedantic", + "pensive", + "prickly", + "reverent", + "romantic", + "sad", + "serene", + "sharp", + "silly", + "sleepy", + "stoic", + "stupefied", + "suspicious", + "tender", + "thirsty", + "tiny", + "trusting" + }; + + private static string[] SECOND = + { + // constructed telephone-like devices in 1854 + "meucci", + + // prototype make-or-break telephones in 1860 + "reis", + + // Alexander Graham Bell + "bell", + + // designed telephone using water microphone in 1876 + "gray", + + // Tivadar Puskás invented the telephone switchboard exchange in 1876. + "puskas", + + // Thomas Edison, invented the carbon microphone which produced a strong telephone signal. + "edison", + + // 1950s, Paul Baran developed the concept Distributed Adaptive Message Block Switching + "baran", + + // Donald Davies coined the phrase 'packet switching network' + "davies", + + // Robert Licklider helped get ARPANET funded + "licklider", + + // Robert Taylor, ARPANET pioneer + "taylor", + + // Lawrence Roberts, ARPANET + "roberts", + + // Vint Cerf, TCP + "cerf", + + // Bob Kahn, TCP + "kahn", + + // David P Reed, UDP + "reed", + + // Community Memory was created by Efrem Lipkin, Mark Szpakowski, and Lee Felsenstein, acting as The Community Memory Project within the Resource One computer center at Project One in San Francisco. + "lipkin", + "szpakowski", + "felsenstein", + + // The first public dial-up BBS was developed by Ward Christensen and Randy Suess. + "christensen", + "suess", + + // Joybubbles (May 25, 1949 – August 8, 2007), born Josef Carl Engressia, Jr. in Richmond, Virginia, USA, was an early phone phreak. + "engressia", + "joybubbles", + + // John Thomas Draper (born 1943), also known as Captain Crunch, Crunch or Crunchman (after Cap'n Crunch breakfast cereal mascot), is an American computer programmer and former phone phreak + "draper", + + // Dennis C. Hayes, founder of Hayes Microcomputer Products + // "The Modem of Dennis Hayes and Dale Heatherington." + "hayes", + "heatherington", + + // "Ethernet was developed at Xerox PARC between 1973 and 1974.[7][8] It was inspired by ALOHAnet, which Robert Metcalfe had studied as part of his PhD dissertation." + "metcalfe", + + // William Bradford Shockley Jr. (February 13, 1910 – August 12, 1989) was an American physicist and inventor. Shockley was the manager of a research group that included John Bardeen and Walter Brattain. The three scientists invented the point contact transistor in 1947 + "shockley", + "bardeen", + "brattain", + + // "Randall Erck invented the modern modem as we know it today. There were devices similar to modems used by the military, but they were designed more for the purpose of sending encripted nuclear launch codes to various bases around the world." + "erck", + + // Leonard Kleinrock, packet switching network pioneer + "kleinrock", + + // Tim Berners-Lee, WWW + "berners_lee", + + // Steve Wozniak, early phone phreak + "wozniak", + + // James Fields Smathers of Kansas City invented what is considered the first practical power-operated typewriter in 1914. + "smathers", + + // The teleprinter evolved through a series of inventions by a number of engineers, including Royal Earl House, David Edward Hughes, Emile Baudot, Donald Murray, Charles L. Krum, Edward Kleinschmidt and Frederick G. Creed. + "house", + "hughes", + "baudot", + "murray", + "krum", + "kleinschmidt", + "creed", + + // Ron Rosenbaum, author of "Secrets of the Little Blue Box" which mainstreamed phone phreaking + "rosenbaum", + + // Bram Cohen. Bram Cohen (born October 12, 1975) is an American computer programmer, best known as the author of the peer-to-peer (P2P) BitTorrent protocol, + "cohen", + + // Jarkko Oikarinen (born 16 August 1967, in Kuusamo, Finland) is the inventor of the first Internet chat network, called Internet Relay Chat (IRC), where he is known as WiZ. + "oikarinen", + + // "What you probably didn't know is that the author of Trumpet Winsock — Peter Tattam from Tasmania, Australia — didn't see much money for his efforts." + "tattam", + + // Satoshi Nakamoto + "nakamoto", + + // Philo Farnsworth, inventor of the first practical TV tube + "farnsworth", + + // Scottish inventor John Logie Baird employed the Nipkow disk in his prototype video systems. On 25 March 1925, Baird gave the first public demonstration of televised silhouette images in motion, at Selfridge's Department Store in London. + "baird", + + // Beginning in 1836, the American artist Samuel F. B. Morse, the American physicist Joseph Henry, and Alfred Vail developed an electrical telegraph system. + "morse", + "henry", + "vail" + }; + } +} diff --git a/windows/WinUI/OnboardProcess/CreateAccount.xaml b/windows/WinUI/OnboardProcess/CreateAccount.xaml new file mode 100644 index 00000000..ddf50252 --- /dev/null +++ b/windows/WinUI/OnboardProcess/CreateAccount.xaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/windows/WinUI/OnboardProcess/CreateAccount.xaml.cs b/windows/WinUI/OnboardProcess/CreateAccount.xaml.cs new file mode 100644 index 00000000..72ba2182 --- /dev/null +++ b/windows/WinUI/OnboardProcess/CreateAccount.xaml.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace WinUI.OnboardProcess +{ + /// + /// Interaction logic for CreateAccount.xaml + /// + public partial class CreateAccount : UserControl, ISwitchable + { + public CreateAccount() + { + InitializeComponent(); + } + + public void UtilizeState(object state) + { + throw new NotImplementedException(); + } + + public void CreateAccount_Click(object sender, RoutedEventArgs e) + { + DoCreateAccount(); + } + + public void BackButton_Click(object sender, RoutedEventArgs e) + { + Switcher.Switch(new RegisterOrLogIn()); + } + + public async void DoCreateAccount() + { + if (PasswordTextBox1.Password.ToString() != PasswordTextBox2.Password.ToString()) + { + ErrorText.Content = "Passwords do not match!"; + } + else + { + CentralAPI api = CentralAPI.Instance; + bool accountCreated = await api.Login(EmailAddressTextBox.Text, + PasswordTextBox1.Password.ToString(), true); + + if (accountCreated) + { + Switcher.Switch(new CreateOrJoin()); + } + else + { + ErrorText.Content = "An error ocurred while creating your account."; + } + } + } + } +} diff --git a/windows/WinUI/OnboardProcess/CreateOrJoin.xaml b/windows/WinUI/OnboardProcess/CreateOrJoin.xaml new file mode 100644 index 00000000..21413e84 --- /dev/null +++ b/windows/WinUI/OnboardProcess/CreateOrJoin.xaml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + diff --git a/windows/WinUI/OnboardProcess/Finished.xaml.cs b/windows/WinUI/OnboardProcess/Finished.xaml.cs new file mode 100644 index 00000000..a34abfe2 --- /dev/null +++ b/windows/WinUI/OnboardProcess/Finished.xaml.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace WinUI.OnboardProcess +{ + /// + /// Interaction logic for Finished.xaml + /// + public partial class Finished : UserControl, ISwitchable + { + public Finished() + { + InitializeComponent(); + } + public void UtilizeState(object state) + { + throw new NotImplementedException(); + } + + private void DoneButton_Click(object sender, RoutedEventArgs e) + { + Window.GetWindow(this).Close(); + } + } +} diff --git a/windows/WinUI/OnboardProcess/LogIn.xaml b/windows/WinUI/OnboardProcess/LogIn.xaml new file mode 100644 index 00000000..501f7e0f --- /dev/null +++ b/windows/WinUI/OnboardProcess/LogIn.xaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/windows/WinUI/OnboardProcess/LogIn.xaml.cs b/windows/WinUI/OnboardProcess/LogIn.xaml.cs new file mode 100644 index 00000000..8657b800 --- /dev/null +++ b/windows/WinUI/OnboardProcess/LogIn.xaml.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace WinUI.OnboardProcess +{ + /// + /// Interaction logic for LogIn.xaml + /// + public partial class LogIn : UserControl, ISwitchable + { + public LogIn() + { + InitializeComponent(); + } + + public void UtilizeState(object state) + { + throw new NotImplementedException(); + } + + public void LoginButton_Click(object sender, RoutedEventArgs e) + { + DoLogin(); + } + + public void BackButton_Click(object sender, RoutedEventArgs e) + { + Switcher.Switch(new RegisterOrLogIn()); + } + + private async void DoLogin() + { + CentralAPI api = CentralAPI.Instance; + bool didLogIn = await api.Login(EmailAddressTextBox.Text, PasswordTextBox.Password.ToString(), false); + if (didLogIn) + { + Switcher.Switch(new CreateOrJoin()); + } + else + { + ErrorText.Content = "Invalid username or password"; + } + } + } +} diff --git a/windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml b/windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml new file mode 100644 index 00000000..01f3ba9d --- /dev/null +++ b/windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml @@ -0,0 +1,27 @@ + + + Welcome to ZeroTier + Let's get started! + + If you haven't yet created an account, click "Create Account" below. If you have an account, you can log in with your username/password, or simply enter an API key. + + + + +