using System;
|
|
using System.Collections.Generic;
|
|
using System.Web.UI.HtmlControls;
|
|
using Bwp.Web.Pages.FrameworkPages;
|
|
using TSingSoft.WebControls2;
|
|
using TSingSoft.WebPluginFramework;
|
|
using System.Web.UI;
|
|
using TSingSoft.WebPluginFramework.Exports;
|
|
using System.Web.UI.WebControls;
|
|
using Forks.EnterpriseServices.BusinessInterfaces;
|
|
using System.Web;
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Bwp.MainSystem.BO;
|
|
using Forks.EnterpriseServices.SqlDoms;
|
|
using System.Collections.Concurrent;
|
|
using System.Text;
|
|
using System.Web.Script.Serialization;
|
|
using BWP.B3DogAuth;
|
|
using BWP.B3Frameworks.BL;
|
|
using BWP.B3Frameworks.BO;
|
|
using BWP.B3Frameworks.BO.NamedValueTemplate;
|
|
|
|
[assembly: WebResource("Bwp.Web.Pages.TSSecurityInstall2.exe", Mimes.OctetStream)]
|
|
|
|
namespace Bwp.Web.Pages {
|
|
class DogAuthLoginPlugin : IWpfLoginPlugin {
|
|
|
|
class GetUserInfo : WebControl, ICallbackEventHandler {
|
|
public string GetCallbackResult() {
|
|
return result;
|
|
}
|
|
|
|
string result = string.Empty;
|
|
|
|
public void RaiseCallbackEvent(string eventArgument) {
|
|
long dogNo;
|
|
if (!long.TryParse(eventArgument, out dogNo)) {
|
|
IUserBL userBL = BIFactory.Create<IUserBL>();
|
|
if (!userBL.Exist(eventArgument))
|
|
result = "用户不存在";
|
|
return;
|
|
}
|
|
IDogLoginUserBL bl = BIFactory.Create<IDogLoginUserBL>();
|
|
DogLoginUser user = bl.Load(dogNo);
|
|
if (user == null) {
|
|
result = "未配置";
|
|
}
|
|
else {
|
|
result = user.User_Name;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
class SendMobileVerifyCode : WebControl, ICallbackEventHandler {
|
|
|
|
string mResult = string.Empty;
|
|
public string GetCallbackResult() {
|
|
return mResult;
|
|
}
|
|
|
|
public void RaiseCallbackEvent(string eventArgument) {
|
|
var serializer = new JavaScriptSerializer();
|
|
var info = serializer.Deserialize<Dictionary<string, string>>(eventArgument);
|
|
var username = info["username"];
|
|
var password = info["password"];
|
|
var config = new DogAuthConfig();
|
|
if (config.CloseMobileVerifyCode) {
|
|
bool loginByMobileVerifyCode = false;
|
|
foreach (var user in config.CanLoginWithMobileVerifyCode.Value) {
|
|
if (user == username) {
|
|
loginByMobileVerifyCode = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!loginByMobileVerifyCode) {
|
|
mResult = "手机验证码登陆功能已关闭";
|
|
return;
|
|
}
|
|
}
|
|
var wpfuser =new JoinAlias(typeof(WpfUser));
|
|
var pro = new JoinAlias(typeof(UserBasicProfile));
|
|
var query = new DQueryDom(pro);
|
|
query.From.AddJoin(JoinType.Left,new DQDmoSource(wpfuser),DQCondition.EQ(wpfuser,"ID",pro,"ID") );
|
|
query.Where.Conditions.Add(DQCondition.EQ(wpfuser,"Name", username));
|
|
query.Columns.Add(DQSelectColumn.Field("Mobile",pro));
|
|
query.Range = SelectRange.Top(1);
|
|
var mobile = query.EExecuteScalar<string>();
|
|
if (string.IsNullOrEmpty(mobile)) {
|
|
mResult = string.Format("用户{0}不存在或未设置手机号", username);
|
|
return;
|
|
}
|
|
|
|
var userBL = BIFactory.Create<IUserBL>();
|
|
try {
|
|
userBL.ValidUser(username, password);
|
|
}
|
|
catch {
|
|
mResult = "用户名或密码错误";
|
|
return;
|
|
}
|
|
|
|
var verifyCode = MobileAuthCenter.GenVerifyCode(username);
|
|
var externalMessage = new ExternalMessage();
|
|
externalMessage.Content = string.Format("您的登录验证码是{0},5分钟后该验证码将失效", verifyCode);
|
|
externalMessage.Receiver = mobile;
|
|
externalMessage.ReceiverName = username;
|
|
externalMessage.Type = ExternalMessageType.短信;
|
|
try {
|
|
var messageBL = BIFactory.Create<IExternalMessageBL>();
|
|
using (var scope = new WpfInternalUserScope()) {
|
|
#if !DEBUG
|
|
messageBL.Insert(externalMessage);
|
|
#endif
|
|
}
|
|
mResult = "验证码已发送";
|
|
#if DEBUG
|
|
mResult += verifyCode;
|
|
#endif
|
|
}
|
|
catch (Exception ex) {
|
|
mResult = string.Format("短信发送失败:" + ex.Message);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
static HtmlTableRow CreateClientDogDownloadRow() {
|
|
HtmlTableRow tr = new HtmlTableRow();
|
|
var cell = tr.EAdd(new HtmlTableCell {
|
|
ColSpan = 2,
|
|
Align = "center",
|
|
InnerHtml = "<a id=\"lnkdownload\" style=\"visibility:hidden\" href=\"" +
|
|
TSWebResource.GetUrl("Bwp.Web.Pages.TSSecurityInstall2.exe", typeof(DogAuthLoginPlugin).Assembly) +
|
|
"\">下载黑贝客户端</a>"
|
|
});
|
|
|
|
return tr;
|
|
}
|
|
|
|
GetUserInfo getUserInfo;
|
|
|
|
SendMobileVerifyCode sendMobileVerifyCode;
|
|
|
|
LinkButton switchDogButton;
|
|
public void CreateExtraControls(WpfLogin self, HtmlTable tbl) {
|
|
if (BrowserIsIE) {
|
|
CreateExtraControl_IE(self, tbl);
|
|
}
|
|
else {
|
|
CreateExtraControl_NotIE(self, tbl);
|
|
}
|
|
}
|
|
|
|
TextBox verifyCodeInput;
|
|
private void CreateExtraControl_NotIE(WpfLogin self, HtmlTable tbl) {
|
|
sendMobileVerifyCode = new SendMobileVerifyCode();
|
|
tbl.Rows[0].Cells[0].Controls.Add(sendMobileVerifyCode);
|
|
|
|
var row = new HtmlTableRow();
|
|
tbl.Rows.Insert(2, row);
|
|
var cell1 = new HtmlTableCell();
|
|
cell1.ColSpan = 2;
|
|
cell1.Attributes["class"] = "verifyCodeLabel";
|
|
row.Cells.Add(cell1);
|
|
verifyCodeInput = new TextBox() { Width = Unit.Pixel(80) };
|
|
verifyCodeInput.CssClass = "verifyCodeInput";
|
|
verifyCodeInput.Attributes["placeholder"] = "输入验证码";
|
|
cell1.Controls.Add(verifyCodeInput);
|
|
|
|
var row2 = new HtmlTableRow();
|
|
var verifyCodeCell = new HtmlTableCell();
|
|
verifyCodeCell.Style.Add(HtmlTextWriterStyle.Color, "red");
|
|
verifyCodeCell.Controls.Add(new LiteralControl("<span id='VerifyCodeInfo'></span>"));
|
|
verifyCodeCell.ColSpan = 2;
|
|
row2.Cells.Add(verifyCodeCell);
|
|
tbl.Rows.Insert(3, row2);
|
|
|
|
}
|
|
|
|
private void CreateExtraControl_IE(WpfLogin self, HtmlTable tbl) {
|
|
tbl.EAdd(CreateClientDogDownloadRow());
|
|
|
|
getUserInfo = new GetUserInfo();
|
|
HtmlTableRow tr = new HtmlTableRow();
|
|
HtmlTableCell td = new HtmlTableCell();
|
|
td.ColSpan = 2;
|
|
tr.Cells.Add(td);
|
|
tbl.Rows.Add(tr);
|
|
td.Controls.Add(getUserInfo);
|
|
|
|
switchDogButton = new LinkButton();
|
|
if (DogAuthPlugin.AllowNoDog) {
|
|
td.Controls.Add(switchDogButton);
|
|
switchDogButton.Click += (sender, e) => {
|
|
if (!mAllowNoDog) {
|
|
self.Page.Response.Cookies.Add(new HttpCookie("NoDog", "NoDog") { Expires = DateTime.MaxValue });
|
|
AspUtil.Redirect(self.Page.Request.RawUrl);
|
|
self.Page.Response.Redirect(self.Page.Request.RawUrl);
|
|
}
|
|
else {
|
|
self.Page.Response.Cookies["NoDog"].Expires = DateTime.Now.AddYears(-1);
|
|
AspUtil.Redirect(self.Page.Request.RawUrl);
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
public void InitPamContext(WpfLogin self, IDictionary<string, object> pamContext) {
|
|
//这里不能根据verifyCodeInput是否为空来判断,当verifyCodeInput被用到后就不再为空
|
|
//可能和asp.net页面的内部机制有关系
|
|
if (!BrowserIsIE && verifyCodeInput != null) {
|
|
pamContext.Add("VerifyCode", verifyCodeInput.Text);
|
|
}
|
|
}
|
|
|
|
bool BrowserIsIE {
|
|
get {
|
|
return BrowserContext.Current.Browser == "IE";
|
|
}
|
|
}
|
|
|
|
bool mAllowNoDog = false;
|
|
public void OnLoad(WpfLogin self) {
|
|
if (BrowserIsIE) {
|
|
mAllowNoDog = DogAuthPlugin.AllowNoDog && self.Page.Request.Cookies["NoDog"] != null;
|
|
if (!mAllowNoDog) {
|
|
switchDogButton.Text = "切换到不使用黑贝登录";
|
|
self.UserNameTextBox.ReadOnly = true;
|
|
RegisterClientDog(self);
|
|
}
|
|
else {
|
|
switchDogButton.Text = "切换到使用黑贝登录";
|
|
}
|
|
}
|
|
else {
|
|
RegisterMobileLogin(self);
|
|
}
|
|
}
|
|
|
|
private void RegisterMobileLogin(WpfLogin self) {
|
|
|
|
var script = @"
|
|
function GetVerifyCode(){
|
|
var username = $('input[type=text]:first').val();
|
|
var password = $('input[type=password]:first').val();
|
|
var callbackdata = JSON.stringify({username:username,password:password});
|
|
{Callback}
|
|
}
|
|
|
|
function ReceiveServerData(value){
|
|
$('#VerifyCodeInfo').text(value);
|
|
}
|
|
$(""<a id='getverifycode' class='getverifycode' href=\""javascript:GetVerifyCode();\"">获取验证码</a>"").insertAfter(""input[type=password]:first"")
|
|
";
|
|
script = script.Replace("{Callback}", self.Page.ClientScript.GetCallbackEventReference(sendMobileVerifyCode, "callbackdata", "ReceiveServerData", null));
|
|
|
|
self.Page.ClientScript.RegisterStartupScript(typeof(WpfLogin), "ClientDog", script, true);
|
|
}
|
|
|
|
void RegisterClientDog(WpfLogin self) {
|
|
self.UserNameTextBox.Attributes["onchange"] = "SetDogInfo();";
|
|
|
|
string script =
|
|
"var dogDate='" + new DateTime(2000, 1, 1).ToString("yyyy-MM-dd") + "';" +
|
|
"var uid=document.all." + self.UserNameTextBox.ClientID + ";" +
|
|
"var btn=document.all." + self.LoginButton.ClientID + ";" +
|
|
@"
|
|
btn.disabled = true;
|
|
var checkObj;
|
|
|
|
var dog = -1;
|
|
function SetDogInfo()
|
|
{
|
|
{Callback}
|
|
}
|
|
function ReceiveServerData(value)
|
|
{
|
|
var span = uid.nextSibling;
|
|
if(span == null || span.tagName != 'SPAN')
|
|
{
|
|
span = document.createElement('span');
|
|
$(span).css('color',$(uid).css('color'));
|
|
$(span).css('fontSize',$(uid).css('fontSize'));
|
|
$(span).css('fontFamily',$(uid).css('fontFamily'));
|
|
uid.insertAdjacentElement('afterEnd',span);
|
|
}
|
|
span.innerText = value;
|
|
span.innerText += '|' + uid.value;;
|
|
}
|
|
function CheckSign() {
|
|
if(checkObj.DogNo == dog) {
|
|
dog = checkObj.DogNo;
|
|
window.setTimeout('CheckSign()',1000);
|
|
return;
|
|
}
|
|
|
|
var msg = checkObj.CheckSign(dogDate);
|
|
if(msg != '') {
|
|
var result = confirm(msg+',继续吗?');
|
|
if(!result){return;}
|
|
uid.value = '';
|
|
btn.disabled = true;
|
|
window.setTimeout('CheckSign()',1000);
|
|
} else {
|
|
dog = checkObj.DogNo;
|
|
uid.value=dog;
|
|
SetDogInfo();
|
|
uid.style.display='none';
|
|
btn.disabled = false;
|
|
window.setTimeout('CheckSign()',1000);
|
|
}
|
|
}
|
|
var driverInstall = false;
|
|
try {
|
|
checkObj = new ActiveXObject('TSSecurity.UserSign');
|
|
driverInstall = true;
|
|
} catch(e) {
|
|
lnkdownload.style.visibility = 'visible';
|
|
alert('没有安装客户端狗的驱动,不能使用本系统.');
|
|
}
|
|
|
|
if(driverInstall == true)
|
|
CheckSign();
|
|
";
|
|
script = script.Replace("{Callback}", self.Page.ClientScript.GetCallbackEventReference(getUserInfo, "uid.value", "ReceiveServerData", null));
|
|
self.Page.ClientScript.RegisterStartupScript(typeof(WpfLogin), "ClientDog", script, true);
|
|
// RegisterAjaxScript(self.Page);
|
|
}
|
|
|
|
// public void RegisterAjaxScript(Page page) {
|
|
// const string script = @"
|
|
//<script language=javascript>
|
|
//function Ajax()
|
|
//{
|
|
//}
|
|
//
|
|
//Ajax.WaitResult = function(xmlHttp,doResultF)
|
|
//{
|
|
// xmlHttp.onreadystatechange = function()
|
|
// {
|
|
// if(xmlHttp.readyState != 4) return;
|
|
// if(xmlHttp.status != 200)
|
|
// {
|
|
// alert ('所请求的页面出现问题' + xmlHttp.statusText);
|
|
// xmlHttp = null;
|
|
// return;
|
|
// }
|
|
// var rootNode = xmlHttp.responseXML;
|
|
// xmlHttp = null;
|
|
// if(rootNode == null)
|
|
// {
|
|
// alert('未能从页面返回结果中得到xml数据');
|
|
// return;
|
|
// }
|
|
//
|
|
// var successNode = hal.selectSingleNode(rootNode,'//Success');
|
|
// if(successNode.firstChild.data != '1')
|
|
// {
|
|
// var descriptionNode = hal.selectSingleNode(rootNode,'//Description');
|
|
// alert(descriptionNode.firstChild.data);
|
|
// return;
|
|
// }
|
|
// var resultNode = hal.selectSingleNode(rootNode,'//Result');
|
|
// var result;
|
|
// if(resultNode.firstChild.nodeType == 8){
|
|
// result = resultNode.firstChild.data;
|
|
// if(hal.selectSingleNode(rootNode,'//ResultIsJson') != null){
|
|
// result = eval('(' + result + ')');
|
|
// }
|
|
// }
|
|
// else if(resultNode.firstChild.nodeName == 'Row')
|
|
// {
|
|
// result = new Object();
|
|
// for(var i=0;i<resultNode.firstChild.attributes.length;i++)
|
|
// eval('result.' +resultNode.firstChild.attributes.item(i).name + '=hal.getNodeText(resultNode.firstChild.attributes.item(i))');
|
|
// }
|
|
// doResultF(result);
|
|
// }
|
|
//}
|
|
//
|
|
//Ajax.Get = function(url,doResultF)
|
|
//{
|
|
// var xmlHttp = hal.createXmlHttp();
|
|
// xmlHttp.open('GET', url , false);
|
|
// Ajax.WaitResult(xmlHttp,doResultF);
|
|
// xmlHttp.send(null);
|
|
//}
|
|
//
|
|
//Ajax.Post = function(url,postData,doResultF)
|
|
//{
|
|
// var xmlHttp = hal.createXmlHttp();
|
|
// xmlHttp.open('POST',url, false);
|
|
// xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
// Ajax.WaitResult(xmlHttp,doResultF);
|
|
// xmlHttp.send(postData);
|
|
//}</script>";
|
|
// page.ClientScript.RegisterClientScriptBlock(page.GetType(), "Ajax", script);
|
|
// }
|
|
}
|
|
}
|