using Shared.SimpleControl;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Security.Cryptography;
|
using System.Text;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class AccountLogin : Dialog
|
{
|
public AccountLogin (string account = "", string password = "")
|
{
|
LoginViewShow (account, password);
|
}
|
|
public void LoginViewShow (string account = "", string password = "")
|
{
|
|
|
var bodyView = new FrameLayout () {
|
BackgroundColor = SkinStyle.Current.ViewColor
|
};
|
AddChidren (bodyView);
|
|
if (MainPage.LoginUser != null && MainPage.LoginUser.IsLogin == true) {
|
this.Close ();
|
AccountView accView = new AccountView ();
|
UserMiddle.SettingPageView.AddChidren (accView);
|
accView.ShouwAccountView ();
|
UserMiddle.SettingPageView.PageIndex = UserMiddle.SettingPageView.ChildrenCount - 1;
|
}
|
|
//UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor;
|
if (account == "") {
|
if (MainPage.LoginUser != null ) {
|
account = MainPage.LoginUser.AccountString;
|
}
|
}
|
|
FrameLayout logoView = new FrameLayout () {
|
Height = Application.GetRealHeight (400),
|
};
|
bodyView.AddChidren (logoView);
|
|
Button btnLogo = new Button () {
|
Y = Application.GetRealHeight (30),
|
Height = Application.GetMinRealAverage (430),
|
UnSelectedImagePath = MainPage.RegisterLogoString,
|
};
|
logoView.AddChidren (btnLogo);
|
|
var accountView = new FrameLayout () {
|
Width = Application.GetMinRealAverage (500),
|
Height = Application.GetMinRealAverage (85),
|
X = Application.GetRealWidth (70),
|
Y = btnLogo.Bottom + Application.GetRealHeight (30),
|
BackgroundImagePath = "Register/Register_Email_Address.png",
|
Radius = (uint)Application.GetRealHeight (0),
|
};
|
bodyView.AddChidren (accountView);
|
|
var etAccount = new EditText () {
|
Width = Application.GetRealWidth (400),
|
X = Application.GetRealWidth (100),
|
PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor,
|
PlaceholderText = Language.StringByID (R.MyInternationalizationString.Account),
|
TextAlignment = TextAlignment.CenterLeft,
|
Radius = (uint)Application.GetRealHeight (0),
|
TextColor = SkinStyle.Current.TextColor1,
|
Text = account,
|
};
|
#if DEBUG
|
etAccount.Text = "2791308028@qq.com";
|
//etAccount.Text = "751083166@qq.com";
|
//etAccount.Text = "18520468203";
|
//etAccount.Text = "13585007789-debug";
|
//etAccount.Text = "balina3ban72-debug@gmail.com";
|
//etAccount.Text = "smartlifeks.user01@gmail.com";
|
#endif
|
accountView.AddChidren (etAccount);
|
|
var userConfigBytes = IO.FileUtils.ReadFile ("AccountListDB");
|
var userConfigString = CommonPage.MyEncodingUTF8.GetString (userConfigBytes);
|
AccountListDB accountListDB = null;
|
if (userConfigString != null) {
|
accountListDB = Newtonsoft.Json.JsonConvert.DeserializeObject<AccountListDB> (userConfigString);
|
}
|
if (accountListDB == null) {
|
accountListDB = new AccountListDB ();
|
}
|
var accountList = accountListDB.account;
|
|
var passwrodView = new FrameLayout () {
|
Width = Application.GetMinRealAverage (500),
|
Height = Application.GetMinRealAverage (85),
|
X = Application.GetRealWidth (70),
|
Y = accountView.Bottom + Application.GetRealHeight (50),
|
BackgroundImagePath = "Register/Register_Password_kuang.png",
|
};
|
bodyView.AddChidren (passwrodView);
|
|
var etPasswrod = new EditText () {
|
Width = Application.GetRealWidth (400 - 73),
|
X = Application.GetRealWidth (100),
|
PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor,
|
PlaceholderText = Language.StringByID (R.MyInternationalizationString.PleaseEnterPassword),
|
TextAlignment = TextAlignment.CenterLeft,
|
SecureTextEntry = true,
|
TextColor = SkinStyle.Current.TextColor1,
|
|
Text = password,
|
};
|
#if DEBUG
|
etPasswrod.Text = "123456";
|
#endif
|
passwrodView.AddChidren (etPasswrod);
|
|
Button btnShowPassword = new Button () {
|
X = etPasswrod.Right,
|
Y = etPasswrod.Y + Application.GetRealHeight (12),
|
Width = Application.GetRealWidth (73),
|
Height = Application.GetRealHeight (60),
|
SelectedImagePath = "CrabtreeAdd/ShowPW.png",
|
UnSelectedImagePath = "CrabtreeAdd/HidePW.png",
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 2,
|
Radius = 1
|
};
|
passwrodView.AddChidren (btnShowPassword);
|
btnShowPassword.MouseUpEventHandler += (dd, ff) => {
|
btnShowPassword.IsSelected = !btnShowPassword.IsSelected;
|
etPasswrod.SecureTextEntry = !btnShowPassword.IsSelected;
|
};
|
|
#if DEBUG
|
int NigelLoginPass = 0;
|
btnLogo.MouseUpEventHandler += (sender, e) => {
|
if (NigelLoginPass == 3) {
|
etAccount.Text = @"464027401@qq.com";
|
etPasswrod.Text = "qqqqqq";
|
} else if (NigelLoginPass == 5) {
|
etAccount.Text = @"HDL_R_D_Department";
|
etPasswrod.Text = "85521566";
|
} else if (NigelLoginPass == 8) {
|
etAccount.Text = @"Support5-debug@hdlchina.com.cn";
|
etPasswrod.Text = "85521566";
|
} else if (NigelLoginPass == 9) {
|
etAccount.Text = @"15961821355-debug";
|
etPasswrod.Text = "123456";
|
}
|
NigelLoginPass++;
|
};
|
#endif
|
etAccount.EditorEnterAction += (obj) => {
|
Application.HideSoftInput ();
|
etPasswrod.Foucs = true;
|
};
|
etPasswrod.EditorEnterAction += (obj) => {
|
Application.HideSoftInput ();
|
};
|
|
Button btnRegister = new Button () {
|
Width = Application.GetRealWidth (200),
|
Height = Application.GetRealHeight (85),
|
X = Application.GetRealWidth (70),
|
Y = passwrodView.Bottom + Application.GetRealHeight (10),
|
TextID = R.MyInternationalizationString.Register,
|
TextSize = 15,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
btnRegister.MouseUpEventHandler += (sender, e) => {
|
Close ();
|
new AccountRegistration ().Show ();
|
};
|
bodyView.AddChidren (btnRegister);
|
|
Button btnForgotPassword = new Button () {
|
Width = Application.GetRealWidth (500 / 2),
|
Height = Application.GetRealHeight (85),
|
X = btnRegister.Right + Application.GetRealWidth (50),
|
Y = passwrodView.Bottom + Application.GetRealHeight (10),
|
TextID = R.MyInternationalizationString.ForgotPassword,
|
TextSize = 15,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextAlignment = TextAlignment.CenterRight,
|
};
|
btnForgotPassword.MouseUpEventHandler += (sender, e) => {
|
new ForgotPassword ().Show ();
|
this.Close ();
|
};
|
bodyView.AddChidren (btnForgotPassword);
|
|
Button btnLogin = new Button () {
|
Width = Application.GetRealWidth (504),
|
Height = Application.GetRealHeight (89),
|
X = Application.GetRealWidth (60),
|
Y = btnRegister.Bottom + Application.GetRealHeight (70),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
TextID = R.MyInternationalizationString.Login,
|
TextSize = 15,
|
TextColor = SkinStyle.Current.TextColor1,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 0,
|
};
|
bodyView.AddChidren (btnLogin);
|
btnLogin.MouseDownEventHandler += (sender, e) => {
|
btnLogin.IsSelected = true;
|
};
|
|
btnLogin.MouseUpEventHandler += (sender, e) => {
|
btnLogin.IsSelected = false;
|
account = etAccount.Text.Trim ();
|
password = etPasswrod.Text.Trim ();
|
if (string.IsNullOrEmpty (account) && string.IsNullOrEmpty (password)) {
|
Application.RunOnMainThread (() => {
|
new Tip () { Text =Language.StringByID(R.MyInternationalizationString.PleaseEnterYourLoginDetails), Direction = AMPopTipDirection.Up, CloseTime = 3 }.Show (btnLogo);
|
});
|
return;
|
}
|
if (string.IsNullOrEmpty (account)) {
|
Application.RunOnMainThread (() => {
|
new Tip () { Text = Language.StringByID (R.MyInternationalizationString.PleaseEnterYourUserLogonName), Direction = AMPopTipDirection.Up, CloseTime = 3 }.Show (btnLogo);
|
});
|
return;
|
}
|
if (string.IsNullOrEmpty (password)) {
|
Application.RunOnMainThread (() => {
|
new Tip () { Text = Language.StringByID (R.MyInternationalizationString.PleaseEnterYourUserLogonPassword), Direction = AMPopTipDirection.Up, CloseTime = 3 }.Show (btnLogo);
|
});
|
return;
|
}
|
new System.Threading.Thread (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
if (Language.CurrentLanguage == "Chinese") {
|
MainPage.Loading.Start ("登录中...");
|
} else {
|
MainPage.Loading.Start ("Login...");
|
}
|
});
|
if (UserConfig.Instance.internetStatus == 0 || !MainPage.checeInternet ()) {
|
Application.RunOnMainThread (() => {
|
new Tip () { Text = Language.StringByID (R.MyInternationalizationString.NetworkAbnormal), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show (btnLogo);
|
});
|
return;
|
}
|
|
var revertConnectionObj = MainPage.RequestHttps ("Connection", "");
|
if (revertConnectionObj.StateCode == "SUCCESS") {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.LinkServerSuccessful));
|
});
|
|
var requestObj = new LoginObj () { Account = account, Password = password, Company = MainPage.SoftSmsType };
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
|
var revertObj = MainPage.RequestHttps ("Login", requestJson, false);
|
if (revertObj.StateCode == "SUCCESS") {
|
if (!accountListDB.account.Contains (account)) {
|
accountListDB.account.Add (account);
|
accountListDB.SaveAccountListDB ();
|
}
|
|
var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginRes> (revertObj.ResponseData.ToString ());
|
var revertData = responseDataObj;
|
MainPage.LoginUser = new UserInfo {
|
ID = revertData.UserId, MasterID = revertData.MainUserId, AccountType = revertData.UserType, AccountString = account, Password = password, LastTime = DateTime.Now,
|
AllVisionRegisterDevUserNameGuid = revertData.AllVisionRegisterDevUserNameGuid,
|
EmqServerId = revertData.EmqServerId
|
};
|
|
////2020-02-27 判断是否需要自动选择服务器
|
//AccountSelectServer.CheckIfAutoSelectServer (revertData.EmqServerId);
|
|
|
string DeviceType = "android";
|
#if __IOS__
|
DeviceType = "iphone";
|
|
|
#endif
|
var mAddRegIDObj = new AddRegIDObj () {
|
RegID = UserConfig.Instance.tokenID,
|
Alias = UserConfig.Instance.phoneName,
|
Account = account,
|
UserMode = 2,
|
};
|
var mAddRegIDObjJson = Newtonsoft.Json.JsonConvert.SerializeObject (mAddRegIDObj);
|
MainPage.RequestHttps (@"AddRegID", mAddRegIDObjJson, true, false);
|
|
|
//string jsonString = "{" +
|
// "\"RegID\":" + "\"" + UserConfig.Instance.tokenID + "\"" + "," +
|
// "\"Alias\":" + "\"" + UserConfig.Instance.phoneName + "\"" + "," +
|
// "\"Account\":" + "\"" + account + "\"" +
|
// "}";
|
//MainPage.RequestHttps (@"AddRegID", jsonString, true);
|
|
#if wallon
|
#else
|
if (!string.IsNullOrEmpty (MainPage.LoginUser.AllVisionRegisterDevUserNameGuid)) {
|
//可视对讲
|
Application.RunOnMainThread (() => {
|
#if Android
|
(Application.Activity as BaseActivity).ReadWriteContact ((b) => {
|
if (b) {
|
com.freeview.global.Video.Init (MainPage.LoginUser.LoginTokenString, MainPage.LoginUser.AllVisionRegisterDevUserNameGuid);
|
}
|
});
|
#else
|
com.freeview.global.Video.Init (MainPage.LoginUser.LoginTokenString, MainPage.LoginUser.AllVisionRegisterDevUserNameGuid);
|
#endif
|
});
|
|
UserConfig.Instance.HideDeviceTypes.Distinct ().ToList ();
|
UserConfig.Instance.DeviceTypes.Distinct ().ToList ();
|
if (UserConfig.Instance.HideDeviceTypes.Contains (R.MyInternationalizationString.VideoIntercom))
|
UserConfig.Instance.HideDeviceTypes.Remove (R.MyInternationalizationString.VideoIntercom);
|
} else {
|
if (!UserConfig.Instance.HideDeviceTypes.Contains (R.MyInternationalizationString.VideoIntercom))
|
UserConfig.Instance.HideDeviceTypes.Add (R.MyInternationalizationString.VideoIntercom);
|
}
|
#endif
|
|
var requestObj2 = new HomeListObj ();
|
var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2);
|
var revertObj2 = MainPage.RequestHttps ("HomeList", requestJson2);
|
if (revertObj2.StateCode == "SUCCESS") {
|
UserConfig.Instance.HomeLists = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RegionInfoRes>> (revertObj2.ResponseData.ToString ());
|
MainPage.LoginUser.LastTime = DateTime.Now;
|
accountListDB.AccountInfo.TryAdd (account.ToLower (), new AccountInfo () { Password = password, UserInfo = MainPage.LoginUser, RegionList = UserConfig.Instance.HomeLists });
|
accountListDB.SaveAccountListDB ();
|
|
|
if (UserConfig.Instance.HomeLists.Find ((obj) => obj.RegionID == UserConfig.Instance.CurrentRegion.RegionID) != null) {
|
UserConfig.Instance.SaveUserConfig ();
|
MainPage.LoginUser.SaveUserInfo ();
|
Room.InitAllRoom ();
|
Application.RunOnMainThread (() => {
|
UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor;
|
Close ();
|
UserMiddle.Init ();
|
EquipmentPublicClass.CheckLinkRemote (2);
|
});
|
return;
|
} else {
|
IO.FileUtils.DeleteAllFile ();
|
if (UserConfig.Instance.HomeLists.Count > 0) {
|
UserConfig.Instance.CurrentRegion = UserConfig.Instance.HomeLists [0];
|
foreach (var home in UserConfig.Instance.HomeLists) {
|
var sssd = IO.FileUtils.ExistRegion (home.RegionID.ToString ());
|
Console.WriteLine ("IO.FileUtils.ExistRegion (home.RegionID.ToString()); " + sssd.ToString ());
|
|
if (sssd) {
|
string newRegionRootPath = IO.FileUtils.CreateRegionBackup (home.RegionID.ToString ());
|
IO.FileUtils.RestoreRegionFiles (newRegionRootPath);
|
UserConfig.Instance.RefreshUserConfig ();
|
UserConfig.Instance.CurrentRegion = home;
|
break;
|
}
|
}
|
} else {
|
//创建默认住宅
|
var requestObj21 = new AddHomeAndGatewayByONObj () { Region = "Home", MAC = "" };
|
var requestJson21 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj21);
|
var revertObj21 = MainPage.RequestHttps ("AddHomeAndGatewayByON", requestJson21);
|
if (revertObj21.StateCode == "SUCCESS") {
|
revertObj2 = MainPage.RequestHttps ("HomeList", requestJson2);
|
if (revertObj2.StateCode == "SUCCESS") {
|
UserConfig.Instance.HomeLists = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RegionInfoRes>> (revertObj2.ResponseData.ToString ());
|
UserConfig.Instance.CurrentRegion = UserConfig.Instance.HomeLists [0];
|
}
|
}
|
}
|
}
|
|
UserConfig.Instance.SaveUserConfig ();
|
MainPage.LoginUser.SaveUserInfo ();
|
Room.InitAllRoom ();
|
Application.RunOnMainThread (() => {
|
UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor;
|
Close ();
|
UserMiddle.Init ();
|
});
|
|
|
//var responseDataObj2 = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RegionInfoRes>> (revertObj2.ResponseData.ToString ());
|
//var revertRoomData = responseDataObj2;
|
//if (revertRoomData.Find ((obj) => obj.RegionID == UserConfig.Instance.CurrentRegion.RegionID) == null) {
|
//UserConfig.Instance.CurrentRegion = revertRoomData [0];
|
//UserConfig.Instance.GatewayMAC = revertRoomData [0].MAC;
|
//IO.FileUtils.DeleteAllFile ();
|
//} else {
|
//Room.InitAllRoom ();
|
//}
|
|
//var gatewayListObj = new GatewayListObj ();
|
//var gatewayListJson = Newtonsoft.Json.JsonConvert.SerializeObject (gatewayListObj);
|
//var gatewayListRevertObj = MainPage.RequestHttps ("GatewayList", gatewayListJson);
|
//if (true){//gatewayListRevertObj.StateCode == "SUCCESS") {
|
//UserConfig.Instance.GatewayList.Clear ();
|
//var responseGatewayDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GatewayRes>> (gatewayListRevertObj.ResponseData.ToString ());
|
//UserConfig.Instance.GatewayList.AddRange (responseGatewayDataObj);
|
//MainPage.LoginUser.LastTime = DateTime.Now;
|
//UserConfig.Instance.HomeLists = revertRoomData;
|
//if (UserConfig.Instance.GatewayList.Count == 0) {
|
// Application.RunOnMainThread (() => {
|
// UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor;
|
// UserMiddle.Init ();
|
// Close ();
|
// });
|
// return;
|
//} else {
|
// RemoteInfo.Current.ReadMsgList (false);
|
// MainPage.LoginUser.SaveUserInfo ();
|
// Scene.Refresh ();
|
// A31MusicModel.Refresh ();
|
// Application.RunOnMainThread (() => {
|
// UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor;
|
// Close ();
|
// UserMiddle.Init ();
|
// EquipmentPublicClass.CheckLinkRemote (2);
|
// });
|
//}
|
//UserConfig.Instance.SaveUserConfig ();
|
//}
|
}
|
}
|
}
|
} catch (Exception ex) {
|
MainPage.FailureToServer ();
|
Console.WriteLine (ex.Message);
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
}) { IsBackground = true}.Start();
|
};
|
|
var accountListView = new VerticalScrolViewLayout () {
|
Width = Application.GetRealWidth (500),
|
Height = Application.GetRealHeight (85 * 2),
|
Y = accountView.Bottom,
|
X = accountView.X,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
Visible = false,
|
};
|
bodyView.AddChidren (accountListView);
|
|
etAccount.FoucsChanged += ( sender, e) => {
|
//#if __IOS__
|
//btnRegister.Visible = btnForgotPassword.Visible = !e.Focus;
|
//#endif
|
foreach(var all in accountListDB.account) {
|
Console.WriteLine (all);
|
}
|
if (e.Focus) {
|
if (etAccount.Text == "")
|
accountList.Clear ();
|
else
|
accountList = accountListDB.account.FindAll ((obj) => (obj.Contains (etAccount.Text) && obj != etAccount.Text));
|
if (accountListView.Parent == null) {
|
Console.WriteLine ("accountListView");
|
bodyView.AddChidren (accountListView);
|
}
|
if (accountList.Count > 0) {
|
accountListView.Visible = e.Focus;
|
foreach (var dbAccount in accountList) {
|
Button btnDB_Account = new Button () {
|
Height = Application.GetRealHeight (85),
|
Radius = 1,
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 1,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
TextAlignment = TextAlignment.Center,
|
TextColor = SkinStyle.Current.TextColor1,
|
Text = dbAccount
|
};
|
accountListView.AddChidren (btnDB_Account);
|
btnDB_Account.MouseUpEventHandler += (asdd, eee) => {
|
etPasswrod.Foucs = true;
|
etAccount.Text = dbAccount;
|
//accountListView.Visible = false;
|
};
|
}
|
}
|
} else {
|
accountListView.Visible = e.Focus;
|
}
|
};
|
etAccount.TextChangeEventHandler += (sender, e) => {
|
foreach(var all in accountListDB.account) {
|
Console.WriteLine (all);
|
}
|
if (e.Length == 0) {
|
accountListView.Visible = false;
|
return;
|
}
|
accountList = accountListDB.account.FindAll ((obj) => (obj.Contains (e) && obj != e));
|
Console.WriteLine (accountList.Count);
|
if (accountList.Count == 0) {
|
accountListView.Visible = false;
|
return;
|
}
|
accountListView.Visible = true;
|
accountListView.RemoveAll ();
|
foreach (var dbAccount in accountList) {
|
Button btnDB_Account = new Button () {
|
Height = Application.GetRealHeight (85),
|
Radius = 1,
|
BorderColor = SkinStyle.Current.BorderColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
BorderWidth = 1,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
TextAlignment = TextAlignment.Center,
|
Text = dbAccount
|
};
|
accountListView.AddChidren (btnDB_Account);
|
btnDB_Account.MouseUpEventHandler += (asdd, eee) => {
|
etPasswrod.Foucs = true;
|
etAccount.Text = dbAccount;
|
accountListView.Visible = false;
|
};
|
}
|
};
|
|
btnLogo.MouseDownEventHandler += (sender, e) => {
|
Application.HideSoftInput ();
|
};
|
bodyView.MouseDownEventHandler += (sender, e) => {
|
Application.HideSoftInput ();
|
};
|
}
|
}
|
}
|