Ejemplo n.º 1
0
        /// <summary>
        /// Publish a file that will become the new base revision of a previously existing file.  Beware.
        /// </summary>
        /// <param name="ticket">ThreeSixtySharp.Objects.AuthTicket instance for current user.</param>
        /// <param name="project">ThreeSixtySharp.Objects.Project instance to return files from.</param>
        /// <param name="doc_path"></param>
        /// <param name="origin_full_filename"></param>
        /// <param name="document_id">The ThreeSixtySharp.Objects.File.Document_Id parameter of the file to revise.</param>
        /// <param name="tags"></param>
        /// <param name="caption"></param>
        /// <param name="allow_replace"></param>
        /// <returns></returns>
        public ThreeSixtySharp.Objects.File PublishBaseRevision(AuthTicket ticket,
                                                                Project project,
                                                                Document_Path doc_path,
                                                                string origin_full_filename,
                                                                string document_id,
                                                                List <string> tags = null,
                                                                string caption     = null)
        {
            var request = new RestRequest(Method.POST);

            request.Resource = "api/library/publish?replace=1";
            request.AddParameter("ticket", ticket.Ticket);
            request.AddParameter("project_id", project.Project_ID);
            request.AddParameter("directory", doc_path.Path);
            request.AddParameter("filename", System.IO.Path.GetFileName(origin_full_filename));
            request.AddFile("Filedata", origin_full_filename);

            if (tags != null)
            {
                request.AddParameter("tags", string.Join(", ", tags));
            }
            if (caption != null)
            {
                request.AddParameter("caption", caption);
            }

            return(Execute <ThreeSixtySharp.Objects.File>(request));
        }
Ejemplo n.º 2
0
        public void DownloadFile(AuthTicket ticket, Project project, string document_id, int revision_number)
        {
            var request = new RestRequest(Method.POST);

            request.Resource = "api/library/file/{id}/{type}/{rev}";
            request.AddParameter("ticket", ticket.Ticket);
            request.AddParameter("project_id", project.Project_ID);
            request.AddParameter("id", document_id, ParameterType.UrlSegment);
            request.AddParameter("type", "original", ParameterType.UrlSegment);
            request.AddParameter("rev", revision_number);

            var client = new RestClient();

            client.BaseUrl = BaseUrl;
            client.ExecuteAsync(request, response =>
            {
                if (response.ErrorException != null)
                {
                    throw response.ErrorException;
                }
                else
                {
                    byte[] file_bytes = response.RawBytes;
                    //in progress
                }
            });
        }
