ShiftOS_TheReturn/ShiftOS.WinForms/UniteSignupDialog.cs

110 lines
3 KiB
C#
Raw Permalink Normal View History

2017-04-30 22:50:54 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ShiftOS.Engine;
2017-04-30 23:26:00 +00:00
using Newtonsoft.Json;
using System.Net;
2017-05-21 12:21:41 +00:00
using ShiftOS.Objects;
using System.Runtime.InteropServices;
2017-04-30 22:50:54 +00:00
namespace ShiftOS.WinForms
{
public partial class UniteSignupDialog : UserControl, IShiftOSWindow
{
// sets a placeholder value on a control using Windows API voodoo
private static void SetPlaceholder(Control ctl, string txt)
{
IntPtr str = IntPtr.Zero;
try
{
str = Marshal.StringToHGlobalUni(txt);
var msgSetPlaceholder = Message.Create(ctl.Handle, 0x1501, IntPtr.Zero, str);
NativeWindow.FromHandle(ctl.Handle).DefWndProc(ref msgSetPlaceholder);
}
finally
{
if (str != IntPtr.Zero)
Marshal.FreeHGlobal(str);
}
}
public class SignupCredentials
{
public string SystemName { get; set; }
public string Username { get; set; }
public string RootPassword { get; set; }
}
public UniteSignupDialog(Action<SignupCredentials> callback)
2017-04-30 22:50:54 +00:00
{
InitializeComponent();
Callback = callback;
}
private Action<SignupCredentials> Callback { get; set; }
2017-04-30 22:50:54 +00:00
public void OnLoad()
{
this.ParentForm.AcceptButton = btnlogin;
SetPlaceholder(txtsys, "Hostname");
SetPlaceholder(txtuname, "Username");
SetPlaceholder(txtroot, "Password");
txtroot.Size = txtuname.Size; // AppearanceManager stop breaking my design REEEEE
2017-04-30 22:50:54 +00:00
}
public void OnSkinLoad()
{
}
public bool OnUnload()
{
return true;
}
public void OnUpgrade()
{
}
2017-04-30 23:26:00 +00:00
private void btnlogin_Click(object sender, EventArgs e)
{
string sys = txtsys.Text;
string uname = txtuname.Text;
string root = txtroot.Text;
2017-04-30 23:26:00 +00:00
// validation
if (string.IsNullOrWhiteSpace(sys))
2017-04-30 23:26:00 +00:00
{
Infobox.Show("{TITLE_EMPTY_SYSNAME}", "{MSG_EMPTY_SYSNAME}");
2017-04-30 23:26:00 +00:00
return;
}
if (sys.Length < 5)
2017-04-30 23:26:00 +00:00
{
Infobox.Show("{TITLE_VALIDATION_ERROR}", "{MSG_VALIDATION_ERROR_SYSNAME_LENGTH}");
2017-04-30 23:26:00 +00:00
return;
}
if (string.IsNullOrWhiteSpace(uname))
{
Infobox.Show("{TITLE_VALIDATION_ERROR}", "You must provide a username.");
return;
}
Callback?.Invoke(new SignupCredentials
2017-04-30 23:26:00 +00:00
{
SystemName = sys,
Username = uname,
RootPassword = root
});
2017-06-30 19:35:09 +00:00
AppearanceManager.Close(this);
2017-04-30 23:26:00 +00:00
}
2017-04-30 22:50:54 +00:00
}
}