public IHttpActionResult AuthorizeOneDrive([FromUri] string code)
        {
            var url = RedirectUrl;

            try
            {
                var connector = new Connector.OneDrive.OneDrive(DataRepository);
                var member    = GetMemberFromAuthenticatedUser();

                var isAuthorized = connector.Authorize(HttpContext.Current, member.Id);

                if (isAuthorized && member.StorageAccessType == StorageProviderType.None)
                {
                    member.StorageAccessType = StorageProviderType.OneDrive;
                    DataRepository.Update(member);
                }
                connector.RefreshFolderContent();
            }

            catch (Exception ex)
            {
                Log.Error(ex);
                return(BadRequest("Cannot authorize"));
            }
            return(Redirect(url));
        }
Esempio n. 2
0
        public IHttpActionResult AuthorizeOneDrive([FromUri] string code)
        {
            var url = RedirectUrl;

            try
            {
                var connector = new Connector.OneDrive.OneDrive(DataRepository);
                var member    = GetMemberFromAuthenticatedUser();

                var isAuthorized = connector.Authorize(HttpContext.Current, member.Id);

                if (isAuthorized && member.StorageAccessType == StorageProviderType.None)
                {
                    member.StorageAccessType = StorageProviderType.OneDrive;
                    DataRepository.Update(member);
                }
                // ReSharper disable once IteratorMethodResultIsIgnored: Wir wollen nur, dass die Daten aktualisiert werden. Das Ergebnis intereesiert nicht
                connector.RefreshFolderContent();
            }

            catch (Exception ex)
            {
                Log.Error(ex);
                return(BadRequest("Cannot authorize"));
            }
            return(Redirect(url));
        }
        public Result <string> GetOneDriveAuthorizationUrl([FromBody] string url)
        {
            var result = new Result <string>();

            try
            {
                var connector = new Connector.OneDrive.OneDrive(DataRepository);
                var memberId  = GetMemberFromAuthenticatedUser().Id;
                result.Data = connector.GetAuthorizeUrl(Request.RequestUri.ToString(), url, memberId);
                if (result.Data == null)
                {
                    result.Status.Code = Controller.StatusCode.GoogleDriverAlreadyAuthorized;
                }
            }
            catch (Exception ex)
            {
                LogExceptionAndSetResult(ex, result);
            }

            return(result);
        }
Esempio n. 4
0
        internal IConnector CurrentConnector(Member member)
        {
            if (member == null || member.StorageAccesses.Count == 0)
            {
                return(null);
            }

            IConnector connector;

            switch (member.StorageAccessType)
            {
            case StorageProviderType.Dropbox:
                connector = new DropboxConnector(DataRepository);
                break;

            case StorageProviderType.GoogleDrive:
                connector = new GoogleDrive(DataRepository);
                break;

            case StorageProviderType.OneDrive:
                connector = new Connector.OneDrive.OneDrive(DataRepository);
                break;

            case StorageProviderType.LocalDrive:
                connector = new LocalDrive(DataRepository,
                                           string.Format("{0}://{1}", Request.RequestUri.Scheme, Request.RequestUri.Authority),
                                           member.Alias);
                break;

            default:
                throw new NotImplementedException("Der Connector ist noch nicht implementiert!");
            }
            var access = member.StorageAccesses.First(s => s.Type == member.StorageAccessType);

            connector.RedirectUrl   = RedirectUrl;
            connector.CurrentMember = member;
            connector.Connect(access);

            return(connector);
        }