コード例 #1
0
ファイル: TreeController.cs プロジェクト: kendarorg/CryptoApp
        public ItemData GetFullData(String id)
        {
            var user = _userSvc.CurrentUser();
            var cry  = (CryptoService)HttpContext.Current.Session["DATA"];

            var      item  = cry.FindById(id);
            AuthLeaf iteml = item as AuthLeaf;
            AuthTree itemt = item as AuthTree;

            if (iteml != null)
            {
                return(new ItemData
                {
                    ExpireTime = iteml.ExpireTime,
                    IsFolder = false,
                    Id = iteml.Id,
                    Notes = iteml.Notes,
                    Title = iteml.Title,
                    Url = iteml.Url,
                    UserName = iteml.UserName,
                    HasAttachment = iteml.HasAttachment
                });
            }
            else if (itemt != null)
            {
                return(new ItemData
                {
                    IsFolder = true,
                    Id = itemt.Id,
                    Title = itemt.Title
                });
            }
            return(null);
        }
コード例 #2
0
        public Guid Upload(String itemId)
        {
            var    user = _userSvc.CurrentUser();
            Attach file = _attach.GetById(Guid.Parse(itemId));

            if (file != null && file.UserId != user.Id)
            {
                throw new Exception();
            }
            if (HttpContext.Current.Request.Files["file"] == null)
            {
                throw new Exception();
            }
            var encriptionKey = HttpContext.Current.Session["FILEKEY"].ToString();

            using (var fileUploadStream = HttpContext.Current.Request.Files["file"].InputStream)
            {
                using (var ms = new MemoryStream())
                {
                    fileUploadStream.CopyTo(ms);
                    var data = ms.ToArray();

                    var strData = Encoding.UTF8.GetString(data);


                    var      cry = (CryptoService)HttpContext.Current.Session["DATA"];
                    AuthLeaf ida = cry.FindById(itemId) as AuthLeaf;
                    ida.HasAttachment = HttpContext.Current.Request.Files["file"].FileName;

                    var id = _files.GetIdByIdUserAndLabel(user.Id, HttpContext.Current.Session["FILE"].ToString());

                    var encrypted = _crypt.Encrypt(data, encriptionKey);
                    if (file == null)
                    {
                        file = new Attach
                        {
                            Id     = Guid.Parse(itemId),
                            Data   = encrypted,
                            FileId = id,
                            Name   = HttpContext.Current.Request.Files["file"].FileName,
                            UserId = user.Id
                        };
                        _attach.Add(file);
                    }
                    else
                    {
                        file.Data = encrypted;
                        file.Name = HttpContext.Current.Request.Files["file"].FileName;
                        _attach.Update(file);
                    }
                    Save();


                    return(file.Id);
                }
            }
        }
コード例 #3
0
ファイル: TreeController.cs プロジェクト: kendarorg/CryptoApp
        public String GetPassword(String id)
        {
            var      user = _userSvc.CurrentUser();
            var      cry  = (CryptoService)HttpContext.Current.Session["DATA"];
            AuthLeaf item = cry.FindById(id) as AuthLeaf;

            if (item == null)
            {
                return(String.Empty);
            }
            item.LastAccessTime = DateTime.UtcNow;
            Save();
            return(item.Password);
        }
コード例 #4
0
ファイル: TreeController.cs プロジェクト: kendarorg/CryptoApp
        public void ChangePassword(PasswordChangeModel changeModel, String id)
        {
            var user = _userSvc.CurrentUser();

            if (changeModel.New != changeModel.NewRepeat)
            {
                throw new Exception("Not matching passwords");
            }
            var      cry  = (CryptoService)HttpContext.Current.Session["DATA"];
            var      file = (String)HttpContext.Current.Session["FILE"];
            AuthLeaf item = cry.FindById(id) as AuthLeaf;

            //if (item.Password != changeModel.Old) throw new Exception("Not matching passwords");
            item.Password         = changeModel.New;
            item.LastModifiedTime = DateTime.UtcNow;
            Save();
        }
コード例 #5
0
ファイル: TreeController.cs プロジェクト: kendarorg/CryptoApp
        public String UpdateItem(ItemData item)
        {
            var user     = _userSvc.CurrentUser();
            var cry      = (CryptoService)HttpContext.Current.Session["DATA"];
            var file     = (String)HttpContext.Current.Session["FILE"];
            var toUpdate = cry.FindById(item.Id);
            var parentId = item.ParentId;

            if (String.IsNullOrWhiteSpace(parentId))
            {
                parentId = toUpdate.Parent.Id;
            }
            var      parentItem = cry.FindById(parentId) as AuthTree;
            AuthTree toUpdatet  = toUpdate as AuthTree;
            AuthLeaf toUpdatel  = toUpdate as AuthLeaf;

            if (parentItem == cry.Root && toUpdatet == null)
            {
                throw new Exception("ONLY FOLDERS CAN BE ADDED TO ROOT!!");
            }
            if (parentItem.Id != toUpdate.Parent.Id)
            {
                toUpdate.Parent.Children.Remove(toUpdate);
                parentItem.Children.Add(toUpdate);
                toUpdate.Parent = parentItem;
            }
            if (toUpdatet != null)
            {
                toUpdatet.Title = item.Title;
            }
            else if (toUpdatel != null)
            {
                toUpdatel.Notes            = item.Notes;
                toUpdatel.UserName         = item.UserName;
                toUpdatel.Url              = item.Url;
                toUpdatel.Title            = item.Title;
                toUpdatel.LastModifiedTime = DateTime.UtcNow;
                toUpdatel.HasAttachment    = item.HasAttachment;
            }
            Save();
            return(item.Id);
        }
コード例 #6
0
ファイル: TreeController.cs プロジェクト: kendarorg/CryptoApp
        public void CreateItem(ItemData item)
        {
            var      user     = _userSvc.CurrentUser();
            var      cry      = (CryptoService)HttpContext.Current.Session["DATA"];
            var      file     = (String)HttpContext.Current.Session["FILE"];
            var      parentId = item.ParentId;
            AuthTree ida      = cry.FindById(parentId) as AuthTree;

            if (item.IsFolder)
            {
                var newNode = new AuthTree
                {
                    Title  = item.Title,
                    Parent = ida
                };
                ida.Children.Add(newNode);
                cry.RegisterNode(newNode);
            }
            else
            {
                var newNode = new AuthLeaf
                {
                    Notes         = item.Notes,
                    ExpireTime    = item.ExpireTime,
                    Title         = item.Title,
                    Url           = item.Url,
                    UserName      = item.UserName,
                    Password      = item.Password,
                    Parent        = ida,
                    HasAttachment = item.HasAttachment
                };
                ida.Children.Add(newNode);
                cry.RegisterNode(newNode);
            }
            Save();
        }