using System; using System.Collections.Generic; using Bwp.MainSystem.Auth; using Forks.EnterpriseServices.BusinessInterfaces; using Forks.EnterpriseServices.DomainObjects2; using Forks.EnterpriseServices.DomainObjects2.DQuery; using Forks.EnterpriseServices.SqlDoms; using TSingSoft.WebPluginFramework; namespace BWP.B3DogAuth { public class DogAuthPlugin : IAuthPlugin { public void Auth(IDictionary context) { if (UserAndPasswordOnly(context)) { return; } if (context.ContainsKey("SkipPasswordAuth")) { return; } var name = (string)context["Name"]; if (context.ContainsKey("VerifyCode")) { var verifyCode = (string)context["VerifyCode"]; if (!MobileAuthCenter.Auth(name, verifyCode)) { throw new Exception("验证码不正确"); } } else { int dogNo; if (int.TryParse(name, out dogNo)) { context["Name"] = DogNoToUserName(dogNo); context.Add("DogAuthNo", name); } else { if (AllowNoDog) { CheckNoDogUserName(name); } else { throw new WpfException("Internal error: 43bb83d0-3388-4cde-9459-4dc9a44918e4 " + name); } } } } static bool UserAndPasswordOnly(IDictionary context) { return context.EGetDefault("UserAndPasswordOnly"); } static string DogNoToUserName(int dogNo) { IDogLoginUserBL bl = BIFactory.Create(); var dogLoginUser = bl.Load(dogNo); if (dogLoginUser == null) { throw new WpfException(string.Format("您当前的黑贝序号是{0},没有在黑贝认证中定义", dogNo)); } return dogLoginUser.User_Name; } static void CheckNoDogUserName(string userName) { var query = new DQueryDom(new JoinAlias(typeof(DogLoginUser))); query.Where.Conditions.Add(DQCondition.EQ("User_Name", userName)); query.Range = SelectRange.Top(1); query.Columns.Add(DQSelectColumn.Field("ID")); using (IDmoSession session = Dmo.NewSession()) { if (session.ExecuteScalar(query) != null) { throw new Exception(string.Format("用户名{0}必须使用黑贝登录", userName)); } } } public static bool AllowNoDog { get { return Wpf.Parameters.AsBool("B3DogAuth.AllowUnConfigedDog"); } } } }