using System;
|
using Shared.Common;
|
using System.Text.RegularExpressions;
|
using System.Collections.Generic;
|
using System.Timers;
|
using Shared.Phone.UserView;
|
using Shared.Phone.Device.CommonForm;
|
|
namespace Shared.Phone.Login
|
{
|
/// <summary>
|
/// 验证码登录
|
/// </summary>
|
public class AccountLoginByCode : FrameLayout
|
{
|
|
#region ◆ 变量____________________________
|
/// <summary>
|
/// 背景视图
|
/// </summary>
|
private FrameLayout midFrameLayout;
|
/// <summary>
|
/// 手机邮箱
|
/// </summary>
|
private PhoneEmailForm phoneEmailForm;
|
/// <summary>
|
/// phoneRowForm
|
/// </summary>
|
private PhoneRowForm phoneRow;
|
/// <summary>
|
/// emailRow
|
/// </summary>
|
private EmailRowForm emailRow;
|
/// <summary>
|
/// codeRow
|
/// </summary>
|
private VerificationCodeRowForm codeRow;
|
/// <summary>
|
/// 账号验证码fl
|
/// </summary>
|
private FrameLayout accountCodeFL;
|
/// <summary>
|
/// 登录按钮
|
/// </summary>
|
private Button loginBtn;
|
/// <summary>
|
/// 忘记密码按钮
|
/// </summary>
|
private Button forgotPasswordBtn;
|
/// <summary>
|
/// 注册
|
/// </summary>
|
private Button registerBtn;
|
/// <summary>
|
/// 账号登录
|
/// </summary>
|
private Button LoginByAccountPWDBtn;
|
/// <summary>
|
/// 登录错误提示按钮
|
/// </summary>
|
private Button loginErrorBtn;
|
/// <summary>
|
/// 账号
|
/// </summary>
|
private string account;
|
/// <summary>
|
/// 验证码
|
/// </summary>
|
private string code;
|
/// <summary>
|
/// wechat
|
/// </summary>
|
private Button wechatBtn;
|
|
private Timer t;
|
private DateTime dateBegin;
|
|
#endregion
|
|
|
/// <summary>
|
/// The phone string.
|
/// </summary>
|
//public string phoneStr = "";
|
/// <summary>
|
/// 手机号输入是否符合规则
|
/// </summary>
|
public bool IsRightAccount = false;
|
/// <summary>
|
/// Initializes a new instance of the <see cref="T:Shared.Phone.Device.Account.AccountLoginByCode"/> class.
|
/// </summary>
|
public AccountLoginByCode()
|
{
|
CommonPage.Instance.IsDrawerLockMode = true;
|
Tag = "Login";
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
|
t = new Timer();
|
dateBegin = new DateTime();
|
}
|
public override void RemoveFromParent()
|
{
|
base.RemoveFromParent();
|
}
|
/// <summary>
|
/// Show this instance.
|
/// </summary>
|
public void Show()
|
{
|
ShowLoginByCodeView();
|
}
|
/// <summary>
|
/// Shows the login by code view.
|
/// </summary>
|
public void ShowLoginByCodeView()
|
{
|
#region midFrameLayout
|
midFrameLayout = new FrameLayout()
|
{
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight(CommonPage.AppRealHeight),
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
|
};
|
AddChidren(midFrameLayout);
|
#endregion
|
|
var logoBG = new Button()
|
{
|
Height = Application.GetRealHeight(619),
|
UnSelectedImagePath = "Account/Logo_loginBG.png"
|
};
|
midFrameLayout.AddChidren(logoBG);
|
|
var phoneEmailBGFL = new FrameLayout()
|
{
|
Y = logoBG.Bottom,
|
Height = Application.GetRealHeight(1921),
|
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor
|
};
|
midFrameLayout.AddChidren(phoneEmailBGFL);
|
|
var logo = new Button()
|
{
|
Width = Application.GetMinRealAverage(184),
|
Height = Application.GetMinRealAverage(184),
|
Y = Application.GetRealHeight(230),
|
UnSelectedImagePath = "Account/Logo_White.png",
|
Gravity = Gravity.CenterHorizontal
|
};
|
midFrameLayout.AddChidren(logo);
|
|
var logoName = new Button()
|
{
|
Y = logo.Bottom,
|
Height = Application.GetRealHeight(69),
|
Width = Application.GetRealWidth(300),
|
Gravity = Gravity.CenterHorizontal,
|
TextID = R.MyInternationalizationString.AppName,
|
TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
TextSize = 16
|
};
|
midFrameLayout.AddChidren(logoName);
|
|
phoneEmailForm = new PhoneEmailForm();
|
phoneEmailForm.Init(midFrameLayout);
|
|
//错误提示Btn
|
loginErrorBtn = new Button()
|
{
|
X = Application.GetRealWidth(242),
|
Y = Application.GetRealHeight(740),
|
Width = Application.GetRealWidth(700),
|
Height = Application.GetRealHeight(58),
|
TextColor = ZigbeeColor.Current.GXCTextRed,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = CommonFormResouce.TextSize,
|
IsBold = true
|
};
|
midFrameLayout.AddChidren(loginErrorBtn);
|
|
accountCodeFL = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(801),
|
Height = Application.GetRealHeight(553),
|
Width = Application.GetRealWidth(942),
|
Gravity = Gravity.CenterHorizontal,
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
|
Radius = (uint)Application.GetRealHeight(17)
|
};
|
midFrameLayout.AddChidren(accountCodeFL);
|
|
AddPhoneOrEmailFL(accountCodeFL, "Phone");
|
|
forgotPasswordBtn = new Button()
|
{
|
X = Application.GetRealWidth(CommonPage.AppRealWidth - 115 - 250),
|
Y = Application.GetRealHeight(1198),
|
Width = Application.GetRealWidth(250),
|
Height = Application.GetRealHeight(58),
|
TextID = R.MyInternationalizationString.ForgotPWD_1,
|
TextSize = CommonFormResouce.loginTextSize,
|
TextColor = Shared.Common.ZigbeeColor.Current.GXCTextGrayColor,
|
TextAlignment = TextAlignment.CenterRight
|
};
|
midFrameLayout.AddChidren(forgotPasswordBtn);
|
|
loginBtn = new Button()
|
{
|
Y = Application.GetRealHeight(1281),
|
Width = Application.GetRealWidth(688),
|
Height = Application.GetRealHeight(127),
|
Gravity = Gravity.CenterHorizontal,
|
TextID = R.MyInternationalizationString.Login,
|
TextSize = 16,
|
IsBold=true,
|
TextColor = ZigbeeColor.Current.GXCTextGrayColor,
|
SelectedTextColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
SelectedBackgroundColor = ZigbeeColor.Current.GXCButtonBlackSelectedColor,
|
BackgroundColor = ZigbeeColor.Current.GXCButtonUnSelectedColor,
|
Radius = (uint)Application.GetRealHeight(127 / 2),
|
Enable = !string.IsNullOrEmpty(codeRow.VerificationCodeET?.Text),
|
IsSelected = !string.IsNullOrEmpty(codeRow.VerificationCodeET?.Text)
|
};
|
midFrameLayout.AddChidren(loginBtn);
|
|
LoginByAccountPWDBtn = new Button()
|
{
|
X = Application.GetRealWidth(98),
|
Y = Application.GetRealHeight(1466),
|
Width = Application.GetRealWidth(300),
|
Height = Application.GetRealHeight(49),
|
TextID = R.MyInternationalizationString.LoginByAccountPWD,
|
TextColor = ZigbeeColor.Current.GXCTextGrayColor,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = CommonFormResouce.loginTextSize
|
};
|
midFrameLayout.AddChidren(LoginByAccountPWDBtn);
|
|
registerBtn = new Button()
|
{
|
X = Application.GetRealWidth(738),
|
Y = Application.GetRealHeight(1466),
|
Width = Application.GetRealWidth(244),
|
Height = Application.GetRealHeight(49),
|
TextID = R.MyInternationalizationString.Register,
|
TextColor = ZigbeeColor.Current.GXCTextGrayColor,
|
TextAlignment = TextAlignment.CenterRight,
|
TextSize = CommonFormResouce.loginTextSize
|
};
|
midFrameLayout.AddChidren(registerBtn);
|
|
wechatBtn = new Button
|
{
|
X = Application.GetRealWidth(395),
|
Y = Application.GetRealHeight(1737),
|
Width = Application.GetMinRealAverage(115),
|
Height = Application.GetMinRealAverage(115),
|
UnSelectedImagePath = "Account/Wechat.png",
|
Gravity = Gravity.CenterHorizontal
|
};
|
midFrameLayout.AddChidren(wechatBtn);
|
|
BindEvent();
|
}
|
|
#region ◆ 绑定事件_________________________
|
|
/// <summary>
|
/// 绑定按钮事件
|
/// </summary>
|
private void BindEvent()
|
{
|
//选择手机邮箱
|
phoneEmailForm.SelectedPhone.MouseUpEventHandler += SelectPhoneOrEmail_MouseUpEvent;
|
phoneEmailForm.SelectedEmail.MouseUpEventHandler += SelectPhoneOrEmail_MouseUpEvent;
|
//登录事件
|
loginBtn.MouseUpEventHandler += LoginBtnEvent;
|
//账号登录
|
LoginByAccountPWDBtn.MouseUpEventHandler += LoginByPWD;
|
//注册事件
|
registerBtn.MouseUpEventHandler += Register;
|
//忘记密码
|
forgotPasswordBtn.MouseUpEventHandler += ForgetPWD_MouseUpEvent;
|
//wechat
|
wechatBtn.MouseUpEventHandler += LoginByWechat;
|
|
}
|
|
#endregion
|
|
|
#region ◆ 登录____________________________
|
|
/// <summary>
|
/// 登录事件
|
/// </summary>
|
/// <param name="sender">Sender.</param>
|
/// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
|
private async void LoginBtnEvent(object sender, MouseEventArgs mouseEventArgs)
|
{
|
CommonPage.Loading.Start();
|
try
|
{
|
if (CheckAccount(account) == false)
|
{
|
return;
|
}
|
var reqLoginByCode = new SendDataToServer.LoginValidCodeOBJ()
|
{
|
Account = account,
|
Code = code,
|
Language = CommonPage.ZigBeeLanguage,
|
AreaCode = int.Parse(CommonPage.PhoneZoneStr)
|
};
|
var requestRevetLoginCodeOBJ = await CommonFormResouce.LoginByCode(reqLoginByCode);
|
if (requestRevetLoginCodeOBJ == null)
|
{
|
CommonPage.Instance.FailureToServer();
|
return;
|
}
|
var stateCodeStr = requestRevetLoginCodeOBJ.StateCode.ToUpper();
|
if (stateCodeStr == "SUCCESS")
|
{
|
if (requestRevetLoginCodeOBJ.ResponseData == null)
|
{
|
return;
|
}
|
|
HomePage.Instance.ShowLoginLoadView();
|
new System.Threading.Thread(async () =>
|
{
|
var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.UserLoginRes>(requestRevetLoginCodeOBJ.ResponseData.ToString());
|
var revertData = responseDataObj;
|
Config.ReFresh();
|
//标记上一次是不是同一个账号登陆
|
UserCenter.UserCenterResourse.ResidenceOption.TheSameLoginAccount = Config.Instance.Guid == revertData.Guid;
|
Config.Instance.Password = string.Empty;
|
Config.Instance.Account = revertData.Account;
|
Config.Instance.Guid = revertData.Guid;
|
Config.Instance.MD5PWD = revertData.MD5PWD;
|
Config.Instance.LoginDateTime = DateTime.Now;
|
Config.Instance.LoginToken = revertData.Token;
|
//需要把登录后返回的md5密码 赋值生成Token 因为用户没有输入密码
|
Config.Instance.MD5PWD = revertData.MD5PWD;
|
Config.Instance.Save();
|
var resultRegID = await CommonPage.Instance.PushRegID();
|
var homes = await House.GetHomeLists();
|
|
//刷新个人中心的内存及线程
|
await UserCenter.UserCenterLogic.InitUserCenterMenmoryAndThread();
|
//启动ZigBee
|
ZigBee.Common.Application.Init();
|
|
UserCenter.HdlRoomLogic.Current.InitAllRoom();
|
Application.RunOnMainThread(() =>
|
{
|
this.RemoveFromParent();
|
CommonPage.Instance.RemoveViewByTag("Login");
|
UserPage.Instance.Fresh();
|
CommonPage.Loading.Hide();
|
});
|
})
|
{ IsBackground = true }.Start();
|
}
|
else if (stateCodeStr == "NOTVERIFY")
|
{
|
CommonPage.Loading.Hide();
|
//未激活
|
loginErrorBtn.TextID = R.MyInternationalizationString.NOTVERIFY;
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.NOTVERIFY);
|
}
|
else if (stateCodeStr == "NOTENABLE")
|
{
|
CommonPage.Loading.Hide();
|
//该用户属于调试账号,并未启用
|
loginErrorBtn.TextID = R.MyInternationalizationString.NOTENABLE;
|
}
|
else if (stateCodeStr == "PARAMETEROREMPTY")
|
{
|
CommonPage.Loading.Hide();
|
//提供的参数错误
|
loginErrorBtn.TextID = R.MyInternationalizationString.PARAMETEROREMPTY;
|
}
|
else if (stateCodeStr == "VALIDCODEANDPHONENOEQUAL")
|
{
|
CommonPage.Loading.Hide();
|
loginErrorBtn.TextID = R.MyInternationalizationString.VALIDCODEANDPHONENOEQUAL;
|
}
|
else if (stateCodeStr == "NORECORD")
|
{
|
CommonPage.Loading.Hide();
|
loginErrorBtn.TextID = R.MyInternationalizationString.NORECORD;
|
}
|
else if (stateCodeStr == "YOUDATANOISLOCALREGION")
|
{
|
CommonPage.Loading.Hide();
|
//不在本区域,需要重定向区域后再次请求登录
|
if (requestRevetLoginCodeOBJ.ResponseData == null)
|
{
|
return;
|
}
|
var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.UserLoginLocalRegionRes>(requestRevetLoginCodeOBJ.ResponseData.ToString());
|
CommonPage.RequestHttpsHost = responseDataObj.RegionServer;
|
//再次登录
|
//loginByCode();
|
}
|
else
|
{
|
CommonPage.Loading.Hide();
|
loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
|
}
|
}
|
catch
|
{
|
CommonPage.Loading.Hide();
|
CommonPage.Instance.FailureToServer();
|
}
|
finally
|
{
|
CommonPage.Loading.Hide();
|
}
|
|
}
|
|
/// <summary>
|
/// 通过密码登录
|
/// </summary>
|
/// <param name="sender">Sender.</param>
|
/// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
|
private void LoginByPWD(object sender, MouseEventArgs mouseEventArgs)
|
{
|
this.RemoveFromParent();
|
var login = new AccountLogin();
|
Shared.Common.CommonPage.Instance.AddChidren(login);
|
login.Show();
|
}
|
|
/// <summary>
|
/// phone/email 选择
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="mouseEventArgs"></param>
|
private void SelectPhoneOrEmail_MouseUpEvent(object sender, MouseEventArgs mouseEventArgs)
|
{
|
phoneEmailForm.SelectedPhone.IsSelected = phoneEmailForm.SelectedEmail.IsSelected = false;
|
phoneEmailForm.SelectedPhone.IsBold = phoneEmailForm.SelectedEmail.IsBold = false;
|
loginBtn.Enable = loginBtn.IsSelected = false;
|
(sender as Button).IsSelected = (sender as Button).IsBold = true;
|
if ((sender as Button).Tag.ToString() == "Phone")
|
{
|
AddPhoneOrEmailFL(accountCodeFL, "Phone");
|
}
|
else
|
{
|
AddPhoneOrEmailFL(accountCodeFL, "Email");
|
}
|
}
|
/// <summary>
|
/// AddPhoneOrEmailFL
|
/// </summary>
|
/// <param name="accountCodeFrameLayout"></param>
|
/// <param name="phoneOrEmail"></param>
|
private void AddPhoneOrEmailFL(FrameLayout accountCodeFrameLayout, string phoneOrEmail)
|
{
|
accountCodeFrameLayout.RemoveAll();
|
account = string.Empty;
|
loginErrorBtn.Text = string.Empty;
|
if (phoneOrEmail == "Phone")
|
{
|
phoneRow = new PhoneRowForm();
|
phoneRow.Init(accountCodeFrameLayout, this, this.account, 29, 29);
|
phoneRow.AccountET.TextChangeEventHandler += Account_TextChange;
|
}
|
else
|
{
|
emailRow = new EmailRowForm();
|
emailRow.Init(accountCodeFrameLayout, this.account, 29, 29);
|
emailRow.AccountET.TextChangeEventHandler += Account_TextChange;
|
}
|
|
codeRow = new VerificationCodeRowForm();
|
codeRow.Init(accountCodeFrameLayout, 29, 225);
|
codeRow.SendCodeBtn.MouseUpEventHandler += SendCode_MouseUpEventAsync;
|
codeRow.VerificationCodeET.TextChangeEventHandler += Code_TextChange;
|
}
|
|
/// <summary>
|
/// wechat登录
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="mouseEventArgs"></param>
|
private void LoginByWechat(object sender, MouseEventArgs mouseEventArgs)
|
{
|
#if Android
|
//var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP),
|
// Language.StringByID(R.MyInternationalizationString.LoginByWechat),
|
// Language.StringByID(R.MyInternationalizationString.Cancel),
|
// Language.StringByID(R.MyInternationalizationString.Confrim));
|
//alert.Show();
|
//alert.ResultEventHandler += (send, e) =>
|
//{
|
//if (e)
|
//{
|
com.hdl.home.Application.WXLogin();
|
com.hdl.home.WXEntryActivity.RespAction = (authStr) =>
|
{
|
if (authStr == null)
|
{
|
|
}
|
else
|
{
|
new System.Threading.Thread(async () =>
|
{
|
var re = await isBindAuthAsync(authStr);
|
if (re)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
//直接登录
|
HomePage.Instance.ShowLoginLoadView();
|
});
|
var resultRegID = await Shared.Common.CommonPage.Instance.PushRegID();
|
var homes = await House.GetHomeLists();
|
//启动ZigBee
|
ZigBee.Common.Application.Init();
|
//刷新个人中心的内存及线程
|
await UserCenter.UserCenterLogic.InitUserCenterMenmoryAndThread();
|
UserCenter.HdlRoomLogic.Current.InitAllRoom();
|
Application.RunOnMainThread(() =>
|
{
|
this.RemoveFromParent();
|
CommonPage.Instance.RemoveViewByTag("Login");
|
UserPage.Instance.Fresh();
|
});
|
}
|
else
|
{
|
var authRes = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.ResponseEntity.AuthUserRes>(authStr);
|
Application.RunOnMainThread(() =>
|
{
|
var registerPage = new AccountRegister();
|
Shared.Common.CommonPage.Instance.AddChidren(registerPage);
|
registerPage.OpenID = authRes.openid;
|
registerPage.Show();
|
});
|
}
|
})
|
{ IsBackground = true }.Start();
|
}
|
};
|
//}
|
//};
|
#endif
|
|
#if iOS
|
Home.IOS.AppDelegate.WXLogin();
|
Home.IOS.AppDelegate.RespAction = (authStr) =>
|
{
|
if (authStr == null)
|
{
|
|
}
|
else
|
{
|
new System.Threading.Thread(async () =>
|
{
|
|
var re = await isBindAuthAsync(authStr);
|
if (re)
|
{
|
//直接登录
|
//this.RemoveFromParent();
|
|
//UserPage.Instance.Fresh();
|
var resultRegID = await Shared.Common.CommonPage.Instance.PushRegID();
|
var homes = await House.GetHomeLists();
|
//启动ZigBee
|
ZigBee.Common.Application.Init();
|
//刷新个人中心的内存及线程
|
await UserCenter.UserCenterLogic.InitUserCenterMenmoryAndThread();
|
UserCenter.HdlRoomLogic.Current.InitAllRoom();
|
Application.RunOnMainThread(() =>
|
{
|
this.RemoveFromParent();
|
UserPage.Instance.Fresh();
|
});
|
}
|
else
|
{
|
var authRes = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.ResponseEntity.AuthUserRes>(authStr);
|
Application.RunOnMainThread(() =>
|
{
|
var registerPage = new AccountRegister();
|
Shared.Common.CommonPage.Instance.AddChidren(registerPage);
|
registerPage.OpenID = authRes.openid;
|
registerPage.Show();
|
});
|
}
|
})
|
{ IsBackground = true }.Start();
|
}
|
};
|
#endif
|
}
|
|
/// <summary>
|
/// qq登录
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="mouseEventArgs"></param>
|
private void LoginByQQ(object sender, MouseEventArgs mouseEventArgs)
|
{
|
|
}
|
|
/// <summary>
|
/// 是否已绑定
|
/// </summary>
|
/// <param name="authStr"></param>
|
/// <returns></returns>
|
private async System.Threading.Tasks.Task<bool> isBindAuthAsync(string authStr)
|
{
|
var authRes = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.ResponseEntity.AuthUserRes>(authStr);
|
var auth = new SendDataToServer.AuthUser()
|
{
|
AccessToken = authRes.access_token,
|
RefreshToken = authRes.refresh_token,
|
OpenID = authRes.openid
|
};
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(auth);
|
var revertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/InsertOrUpdateAuthUser", System.Text.Encoding.UTF8.GetBytes(requestJson));
|
if (revertObj == null)
|
{
|
return false;
|
}
|
var stateCodeStr = revertObj.StateCode.ToUpper();
|
if (stateCodeStr == "SUCCESS")
|
{
|
var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.UserLoginRes>(revertObj.ResponseData.ToString());
|
var revertData = responseDataObj;
|
//标记上一次是不是同一个账号登陆
|
UserCenter.UserCenterResourse.ResidenceOption.TheSameLoginAccount = Config.Instance.Guid == revertData.Guid;
|
Config.Instance.Account = revertData.Account;
|
Config.Instance.MD5PWD = revertData.MD5PWD;
|
Config.Instance.Guid = revertData.Guid;
|
Config.Instance.LoginDateTime = DateTime.Now;
|
Config.Instance.Save();
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
|
#endregion
|
|
#region ◆ 账号、验证码监听______________________
|
/// <summary>
|
/// 账号监听
|
/// </summary>
|
/// <param name="sender">Sender.</param>
|
/// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
|
private void Account_TextChange(object sender, string mouseEventArgs)
|
{
|
loginErrorBtn.Text = string.Empty;
|
if ((sender as EditText).Text.Trim().Length > 0)
|
{
|
IsRightAccount = true;
|
codeRow.SendCodeBtn.Enable = codeRow.SendCodeBtn.IsSelected = true;
|
account= (sender as EditText).Text.Trim();
|
}
|
else
|
{
|
IsRightAccount = false;
|
codeRow.SendCodeBtn.Enable = codeRow.SendCodeBtn.IsSelected = false;
|
}
|
}
|
|
/// <summary>
|
/// code监听事件
|
/// </summary>
|
/// <param name="sender">Sender.</param>
|
/// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
|
private void Code_TextChange(object sender, string mouseEventArgs)
|
{
|
loginErrorBtn.Text = "";
|
if ((sender as EditText).Text.Trim().Length > 0 && IsRightAccount)
|
{
|
loginBtn.Enable = loginBtn.IsSelected = true;
|
}
|
else
|
{
|
loginBtn.Enable = loginBtn.IsSelected = false;
|
}
|
code = (sender as EditText).Text.Trim();
|
}
|
|
#endregion
|
|
|
void TimeOut(object sender, System.Timers.ElapsedEventArgs e)
|
{
|
var span = DateTime.Now - dateBegin;
|
if (span.TotalSeconds <= 61)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
codeRow.SendCodeBtn.Text = Convert.ToInt16(60 - span.TotalSeconds) + "s" + Language.StringByID(R.MyInternationalizationString.SendVerificationCodeAgain);
|
codeRow.SendCodeBtn.Enable = false;
|
});
|
}
|
else
|
{
|
Application.RunOnMainThread(() =>
|
{
|
codeRow.SendCodeBtn.Enable = true;
|
codeRow.SendCodeBtn.TextID = R.MyInternationalizationString.SendVerificationCode;
|
t.Stop();
|
t.Close();
|
});
|
}
|
}
|
|
void TimeBegin()
|
{
|
t.Interval = 1000;
|
t.AutoReset = true;
|
t.Enabled = true;
|
t.Elapsed += TimeOut;
|
//启动计时器倒计时-60s
|
t.Start();
|
dateBegin = DateTime.Now;
|
}
|
|
#region ◆ 注册_____________________________
|
|
/// <summary>
|
/// 注册
|
/// </summary>
|
/// <param name="sender">Sender.</param>
|
/// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
|
private void Register(object sender, MouseEventArgs mouseEventArgs)
|
{
|
this.RemoveFromParent();
|
var registerPage = new AccountRegister();
|
CommonPage.Instance.AddChidren(registerPage);
|
registerPage.Show();
|
}
|
|
#endregion
|
|
#region ◆ 忘记密码________________________
|
/// <summary>
|
/// 忘记密码
|
/// </summary>
|
private void ForgetPWD_MouseUpEvent(object sender, MouseEventArgs mouseEventArgs)
|
{
|
this.RemoveFromParent();
|
var forgot = new AccountForgetPWD();
|
CommonPage.Instance.AddChidren(forgot);
|
forgot.Show();
|
}
|
|
#endregion
|
|
#region ◆ 发送验证码________________________
|
/// <summary>
|
/// 发送验证码
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="mouseEventArgs"></param>
|
private async void SendCode_MouseUpEventAsync(object sender, MouseEventArgs mouseEventArgs)
|
{
|
if (CheckAccount(account) == false)
|
{
|
return;
|
}
|
|
(sender as Button).Enable = (sender as Button).IsSelected = false;
|
CommonPage.Loading.Start();
|
try
|
{
|
int companyInt = 0;
|
if (CommonPage.PhoneZoneStr == "86" || phoneEmailForm.SelectedEmail.IsSelected)
|
{
|
companyInt = CommonPage.Company;
|
}
|
else
|
{
|
companyInt = CommonPage.CompanyForINTERNETION;
|
}
|
var reqDtoSignPhone = new SendDataToServer.LoginSendVerCodeObj()
|
{
|
Account = account,
|
Company = companyInt,
|
AreaCode = int.Parse(CommonPage.PhoneZoneStr),
|
Language = CommonPage.ZigBeeLanguage
|
};
|
var requestRevertObj = await CommonFormResouce.LoginSendVerCode(reqDtoSignPhone);
|
if (requestRevertObj == null)
|
{
|
CommonPage.Instance.FailureToServer();
|
return;
|
}
|
var stateCodeStr = requestRevertObj.StateCode.ToUpper();
|
if (stateCodeStr == "SUCCESS")
|
{
|
TimeBegin();
|
var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.SendVerificationCodeSuccess), Language.StringByID(R.MyInternationalizationString.Confrim));
|
alert.Show();
|
}
|
else if (stateCodeStr == "PARAMETEROREMPTY")
|
{
|
//提供的参数错误
|
loginErrorBtn.TextID = R.MyInternationalizationString.PARAMETEROREMPTY;
|
(sender as Button).Enable = (sender as Button).IsSelected = true;
|
}
|
else if (stateCodeStr == "ACCOUNTNOEXISTS")
|
{
|
//账号不存在
|
loginErrorBtn.TextID = R.MyInternationalizationString.ACCOUNTNOEXISTS;
|
IsRightAccount = false;
|
(sender as Button).Enable = (sender as Button).IsSelected = true;
|
}
|
else if (stateCodeStr == "SENDFAIL")
|
{
|
//验证码发送失败
|
loginErrorBtn.TextID = R.MyInternationalizationString.SENDFAIL;
|
(sender as Button).Enable = (sender as Button).IsSelected = true;
|
}
|
else
|
{
|
loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
|
(sender as Button).Enable = (sender as Button).IsSelected = true;
|
}
|
}
|
catch
|
{
|
loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
|
(sender as Button).Enable = (sender as Button).IsSelected = true;
|
}
|
finally
|
{
|
CommonPage.Loading.Hide();
|
}
|
}
|
|
/// <summary>
|
/// CheckAccount
|
/// </summary>
|
/// <param name="accountStr"></param>
|
/// <returns></returns>
|
private bool CheckAccount(string accountStr)
|
{
|
loginErrorBtn.Text = string.Empty;
|
if (phoneEmailForm.SelectedEmail.IsSelected)
|
{
|
if (AccountLogic.Instance.CheckEmail(accountStr) == false)
|
{
|
loginErrorBtn.TextID = R.MyInternationalizationString.TheEmailError;
|
return false;
|
}
|
}
|
else
|
{
|
if (AccountLogic.Instance.CheckPhoneWithZone(accountStr, CommonPage.PhoneZoneStr) == false)
|
{
|
loginErrorBtn.TextID = R.MyInternationalizationString.ThePhoneError;
|
return false;
|
}
|
}
|
return true;
|
}
|
|
#endregion
|
|
#region ◆ 验证验证码________________________
|
|
|
|
#endregion
|
}
|
}
|