using Yw;
|
using Yw.Auth;
|
using Yw.Dto;
|
using Yw.WinFrmUI;
|
|
namespace HStation.WinFrmUI
|
{
|
public partial class PersonalCenterDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public PersonalCenterDlg()
|
{
|
InitializeComponent();
|
this.Load += PersonalCenterDlg_Load;
|
this.wechatBindingCtrl1.LoginStartEvent += WechatBindingCtrl1_LoginStartEvent;
|
}
|
|
private const string _smsTemplate = "hzkw_sms_template";//手机号登录模板
|
private const string _vxTemplate = "hzkw_wx_template";//微信登录模板
|
private const string _software = "HStation_XHS_DESKTOP";//软件编码
|
|
//登录回调
|
private void WechatBindingCtrl1_LoginStartEvent(string code)
|
{
|
WechatBinding(code);
|
}
|
|
//初始化
|
private void PersonalCenterDlg_Load(object? sender, EventArgs e)
|
{
|
this.txtEditUserName.Text = GlobalParas._GlobalParas.LoginName;
|
this.txtEditAdminType.Text = GlobalParas._GlobalParas.AdminType;
|
this.txtAccountName.Text = GlobalParas._GlobalParas.AccountName;
|
this.textAccountType.Text = GlobalParas._GlobalParas.LoginType;
|
this.wechatBindingCtrl1.Initial();
|
}
|
|
//修改密码
|
private void BtnEditPwd_Click(object sender, EventArgs e)
|
{
|
var dlg = new UpdatePwdDlg();
|
dlg.SetBindingData(GlobalParas._GlobalParas.LoginID);
|
dlg.ShowDialog();
|
}
|
|
//手机号验证
|
private bool IsValidMobileNumber(string mobile)
|
{
|
var regex = new System.Text.RegularExpressions.Regex(@"^1\d{10}$");
|
return regex.IsMatch(mobile);
|
}
|
|
//微信绑定
|
private async void WechatBinding(string code)
|
{
|
var loginType = await BLLFactory<Yw.BLL.UserLoginType>.Instance.GetByIdentifier(LoginType.Wechat);
|
if (loginType != null)
|
{
|
var tokenInfo = await BLLFactory<Yw.BLL.ToolWechat>.Instance.GetTokenInfo(code, _vxTemplate);
|
if (tokenInfo == null)
|
return;
|
var isExist = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.IsExist(new IsExistUserLoginAccountInput
|
{
|
CorpID = GlobalParas._GlobalParas.CorpID,
|
LoginTypeID = loginType.ID,
|
Identifier = _vxTemplate,
|
Credential = tokenInfo.openid
|
});
|
if (isExist)
|
{
|
TipFormHelper.ShowError("账户已存在!");
|
return;
|
}
|
var vmo = new Yw.Vmo.AddUserLoginAccountVmo
|
{
|
CorpID = GlobalParas._GlobalParas.CorpID,
|
UserID = GlobalParas._GlobalParas.UserID,
|
LoginTypeID = loginType.ID,
|
Identifier = _vxTemplate,
|
Credential = tokenInfo.openid,
|
IfVerified = true
|
};
|
var bol = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.Insert(vmo);
|
if (bol > 0)
|
{
|
TipFormHelper.ShowSucceed("绑定成功!");
|
}
|
else
|
{
|
TipFormHelper.ShowError("绑定失败!");
|
}
|
};
|
}
|
|
//手机绑定
|
private async void PhoneBinding()
|
{
|
if (!IsValidMobileNumber(this.txtMobileNumber.Text.Trim()))
|
{
|
TipFormHelper.ShowError("手机号有误!");
|
return;
|
}
|
var loginType = await BLLFactory<Yw.BLL.UserLoginType>.Instance.GetByIdentifier(LoginType.SMS);
|
if (loginType != null)
|
{
|
var isExist = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.IsExist(new IsExistUserLoginAccountInput
|
{
|
CorpID = GlobalParas._GlobalParas.CorpID,
|
LoginTypeID = loginType.ID,
|
Identifier = _smsTemplate,
|
Credential = this.txtMobileNumber.Text.Trim()
|
});
|
if (isExist)
|
{
|
TipFormHelper.ShowError("账户已存在!");
|
return;
|
}
|
var vmo = new Yw.Vmo.AddUserLoginAccountVmo
|
{
|
CorpID = GlobalParas._GlobalParas.CorpID,
|
UserID = GlobalParas._GlobalParas.UserID,
|
LoginTypeID = loginType.ID,
|
Identifier = _smsTemplate,
|
Credential = this.txtMobileNumber.Text.Trim(),
|
IfVerified = true
|
};
|
var bol = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.Insert(vmo);
|
if (bol > 0)
|
{
|
TipFormHelper.ShowSucceed("绑定成功!");
|
}
|
else
|
{
|
TipFormHelper.ShowError("绑定失败!");
|
}
|
}
|
}
|
|
private void btnPhoneBinding_Click(object sender, EventArgs e)
|
{
|
PhoneBinding();
|
}
|
|
//微信二维码刷新
|
private void btnRefresh_Click(object sender, EventArgs e)
|
{
|
this.wechatBindingCtrl1.Initial();
|
}
|
}
|
}
|