2017-04-30 18:50:54 -04: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 19:26:00 -04:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System.Net;
|
2017-05-21 08:21:41 -04:00
|
|
|
|
using ShiftOS.Objects;
|
2017-07-01 13:31:42 -04:00
|
|
|
|
using System.Runtime.InteropServices;
|
2017-04-30 18:50:54 -04:00
|
|
|
|
|
|
|
|
|
namespace ShiftOS.WinForms
|
|
|
|
|
{
|
|
|
|
|
public partial class UniteSignupDialog : UserControl, IShiftOSWindow
|
|
|
|
|
{
|
2017-07-01 13:31:42 -04:00
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-11 17:58:35 -04:00
|
|
|
|
public class SignupCredentials
|
|
|
|
|
{
|
|
|
|
|
public string SystemName { get; set; }
|
2017-07-01 13:31:42 -04:00
|
|
|
|
public string Username { get; set; }
|
2017-06-11 17:58:35 -04:00
|
|
|
|
public string RootPassword { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UniteSignupDialog(Action<SignupCredentials> callback)
|
2017-04-30 18:50:54 -04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
Callback = callback;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-11 17:58:35 -04:00
|
|
|
|
private Action<SignupCredentials> Callback { get; set; }
|
2017-04-30 18:50:54 -04:00
|
|
|
|
|
|
|
|
|
public void OnLoad()
|
|
|
|
|
{
|
|
|
|
|
this.ParentForm.AcceptButton = btnlogin;
|
2017-07-01 13:31:42 -04:00
|
|
|
|
SetPlaceholder(txtsys, "Hostname");
|
|
|
|
|
SetPlaceholder(txtuname, "Username");
|
|
|
|
|
SetPlaceholder(txtroot, "Password");
|
|
|
|
|
txtroot.Size = txtuname.Size; // AppearanceManager stop breaking my design REEEEE
|
2017-04-30 18:50:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnSkinLoad()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnUnload()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnUpgrade()
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-04-30 19:26:00 -04:00
|
|
|
|
|
|
|
|
|
private void btnlogin_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-06-11 17:58:35 -04:00
|
|
|
|
string sys = txtsys.Text;
|
2017-07-01 13:31:42 -04:00
|
|
|
|
string uname = txtuname.Text;
|
2017-06-11 17:58:35 -04:00
|
|
|
|
string root = txtroot.Text;
|
2017-04-30 19:26:00 -04:00
|
|
|
|
|
2017-07-01 13:31:42 -04:00
|
|
|
|
// validation
|
|
|
|
|
|
2017-06-11 17:58:35 -04:00
|
|
|
|
if (string.IsNullOrWhiteSpace(sys))
|
2017-04-30 19:26:00 -04:00
|
|
|
|
{
|
2017-06-11 17:58:35 -04:00
|
|
|
|
Infobox.Show("{TITLE_EMPTY_SYSNAME}", "{MSG_EMPTY_SYSNAME}");
|
2017-04-30 19:26:00 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-07-01 13:31:42 -04:00
|
|
|
|
|
|
|
|
|
if (sys.Length < 5)
|
2017-04-30 19:26:00 -04:00
|
|
|
|
{
|
2017-06-11 17:58:35 -04:00
|
|
|
|
Infobox.Show("{TITLE_VALIDATION_ERROR}", "{MSG_VALIDATION_ERROR_SYSNAME_LENGTH}");
|
2017-04-30 19:26:00 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-01 13:31:42 -04:00
|
|
|
|
if (string.IsNullOrWhiteSpace(uname))
|
|
|
|
|
{
|
|
|
|
|
Infobox.Show("{TITLE_VALIDATION_ERROR}", "You must provide a username.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-11 17:58:35 -04:00
|
|
|
|
Callback?.Invoke(new SignupCredentials
|
2017-04-30 19:26:00 -04:00
|
|
|
|
{
|
2017-06-11 17:58:35 -04:00
|
|
|
|
SystemName = sys,
|
2017-07-01 13:31:42 -04:00
|
|
|
|
Username = uname,
|
2017-06-11 17:58:35 -04:00
|
|
|
|
RootPassword = root
|
|
|
|
|
});
|
2017-06-30 15:35:09 -04:00
|
|
|
|
AppearanceManager.Close(this);
|
2017-04-30 19:26:00 -04:00
|
|
|
|
}
|
2017-04-30 18:50:54 -04:00
|
|
|
|
}
|
|
|
|
|
}
|