/// <summary>
        /// 用户管理员权限验证
        /// </summary>
        /// <param name="usercd">用户账号</param>
        /// <param name="pwd">用户密码</param>
        /// <returns>返回token</returns>
        public static bool AdminCheck(string usercd, string token)
        {
            bool isAdmin = false;

            //无效参数
            if (usercd == String.Empty || token == String.Empty)
            {
                return(isAdmin);
            }
            PatrolUserInfo user = new PatrolUserInfo();

            user.UserCD = usercd;

            PatrolUserInfo entity = Select(user);

            //用户不存在
            if (entity == null)
            {
                return(isAdmin);
            }
            ////旧密码输入错误
            //if (entity.Token != token)
            //{
            //    return isAdmin;
            //}
            //旧密码输入错误
            if (entity.IsAdmin == "1")
            {
                return(true);
            }
            return(isAdmin);
        }
Exemple #2
0
        /// <summary>
        /// 新增对象
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>true=成功;false=失败</returns>
        public bool Insert(PatrolUserInfo entity)
        {
            SQLEntities context = new SQLEntities();
            bool        success = false;

            using (TransactionScope trans = new TransactionScope())
            {
                try
                {
                    context.PatrolUserInfo.AddObject(entity);
                    trans.Complete();
                    success = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            try
            {
                if (success)
                {
                    //提交保存
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            context.Dispose();

            return(success);
        }
        /// <summary>
        /// 重置用户密码
        /// </summary>
        /// <param name="usercd">账号</param>
        /// <returns></returns>
        public static bool ResetPassword(string usercd, string updator)
        {
            //无效参数
            if (usercd == String.Empty || updator == String.Empty)
            {
                return(false);
            }
            PatrolUserInfo user = new PatrolUserInfo();

            user.UserCD = usercd;

            PatrolUserInfo olduser = Select(user);

            //用户不存在
            if (olduser == null)
            {
                return(false);
            }
            Hashtable updatekeys = new Hashtable();

            updatekeys.Add("UserPassword", Common.DefaultPassword + usercd);
            updatekeys.Add("Token", CreateToken());
            updatekeys.Add("TokenInvalid", SetTokenInvalid(Common.TokenLife));
            updatekeys.Add("UpdatedAt", DateTime.Now);
            updatekeys.Add("Updator", updator);

            return(Update(olduser, updatekeys));
        }
Exemple #4
0
        /// <summary>
        /// 测试用户数据信息
        /// </summary>
        public static void TestPatrolUserInfo()
        {
            PatrolUserInfoHelper ph = new PatrolUserInfoHelper();

            PatrolUserInfo entity = new PatrolUserInfo();

            entity.UserCD       = "123456";
            entity.UserPassword = "******";
            entity.Token        = "xxxxx";
            entity.IsAdmin      = "1";
            entity.IsAvailable  = "1";
            entity.SearchRange  = "0";
            entity.CreatedAt    = DateTime.Now;
            entity.Creator      = "admin";
            entity.UpdatedAt    = DateTime.Now;
            entity.Updator      = "admin";

            ph.Insert(entity);
            List <PatrolUserInfo> list = ph.SelectAll();

            foreach (PatrolUserInfo item in list)
            {
                Console.WriteLine(item.UserCD);
            }
        }
 /// <summary>
 /// 根据用户名称查询唯一用户
 /// </summary>
 /// <param name="searchInfo">带有UserCD值的查询对象</param>
 /// <returns>指定UserCD值的个人信息</returns>
 public static PatrolUserInfo Select(PatrolUserInfo searchInfo)
 {
     if (searchInfo == null || searchInfo.UserCD == String.Empty)
     {
         return(null);
     }
     return(controller.Select(searchInfo));
 }
 /// <summary>
 /// 删除记录
 /// </summary>
 /// <param name="entity">删除对象 主键必须设置</param>
 /// <returns></returns>
 public static bool Delete(PatrolUserInfo entity)
 {
     if (entity != null)
     {
         return(controller.Delete(entity));
     }
     return(false);
 }
 /// <summary>
 /// 更新记录
 /// </summary>
 /// <param name="entity">要更新对象</param>
 /// <param name="updateKeys">更新列表</param>
 /// <returns>true=成功,false=失败</returns>
 public static bool Update(PatrolUserInfo entity, Hashtable updateKeys)
 {
     if (entity != null && updateKeys != null && updateKeys.Count > 0)
     {
         return(controller.Update(entity, updateKeys));
     }
     return(false);
 }
 /// <summary>
 /// 新增记录
 /// </summary>
 /// <param name="entity">新增对象</param>
 /// <returns>true=成功,false=失败</returns>
 public static bool Insert(PatrolUserInfo entity)
 {
     if (entity != null)
     {
         return(controller.Insert(entity));
     }
     return(false);
 }
Exemple #9
0
        /// <summary>
        /// 记录需要更新的字段
        /// </summary>
        /// <param name="update"></param>
        private static void SetUpdateValue(PatrolUserInfo current, Hashtable updateKeys)
        {
            foreach (DictionaryEntry item in updateKeys)
            {
                switch (item.Key.ToString().ToLower())
                {
                case "usercd":
                    current.UserCD = item.Value.ToString();
                    break;

                case "userpassword":
                    current.UserPassword = item.Value.ToString();
                    break;

                case "token":
                    current.Token = item.Value.ToString();
                    break;

                case "tokeninvalid":
                    current.TokenInvalid = Convert.ToDateTime(item.Value);
                    break;

                case "isadmin":
                    current.IsAdmin = item.Value.ToString();
                    break;

                case "searchrange":
                    current.SearchRange = item.Value.ToString();
                    break;

                case "isavailable":
                    current.IsAvailable = item.Value.ToString();
                    break;

                case "creator":
                    current.Creator = item.Value.ToString();
                    break;

                case "createdat":
                    current.CreatedAt = Convert.ToDateTime(item.Value);
                    break;

                case "updator":
                    current.Updator = item.Value.ToString();
                    break;

                case "updatedat":
                    current.UpdatedAt = Convert.ToDateTime(item.Value);
                    break;

                default:
                    break;
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// 根据查询条件查询单条记录
        /// </summary>
        /// <param name="searchInfo">查询条件,主键查询</param>
        /// <returns></returns>
        public PatrolUserInfo Select(PatrolUserInfo searchInfo)
        {
            PatrolUserInfo instance = null;

            try
            {
                SQLEntities context = new SQLEntities();

                instance = context.PatrolUserInfo.Where("it.UserCD=@UserCD", new ObjectParameter("UserCD", searchInfo.UserCD)).First();

                context.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(instance);
        }
Exemple #11
0
        /// <summary>
        /// 复制对象
        /// </summary>
        /// <param name="source">源对象</param>
        /// <returns></returns>
        public PatrolUserInfo Copy(PatrolUserInfo source)
        {
            PatrolUserInfo target = new PatrolUserInfo();

            target.UserCD       = source.UserCD;
            target.UserPassword = source.UserPassword;
            target.Token        = source.Token;
            target.TokenInvalid = source.TokenInvalid;
            target.IsAdmin      = source.IsAdmin;
            target.SearchRange  = source.SearchRange;
            target.IsAvailable  = source.IsAvailable;
            target.Creator      = source.Creator;
            target.CreatedAt    = source.CreatedAt;
            target.Updator      = source.Updator;
            target.UpdatedAt    = source.UpdatedAt;


            return(target);
        }
        /// <summary>
        /// 检查token是否有效
        /// </summary>
        /// <param name="entity">用户对象</param>
        /// <param name="token">token</param>
        /// <returns>true=有效,false=失效</returns>
        public static bool CheckToken(PatrolUserInfo entity, string token)
        {
            bool success = false;

            if (entity != null)
            {
                PatrolUserInfo user = Select(entity);
                if (user != null)
                {
                    if (user.Token.Trim() == token.Trim() && user.TokenInvalid != null && DateTime.Now.CompareTo(user.TokenInvalid) >= 0)
                    {
                        //token 相等 并且当前访问日期在有效期之内
                        success = true;
                    }
                }
            }

            return(success);
        }
        /// <summary>
        /// 用户登录验证
        /// </summary>
        /// <param name="usercd">用户账号</param>
        /// <param name="pwd">用户密码</param>
        /// <returns>返回token</returns>
        public static string LoginCheck(string usercd, string pwd)
        {
            string token = String.Empty;

            //无效参数
            if (usercd == String.Empty || pwd == String.Empty)
            {
                return(token);
            }
            PatrolUserInfo user = new PatrolUserInfo();

            user.UserCD = usercd;

            PatrolUserInfo entity = Select(user);

            //用户不存在
            if (entity == null)
            {
                return(token);
            }
            //旧密码输入错误
            if (entity.UserPassword != pwd)
            {
                return(token);
            }
            //查询到有效用户,更新token并返回token到客户端
            token = CreateToken();
            Hashtable updatekeys = new Hashtable();

            updatekeys.Add("Token", token);
            updatekeys.Add("TokenInvalid", SetTokenInvalid(Common.TokenLife));
            updatekeys.Add("UpdatedAt", DateTime.Now);

            bool success = controller.Update(entity, updatekeys);

            if (!success)
            {
                //更新token失败
                token = String.Empty;
            }
            return(token);
        }
Exemple #14
0
        public static bool InsertUser(PatrolUserInfo newuser)
        {
            SQLEntities context = new SQLEntities();
            bool        success = false;

            if (newuser != null)
            {
                using (TransactionScope trans = new TransactionScope())
                {
                    try
                    {
                        context.PatrolUserInfo.AddObject(newuser);
                        Console.WriteLine("新增对象完毕");
                        trans.Complete();
                        success = true;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("新增对象异常" + ex.Message);
                    }
                }
            }
            try
            {
                if (success)
                {
                    //提交保存
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            context.Dispose();

            return(success);
        }
Exemple #15
0
        /// <summary>
        /// 根据主键删除实例
        /// </summary>
        /// <param name="oldEntity">设置了主键Id的对象</param>
        /// <returns></returns>
        public bool Delete(PatrolUserInfo entity)
        {
            SQLEntities context = new SQLEntities();
            bool        success = false;

            using (TransactionScope trans = new TransactionScope())
            {
                try
                {
                    PatrolUserInfo instance = context.PatrolUserInfo.Where("it.UserCD=@UserCD", new ObjectParameter("UserCD", entity.UserCD)).First();
                    //标记删除
                    context.PatrolUserInfo.DeleteObject(instance);
                    trans.Complete();
                    success = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            try
            {
                if (success)
                {
                    //提交保存
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            context.Dispose();

            return(success);
        }
Exemple #16
0
        public Stream AddUser(Stream data)
        {
            #region 查找数据
            ResAddUser response = new ResAddUser();
            bool       success  = true;
            try
            {
                DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(ReqAddUser));
                //读取器
                StreamReader sr         = new StreamReader(data);
                string       dataString = String.Empty;
                while (!sr.EndOfStream)
                {
                    dataString = sr.ReadToEnd();
                    Console.WriteLine(dataString);

                    #region 日志输出
                    CommonInfo.Log(dataString);
                    #endregion

                    //反序列化json为对象注意顺序很重要
                    ReqAddUser   request = new ReqAddUser();
                    MemoryStream temp    = new MemoryStream(Encoding.UTF8.GetBytes(dataString));
                    request = json.ReadObject(temp) as ReqAddUser;

                    //关闭临时流
                    temp.Close();

                    //调用用户更新密码接口
                    if (request != null)
                    {
                        //**********(此处加入代码) 根据查询条件 加入业务逻辑代码*************
                        if (request.account != null && request.account != String.Empty && request.token != null && request.token != String.Empty)
                        {
                            if (request.user != null)
                            {
                                Console.WriteLine("开始新增用户");
                                PatrolUserInfo userinfo = new PatrolUserInfo();
                                userinfo.UserCD       = request.user.user_id;
                                userinfo.UserPassword = CommonInfo.DefaultPassword + userinfo.UserCD;
                                userinfo.SearchRange  = SetSearchRange(request.user.search_range);
                                userinfo.IsAdmin      = SetAdmin(request.user.isadmin);
                                userinfo.IsAvailable  = "1";
                                userinfo.CreatedAt    = DateTime.Now;
                                userinfo.Creator      = request.account;
                                Console.WriteLine("我的测试数据" + userinfo.IsAdmin);
                                success = UserEntity.InsertUser(userinfo);
                            }
                        }
                        else
                        {
                            Console.WriteLine("用户验证失败");
                        }
                    }
                    else
                    {
                        Console.WriteLine("请求对象为空");
                    }
                }
                sr.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                #region 日志输出
                CommonInfo.Error("获取特巡列表数据错误" + ex.Message);
                #endregion
            }

            //返回消息体
            if (success)
            {
                response.SetSuccess();
            }
            else
            {
                ////默认是失败
                //response.SetFailed();
            }
            //将消息序列化为Json格式数据
            DataContractJsonSerializer obj2Json = new DataContractJsonSerializer(typeof(ResAddUser));
            MemoryStream ms = new MemoryStream();
            obj2Json.WriteObject(ms, response);

            //注意一定要设置流的位置到开始位置,否则没有消息输出
            ms.Position = 0;
            return(ms);

            #endregion
        }