Ejemplo n.º 3
0
        public void SetAuthTicket(AuthTicket authTicket)
        {
            AuthTicket = authTicket;
            var expire_time = Utils.TimeMStoString((long)AuthTicket.ExpireTimestampMs, @"mm\:ss");

            Logger.Debug($"===================> Recieved Auth Ticket: {authTicket} --- Expires in: {expire_time}");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Asynchronous method to publish a file that will become the new base revision of a previously existing file.  Beware.
        /// </summary>
        /// <param name="ticket">ThreeSixtySharp.Objects.AuthTicket instance for current user.</param>
        /// <param name="project">ThreeSixtySharp.Objects.Project instance to return files from.</param>
        /// <param name="doc_path"></param>
        /// <param name="origin_full_filename"></param>
        /// <param name="document_id">The ThreeSixtySharp.Objects.File.Document_Id parameter of the file to revise.</param>
        /// <param name="tags"></param>
        /// <param name="caption"></param>
        /// <returns></returns>
        public Task <ThreeSixtySharp.Objects.File> PublishBaseRevisionAsync(AuthTicket ticket,
                                                                            Project project,
                                                                            Document_Path doc_path,
                                                                            string origin_full_filename,
                                                                            string document_id,
                                                                            List <string> tags = null,
                                                                            string caption     = null)
        {
            var request = new RestRequest(Method.POST);

            request.Resource = "api/library/publish?replace=1";
            request.AddParameter("ticket", ticket.Ticket);
            request.AddParameter("project_id", project.Project_ID);
            request.AddParameter("directory", doc_path.Path);
            request.AddParameter("filename", System.IO.Path.GetFileName(origin_full_filename));
            using (FileStream fileStream = System.IO.File.OpenRead(origin_full_filename))
            {
                MemoryStream memStream = new MemoryStream();
                memStream.SetLength(fileStream.Length);
                fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length);
                request.AddFile("Filedata", ReadToEnd(fileStream), origin_full_filename);
                if (tags != null)
                {
                    request.AddParameter("tags", string.Join(",", tags));
                }
                if (caption != null)
                {
                    request.AddParameter("caption", caption);
                }

                return(ExecuteAsync <ThreeSixtySharp.Objects.File>(request));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ActionActivityContext" /> class.
        /// </summary>
        /// <param name="action">The action.</param>
        public ActionActivityContext(
            ProjectItem project,
            ActionItem action,
            AuthTicket authTicket         = null,
            ContactItem contact           = null,
            ObjectState contactState      = ObjectState.Unchanged,
            PropertyDictionary properties = null,
            EventItem eventItem           = null)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            Project          = project;
            RootAction       = Action = action;
            AuthTicket       = authTicket;
            Event            = eventItem ?? new EventItem();
            Event.ObjectType = ObjectType.Action;
            Event.ObjectId   = action.Id;
            Event.Project    = project;
            AnonymId         = Event.AnonymId;
            Contact          = contact;
            ContactState     = contactState;
            Properties       = properties == null ? new PropertyDictionary() : new PropertyDictionary(properties);
            Errors           = new List <string>();
        }
Ejemplo n.º 6
0
        public async Task <System.Web.Mvc.ActionResult> Portal(
            string portalUri,
            string pageUri,
            string preview,
            [ModelBinder(typeof(ActionLinkModelBinder))] ActionLink actionLink,
            [ModelBinder(typeof(AuthTicketModelBinder))] AuthTicket authTicket,
            CancellationToken cancellationToken)
        {
            var portal = await _portalManager.FindByUriAsync(portalUri, PortalField.Project | PortalField.Owners, cancellationToken);

            if (portal == null)
            {
                return(HttpNotFound());
            }
            if (!string.IsNullOrEmpty(portal.Domain))
            {
                return(Redirect(string.Join("/", "http://www." + portal.Domain, pageUri)));
            }
            var security = await _securityManager.CheckAccessAsync(portal, User.Identity.Name, AccessPermission.CanView, cancellationToken);

            if (!security.AccessGranted)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            var pageLayers = await _portalManager.GetPageLayersByUriAsync(portal, pageUri, cancellationToken);

            if (pageLayers?.ContentPage == null)
            {
                return(HttpNotFound());
            }
            return(View("Content", await CreateResultAsync(security, portal, pageLayers, actionLink, authTicket, preview == null, cancellationToken)));
        }
Ejemplo n.º 7
0
        public RequestBuilder(string authToken, AuthType authType, double latitude, double longitude, double altitude, ISettings settings, AuthTicket authTicket = null)
        {
            _authToken     = authToken;
            _authType      = authType;
            _latitude      = latitude;
            _longitude     = longitude;
            _altitude      = altitude;
            this.settings  = settings;
            _authTicket    = authTicket;
            _nextRequestId = Convert.ToUInt64(RandomDevice.NextDouble() * Math.Pow(10, 18));
            if (_startTime == 0)
            {
                _startTime = Utils.GetTime(true);
            }

            if (SessionHash == null)
            {
                GenerateNewHash();
            }

            if (crypt == null)
            {
                crypt = new Crypt();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 获取登录时设置的票据
        /// </summary>
        /// <param name="uid">用户标识</param>
        /// <param name="days">有效时间</param>
        /// <param name="roles">用户所属的角色</param>
        /// <param name="data">用户附加数据</param>
        /// <returns>认证票据</returns>
        public Dictionary <string, string> SignIn(string uid, int days, string[] roles, object data)
        {
            //实际上在这里 AuthTicket.UserId 和 FormsAuthenticationTicket里的 uid 冗余了
            //不过两者最好保持一致
            var expire   = DateTime.Now.AddDays(days);
            var dataJson = AuthTicket <object> .Create(uid, roles, data, expire).ToJson();

            var ticket      = new FormsAuthenticationTicket(2, uid, DateTime.Now, DateTime.Now.AddDays(days), true, dataJson);
            var cookieValue = FormsAuthentication.Encrypt(ticket);

            var cookieName = FormsAuthentication.FormsCookieName ?? typeof(FormsAuthAuthentication).Name;
            var cookiePath = FormsAuthentication.FormsCookiePath ?? "/";

            var setCookieValue = String.Format("{0}={1}; Path={2}; Domain={3}; HttpOnly",
                                               cookieName,
                                               cookieValue,
                                               cookiePath,
                                               FormsAuthentication.CookieDomain);
            var headers = new Dictionary <string, string>()
            {
                { "Set-Cookie", setCookieValue }
            };


            return(headers);
        }
Ejemplo n.º 9
0
        public ActionResult Login(Person loginAttempt)
        {
            var person = db.ReadSinglePerson(loginAttempt.email);

            if (person != null && Password.Authenticate(loginAttempt.password, person.password))
            {
                UserPrincipalSerialize user = new UserPrincipalSerialize(person);
                Response.Cookies.Add(AuthTicket.Make(user));

                if (user.IsInRole("Admin"))
                {
                    return(RedirectToAction("Index", "Admin"));
                }
                else if (user.IsInRole("Pharmacist"))
                {
                    return(RedirectToAction("Index", "Pharmacy"));
                }
                else
                {
                    return(RedirectToAction("Index", "User"));
                }
            }
            else
            {
                ModelState.AddModelError("", "Login data is incorrect!");
            }

            return(View(loginAttempt));
        }
Ejemplo n.º 10
0
        public RequestBuilder(Client client, string authToken, AuthType authType, double latitude, double longitude, double altitude, ISettings settings,
                              AuthTicket authTicket = null)
        {
            if (!setupdevicedone)
            {
                setUpDevice();
            }

            _client     = client;
            _authToken  = authToken;
            _authType   = authType;
            _latitude   = latitude;
            _longitude  = longitude;
            _altitude   = altitude;
            _authTicket = authTicket;
            _settings   = settings;


            // Add small variance to speed.
            _speed = _speed + ((float)Math.Round(GenRandom(-1, 1), 7));



            if (_settings.SessionHash == null)
            {
                GenerateNewHash();
            }

            if (_crypt == null)
            {
                _crypt = new Crypt();
            }
        }
Ejemplo n.º 11
0
        // GET api/<controller>
        public HttpResponseMessage Get(string username, string password, string version, string clientid)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(ERROR_020());
            }

            AuthTicket ticket = null;

            var api = Api.INSTANCE;

            using (var db = api.DAFactory.Get())
            {
                var user = db.Users.GetByUsername(username);
                if (user == null || user.is_banned)
                {
                    return(ERROR_110());
                }

                if (api.Config.Maintainance && !(user.is_admin || user.is_moderator))
                {
                    return(ERROR_160());
                }

                var authSettings      = db.Users.GetAuthenticationSettings(user.user_id);
                var isPasswordCorrect = PasswordHasher.Verify(password, new PasswordHash
                {
                    data   = authSettings.data,
                    scheme = authSettings.scheme_class
                });

                if (!isPasswordCorrect)
                {
                    return(ERROR_110());
                }

                var ip = ApiUtils.GetIP(Request);

                var ban = db.Bans.GetByIP(ip);
                if (ban != null)
                {
                    return(ERROR_110());
                }

                db.Users.UpdateClientID(user.user_id, clientid ?? "0");

                /** Make a ticket **/
                ticket           = new AuthTicket();
                ticket.ticket_id = Guid.NewGuid().ToString().Replace("-", "");
                ticket.user_id   = user.user_id;
                ticket.date      = Epoch.Now;
                ticket.ip        = ip;

                db.AuthTickets.Create(ticket);
            }

            var content = "Valid=TRUE\r\nTicket=" + ticket.ticket_id.ToString() + "\r\n";

            return(ApiResponse.Plain(HttpStatusCode.OK, content));
        }
Ejemplo n.º 12
0
        public RequestBuilder(Client client, string authToken, AuthType authType, double latitude, double longitude, double altitude, float speed,
                              ISettings settings, AuthTicket authTicket = null)
        {
            _client    = client;
            _authToken = authToken;
            _authType  = authType;
            _latitude  = latitude;
            _longitude = longitude;
            _altitude  = altitude;

            // Add small variance to speed.
            _speed = speed + ((float)Math.Round(GenRandom(-1, 1), 7));

            // If speed is 0 or negative, make it random.
            if (_speed <= 0)
            {
                _speed = (float)TRandomDevice.Triangular(0.1, 3.1, .8);
            }

            _horizontalAccuracy = TRandomDevice.Choice(new List <double>(new double[] { 5, 5, 5, 5, 10, 10, 10, 30, 30, 50, 65, GenRandom(66, 80) }));

            _settings   = settings;
            _authTicket = authTicket;

            if (SessionHash == null)
            {
                GenerateNewHash();
            }

            if (_crypt == null)
            {
                _crypt = new Crypt();
            }
        }
Ejemplo n.º 13
0
        public async Task <ThreeSixtySharp.Objects.File> GetFileMetadataAsync(AuthTicket ticket, Project project, string document_id, int revision_number)
        {
            var request = new RestRequest(Method.POST);

            request.Resource = "api/library/file/{id}/{type}/{rev}";
            request.AddParameter("ticket", ticket.Ticket);
            request.AddParameter("project_id", project.Project_ID);
            request.AddParameter("id", document_id, ParameterType.UrlSegment);
            request.AddParameter("type", "metadata", ParameterType.UrlSegment);
            request.AddParameter("rev", revision_number, ParameterType.UrlSegment);
            request.RootElement = "document";

            Task <ThreeSixtySharp.Objects.File> fileMetaDataTask = ExecuteAsync <ThreeSixtySharp.Objects.File>(request);

            ThreeSixtySharp.Objects.File metaDataFile = await fileMetaDataTask;
            if (metaDataFile.Tags != null)
            {
                //This is a janky short term fix.  BIM 360 Field returns Tags as an
                //array of strings and a custom deserializer needs to be made to parse this
                //into this list of strings.  This should be ok for now.
                List <string> parsedTags = metaDataFile.Tags[0].Split(',').ToList();
                metaDataFile.Tags = parsedTags;
            }

            return(metaDataFile);
        }
Ejemplo n.º 14
0
 private SteamUser(SteamId id, byte[] authData)
 {
     UserId     = id;
     AuthTicket = new AuthTicket
     {
         Data = authData
     };
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Get a list of Project objects that the owner of the ticket has access to.
        /// </summary>
        /// <param name="ticket">ThreeSixtySharp.Objects.AuthTicket instance for current user.</param>
        /// <returns>List of ThreeSixtySharp.Objects.Project instances that the owner of the
        /// AuthTicket has access to.</returns>
        public List <Project> GetProjects(AuthTicket ticket)
        {
            var request = new RestRequest(Method.GET);

            request.Resource = "api/projects";
            request.AddParameter("ticket", ticket.Ticket);

            return(Execute <List <Project> >(request));
        }
        //private void SteamFriends_OnGameLobbyJoinRequested(Lobby arg1, SteamId arg2)
        //{
        //    arg1.GetGameServer();
        //}

        public void StartClient()
        {
            if (clientAuth != null)
            {
                clientAuth.Cancel();
                clientAuth = null;
            }
            clientAuth    = SteamUser.GetAuthSessionTicket();
            clientStarted = true;
        }
Ejemplo n.º 17
0
 public RequestBuilder(string authToken, AuthType authType, double latitude, double longitude, double altitude,
     AuthTicket authTicket = null)
 {
     _authToken = authToken;
     _authType = authType;
     _latitude = latitude;
     _longitude = longitude;
     _altitude = altitude;
     _authTicket = authTicket;
 }
Ejemplo n.º 18
0
        public Task <List <Issue> > GetIssuesAsync(AuthTicket ticket, Project project)
        {
            var request = new RestRequest(Method.POST);

            request.Resource = "api/get_issues";
            request.AddParameter("ticket", ticket.Ticket);
            request.AddParameter("project_id", project.Project_ID);

            return(ExecuteAsync <List <Issue> >(request));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Expires a ticket for access to a specific project.
        /// </summary>
        /// <param name="ticket">ThreeSixtySharp.Objects.AuthTicket instance for current user.</param>
        /// <param name="project">ThreeSixtySharp.Objects.Project instance to return ticket for.</param>
        public void ReturnTicketOneProject(AuthTicket ticket, Project project)
        {
            var request = new RestRequest(Method.POST);

            request.Resource = "api/logout";
            request.AddParameter("ticket", ticket);
            request.AddParameter("project_id", project.Project_ID);

            Execute(request);
        }
Ejemplo n.º 20
0
 public RequestBuilder(string authToken, AuthType authType, double latitude, double longitude, double altitude,
                       AuthTicket authTicket = null)
 {
     _authToken  = authToken;
     _authType   = authType;
     _latitude   = latitude;
     _longitude  = longitude;
     _altitude   = altitude;
     _authTicket = authTicket;
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Delete all revisions of a given file.
        /// </summary>
        /// <param name="ticket">ThreeSixtySharp.Objects.AuthTicket instance for current user.</param>
        /// <param name="project">ThreeSixtySharp.Objects.Project instance to return files from.</param>
        /// <param name="doc">ThreeSixtySharp.Objects.File instance to delete.</param>
        public void DeleteAllRevisions(AuthTicket ticket, Project project, ThreeSixtySharp.Objects.File doc)
        {
            var request = new RestRequest(Method.POST);

            request.Resource = "api/library/delete";
            request.AddParameter("ticket", ticket.Ticket);
            request.AddParameter("project_id", project.Project_ID);
            request.AddParameter("id", doc.Document_Id);
            request.AddParameter("rev", "nil");

            Execute(request);
        }
Ejemplo n.º 22
0
 public RequestBuilder(string authToken, AuthType authType, double latitude, double longitude, double altitude,
     AuthTicket authTicket = null)
 {
     _authToken = authToken;
     _authType = authType;
     _latitude = latitude;
     _longitude = longitude;
     _altitude = altitude;
     _authTicket = authTicket;
     if (!_internalWatch.IsRunning)
         _internalWatch.Start();
 }
Ejemplo n.º 23
0
 public RequestBuilder(string authToken, AuthType authType, double latitude, double longitude, double accuracy,
                       IDeviceInfo deviceInfo,
                       AuthTicket authTicket = null)
 {
     _authToken  = authToken;
     _authType   = authType;
     _latitude   = latitude;
     _longitude  = longitude;
     _accuracy   = accuracy;
     _authTicket = authTicket;
     _deviceInfo = deviceInfo;
 }
        public static void Test_Envelope_WithAuthTicket()
        {
            //arrange
            RequestEnvelope envelope = new RequestEnvelope();
            AuthTicket      ticket   = new AuthTicket();

            //act
            envelope.WithAuthTicket(ticket);

            //assert
            Assert.NotNull(envelope.AuthTicket);
            Assert.AreEqual(ticket, envelope.AuthTicket);
        }
Ejemplo n.º 25
0
        public List <ThreeSixtySharp.Objects.File> GetFileMetadataAllRevisions(AuthTicket ticket, Project project, string document_id)
        {
            var request = new RestRequest(Method.POST);

            request.Resource = "api/library/file/{id}/{type}/{rev}";
            request.AddParameter("ticket", ticket.Ticket);
            request.AddParameter("project_id", project.Project_ID);
            request.AddParameter("id", document_id, ParameterType.UrlSegment);
            request.AddParameter("type", "metadata", ParameterType.UrlSegment);
            request.RootElement = "document";

            return(Execute <List <ThreeSixtySharp.Objects.File> >(request));
        }
Ejemplo n.º 26
0
        public async Task <IHttpActionResult> GetAsync(
            [FromUri(BinderType = typeof(ActionLinkModelBinder))] ActionLink linkParams,
            [FromUri(BinderType = typeof(AuthTicketModelBinder))] AuthTicket authTicket,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }
            var contact = await GetContactAsync(linkParams, authTicket, cancellationToken);

            return(await ExecuteActionAsync(linkParams, authTicket, contact, null, cancellationToken));
        }
Ejemplo n.º 27
0
        public static RequestEnvelope GetRequestEnvelope(AuthTicket authTicket, double lat, double lng, double altitude)
        {
            RequestEnvelope envelope = new RequestEnvelope();

            //These requests are sent with our issued AuthTicket
            envelope.WithAltitude(altitude)
            .WithLatitude(lat)
            .WithLongitude(lng)
            .WithRequestID()     //RPC ID?
            .WithAuthTicket(authTicket);

            return(envelope);
        }
Ejemplo n.º 28
0
 public RequestBuilder(string authToken, AuthType authType, double latitude, double longitude, double altitude,
                       AuthTicket authTicket = null)
 {
     _authToken  = authToken;
     _authType   = authType;
     _latitude   = latitude;
     _longitude  = longitude;
     _altitude   = altitude;
     _authTicket = authTicket;
     if (!_internalWatch.IsRunning)
     {
         _internalWatch.Start();
     }
 }
            public void OnResponse(ResponseEnvelope envelope)
            {
                if (envelope == null)
                {
                    throw new ArgumentNullException(nameof(envelope));
                }

                isCompleted = true;
                Result      = envelope;
                ResultState = envelope != null ? FutureState.Valid : FutureState.Invalid;

                ApiUrl = envelope.ApiUrl;
                ticket = envelope.AuthTicket;
            }
Ejemplo n.º 30
0
 public RequestBuilder(string authToken, AuthType authType, double latitude, double longitude, double altitude, ISettings settings, AuthTicket authTicket = null)
 {
     _authToken     = authToken;
     _authType      = authType;
     _latitude      = latitude;
     _longitude     = longitude;
     _altitude      = altitude;
     this._settings = settings;
     _authTicket    = authTicket;
     if (!InternalWatch.IsRunning)
     {
         InternalWatch.Start();
     }
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Iterates through list of projects current user has access to and
        /// expires the ticket for each one.
        /// </summary>
        /// <param name="ticket">ThreeSixtySharp.Objects.AuthTicket instance for current user.</param>
        public void ReturnTicketAllProjects(AuthTicket ticket)
        {
            List <Project> projects = GetProjects(ticket);

            foreach (Project project in projects)
            {
                var request = new RestRequest(Method.POST);
                request.Resource = "api/logout";
                request.AddParameter("ticket", ticket);
                request.AddParameter("project_id", project.Project_ID);

                Execute(request);
            }
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Asynchronous method for returning a list of all ThreeSixtySharp.Objects.File objects for a specified Project,
        /// and optionally for just a specified Document_Path.
        /// </summary>
        /// <param name="ticket">ThreeSixtySharp.Objects.AuthTicket instance for current user.</param>
        /// <param name="project">ThreeSixtySharp.Objects.Project instance to return files from.</param>
        /// <param name="path">Optional ThreeSixtySharp.Objects.Document_Path instance that filters returned File instances
        /// to just those located at the Document_Path.Path location.</param>
        /// <returns>List of ThreeSixtySharp.Object.File instances.</returns>
        public Task <List <ThreeSixtySharp.Objects.File> > GetAllFilesAsync(AuthTicket ticket, Project project, Document_Path path = null)
        {
            var request = new RestRequest(Method.GET);

            request.Resource = "api/library/all_files";
            if (path != null)
            {
                request.AddParameter("directory", path.Path);
            }

            request.AddParameter("ticket", ticket.Ticket);
            request.AddParameter("project_id", project.Project_ID);
            return(ExecuteAsync <List <ThreeSixtySharp.Objects.File> >(request));
        }