Ejemplo n.º 1
0
        public bool ChangePassword(string oldPassword, string newPassword)
        {
            int id = GetClientId();

            if (id < 0)
            {
                return(false);
            }

            using (ShareWareEntities context = new ShareWareEntities())
            {
                try
                {
                    Users user = context.Users.Single(T => T.UserID == id);

                    if (user.Password == oldPassword)
                    {
                        user.Password = newPassword;
                        context.SaveChanges();
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public bool ChangeUserInfo(UserInfo userInfo)
        {
            int id = GetClientId();

            if (id < 0)
            {
                return(false);
            }

            using (ShareWareEntities context = new ShareWareEntities())
            {
                try
                {
                    Users user = context.Users.Single(T => T.UserID == id);
                    user.NickName  = userInfo.NickName;
                    user.IsMale    = userInfo.IsMale;
                    user.QQ        = userInfo.QQ;
                    user.MicroBlog = userInfo.MicroBlog;
                    user.Signature = userInfo.Signature;
                    context.SaveChanges();
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        public void UploadImage(Bitmap image)
        {
            int id = GetClientId();

            if (id < 0)
            {
                return;
            }

            using (ShareWareEntities context = new ShareWareEntities())
            {
                var    user      = context.Users.Single(T => T.UserID == id);
                string nameHash  = ComputeStringMd5(user.UserName);
                string imagePath = ImagePath;
                if (!Directory.Exists(imagePath))
                {
                    Directory.CreateDirectory(imagePath);
                }

                string filePath = imagePath + nameHash.ToString() + ".jpg";
                image.Save(filePath, ImageFormat.Jpeg);
                string fileHash = ComputeFileMd5(filePath);

                user.ImageHash = fileHash;
                context.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public void RemoveOldFile(List <FileInfoTransfer> fileList)
        {
            int id = GetClientId();

            if (id < 0)
            {
                return;
            }
            using (ShareWareEntities context = new ShareWareEntities())
            {
                foreach (var item in fileList)
                {
                    var res = from c in context.FileOwner
                              where c.UserID == id && c.Hash == item.Hash
                              select c;
                    foreach (var file in res)
                    {
                        context.FileOwner.Remove(file);
                    }
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception)
                    {
                        // throw;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void RemoveNotExistShreFileList(List <string> hashList)
        {
            int id = GetClientId();

            if (id < 0)
            {
                return;
            }

            try
            {
                using (ShareWareEntities context = new ShareWareEntities())
                {
                    foreach (var hash in hashList)
                    {
                        var file = from c in context.FileOwner
                                   where (c.UserID == id && c.Hash == hash)
                                   select c;
                        foreach (var item in file)
                        {
                            context.FileOwner.Remove(item);
                        }
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception)
            {
                return;
            }
        }
Ejemplo n.º 6
0
        public RegError Register(UserInfo userInfo)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                using (ShareWareEntities context = new ShareWareEntities())
                {
                    try
                    {
                        var result = from c in context.Users
                                     where c.UserName == userInfo.UserName
                                     select c;
                        if (result.Count() > 0)
                        {
                            return(RegError.UserExist);
                        }

                        Users newUser = new Users()
                        {
                            UserName  = userInfo.UserName,
                            Password  = userInfo.Password,
                            NickName  = userInfo.NickName,
                            IsMale    = userInfo.IsMale,
                            QQ        = userInfo.QQ,
                            MicroBlog = userInfo.MicroBlog,
                            Signature = userInfo.Signature
                        };
                        context.Users.Add(newUser);

                        context.SaveChanges();


                        var    user      = context.Users.Single(T => T.UserName == newUser.UserName);
                        string nameHash  = ShareService.ComputeStringMd5(user.UserName);
                        string imagePath = ConfigurationManager.AppSettings["ImagePath"];
                        if (!Directory.Exists(imagePath))
                        {
                            Directory.CreateDirectory(imagePath);
                        }
                        if (userInfo.Image != null)
                        {
                            string filePath = imagePath + nameHash.ToString() + ".jpg";
                            userInfo.Image.Save(filePath, ImageFormat.Jpeg);
                            string fileHash = ShareService.ComputeFileMd5(filePath);

                            user.ImageHash = fileHash;
                            context.SaveChanges();
                        }

                        transaction.Complete();
                    }
                    catch (Exception)
                    {
                        return(RegError.Ohter);
                    }
                }
            }

            return(RegError.NoError);
        }
Ejemplo n.º 7
0
 public override void Validate(string userName, string password)
 {
     using (ShareWareEntities context = new ShareWareEntities())
     {
         context.Users.Single(us => us.UserName == userName && us.Password == password);
     }
     //if (userName != "asd" || password != "asdd")
     //{
     //    throw new System.IdentityModel.Tokens.SecurityTokenException("Unknown Username or Password");
     //    // throw new Exception("sjhiiiidjasdadasdad");
     //}
 }