コード例 #1
0
ファイル: PortalUserHelper.cs プロジェクト: wkxuan/code
        public override void Login(string username, string password)
        {
            List <SYSUSEREntity> users = _db.SelectList(new SYSUSEREntity()
            {
                USERCODE = username
            });

            if (users.IsEmpty())
            {
                throw new Exception("找不到用户");
            }
            else if (users.Where(a => a.USER_FLAG.ToInt() == (int)用户标记.正常).IsEmpty())
            {
                throw new Exception($"用户已{users.First().USER_FLAG.ToEnum<用户标记>() }");
            }
            else
            {
                SYSUSEREntity user = users.First();
                if (Verify(user, password))
                {
                    Employee e = GetUser(user.USERID);
                    ApplicationContextBase.GetContext().SetData(LoginKey + e.Id, users);
                    ApplicationContextBase.GetContext().principal = new GenericPrincipal(new GenericIdentity(e.Id), null);
                    FormsAuthentication.SetAuthCookie(e.Id, true);
                }
                else
                {
                    throw new Exception("密码错误");
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// 外键约束
 /// </summary>
 /// <typeparam name="TTarget">目标表</typeparam>
 /// <param name="p">本表字段</param>
 /// <param name="t">目标表字段</param>
 /// <param name="ErrorModel">错误信息</param>
 public void IsForeignKey <TTarget>(Expression <Func <TEntity, string> > p, Expression <Func <TTarget, string> > t, string ErrorModel = "[{0}]表中字段[{1}]的值[{2}]在[{3}]表中的字段[{4}]已存在") where TTarget : TableEntityBase, new()
 {
     if (p.Body is MemberExpression && t.Body is MemberExpression)
     {
         MemberExpression tme  = t.Body as MemberExpression;
         MemberExpression me   = p.Body as MemberExpression;
         PropertyInfo     prop = me.Member as PropertyInfo;
         string           str  = prop.GetValue(_entity)?.ToString().Trim();
         TTarget          tar  = (TTarget)Activator.CreateInstance(
             typeof(TTarget),
             BindingFlags.Instance | BindingFlags.Public,
             null,
             new object[] { },
             null);
         tar.SetPropertyValue(tme.Member.Name, prop.GetValue(_entity));
         if (!_dbHelper.SelectList(tar).IsEmpty())
         {
             SetError(string.Format(ErrorModel, _entity.GetComments(), _entity.GetFieldName(p), str, tar.GetTableName(), tar.GetFieldName(t)));
         }
     }
     else
     {
         throw new Exception("此校验只对字段属性生效");
     }
 }