Exemplo n.º 1
0
        public bool Check(Network network, User user)
        {
            var entry = Get(network, user);
            var result = entry != null;

            return result;
        }
Exemplo n.º 2
0
        public Device Get(User user, int id)
        {
            var result = Get(id);

            if (result == null)
            {
                return null;
            }

            if (result.Network == null)
            {
                throw new Exception("Network not set");
            }

            if (result.Network.Owner == null)
            {
                throw new Exception("Owner not set");
            }

            if (result.Network.Owner.Id != user.Id)
            {
                var guest = _guests.Check(result.Network, user);

                if (!guest)
                {
                    result = null;
                }
            }

            return result;
        }
Exemplo n.º 3
0
        public ActionResult Edit(User user)
        {
            this.User.Alias = user.Alias;
            Database.Users.Update(User);

            return View(User);
        }
Exemplo n.º 4
0
        public static UserSession CreateSession(IRoomieDatabaseContext database, User user)
        {
            var userSession = UserSession.Create(user);

            database.Sessions.Add(userSession);

            return userSession;
        }
Exemplo n.º 5
0
 public UserSession(DateTime creationTimeStamp, int id, DateTime lastContactTimeStamp, string token, User user)
 {
     CreationTimeStamp = creationTimeStamp;
     Id = id;
     LastContactTimeStamp = lastContactTimeStamp;
     Token = token;
     User = user;
 }
Exemplo n.º 6
0
        public void Remove(Network network, User user)
        {
            var entry = Get(network, user);

            _entries.Remove(entry);

            _save();
        }
        public Network[] Get(User user)
        {
            var primaryNetworks = _networks.Get(user);
            var guestNetworks = _guests.Get(user);
            var result = primaryNetworks.Concat(guestNetworks).ToArray();

            return result;
        }
Exemplo n.º 8
0
        Page<UserSession> ISessionRepository.ListUserSessions(User user, ListFilter filter)
        {
            var result = _userSessions
                .Where(x => x.User.Id == user.Id)
                .Page(filter, x => x.Id)
                .Transform(x => x.ToRepositoryType());

            return result;
        }
Exemplo n.º 9
0
        public Network[] Get(User user)
        {
            var results = _networks
                .Where(x => x.Owner.Id == user.Id)
                .ToArray()
                .Select(x => x.ToRepositoryType())
                .ToArray();

            return results;
        }
Exemplo n.º 10
0
 public Task(DateTime? expiration, int id, string origin, User owner, DateTime? receivedTimestamp, Script script, Computer target)
 {
     Expiration = expiration;
     Id = id;
     Origin = origin;
     Owner = owner;
     ReceivedTimestamp = receivedTimestamp;
     Script = script;
     Target = target;
 }
Exemplo n.º 11
0
        public static User Create(string token)
        {
            var result = new User
            {
                RegisteredTimestamp = DateTime.UtcNow,
                Token = token
            };

            return result;
        }
        public static Device[] GetDevicesForUser(this IRoomieDatabaseContext database, User user)
        {
            var networks = database.Networks.Get(user);
            var devices = networks.SelectMany(database.Devices.Get).ToList();

            devices.Sort(new DeviceSort());

            var result = devices.ToArray();

            return result;
        }
Exemplo n.º 13
0
        public Network[] Get(User user)
        {
            var result = _entries
                .Where(x => x.User.Id == user.Id)
                .Select(x => x.Network)
                .ToArray()
                .Select(x => x.ToRepositoryType())
                .ToArray();

            return result;
        }
Exemplo n.º 14
0
 public Computer(string accessKey, string address, string encryptionKey, int id, DateTime? lastPing, Script lastScript, string name, User owner)
 {
     AccessKey = accessKey;
     Address = address;
     EncryptionKey = encryptionKey;
     Id = id;
     LastPing = lastPing;
     LastScript = lastScript;
     Name = name;
     Owner = owner;
 }
Exemplo n.º 15
0
        public Network Get(User user, string address)
        {
            var result = _networks.Get(user, address);

            if (result == null)
            {
                var guestNetworks = _guests.Get(user);
                result = guestNetworks.FirstOrDefault(x => string.Equals(x, address));
            }

            return result;
        }
Exemplo n.º 16
0
        public static UserSession Create(User user)
        {
            var result = new UserSession()
            {
                CreationTimeStamp = DateTime.UtcNow,
                LastContactTimeStamp = DateTime.UtcNow,
                Token = Guid.NewGuid().ToString(),
                User = user
            };

            return result;
        }
Exemplo n.º 17
0
        public void Add(Network network, User user)
        {
            var entry = new NetworkGuestModel
            {
                Network = _networks.Find(network.Id),
                User = _users.Find(user.Id),
            };

            _entries.Add(entry);

            _save();
        }
Exemplo n.º 18
0
        public static UserModel FromRepositoryType(User model)
        {
            var result = new UserModel
            {
                Alias = model.Alias,
                Email = model.Email,
                Id = model.Id,
                RegisteredTimestamp = model.RegisteredTimestamp,
                Secret = (model.Secret == null) ? null : model.Secret.Format(),
                Token = model.Token
            };

            return result;
        }
Exemplo n.º 19
0
        public static User CreateInternal(string username, string password)
        {
            var token = UserRepositoryExtensions.BuildInternalUserToken(username);
            var secret = BCryptSecret.FromPassword(password);

            var result = new User
            {
                Alias = username,
                RegisteredTimestamp = DateTime.UtcNow,
                Secret = secret,
                Token = token
            };

            return result;
        }
Exemplo n.º 20
0
        public Network(string address, Computer attatchedComputer, IEnumerable<Device> devices, int id, DateTime? lastPing, string name, User owner)
        {
            Address = address;
            AttatchedComputer = attatchedComputer;

            if (devices != null)
            {
                Devices = SortDevices(devices);
            }

            Id = id;
            LastPing = lastPing;
            Name = name;
            Owner = owner;
        }
Exemplo n.º 21
0
        public Computer Get(User user, int id)
        {
            var result = Get(id);

            if (result == null)
            {
                return null;
            }

            if (result.Owner == null)
            {
                throw new Exception("Owner not set");
            }

            if (result.Owner.Id != user.Id)
            {
                result = null;
            }

            return result;
        }
Exemplo n.º 22
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            try
            {
                if (HttpContext.Items[userKey] == null)
                {
                    User = UserUtilities.GetCurrentUser(Database);
                    ViewBag.User = User;
                    HttpContext.Items[userKey] = User;
                }
                else
                {
                    ViewBag.User = HttpContext.Items[userKey];
                }

                ViewBag.UserAuthenticated = (User != null);
            }
            catch (Exception exception)
            {
                if (!(this is ErrorController)
                    && !(this is TestController))
                {
                    throw exception;
                }
            }

            if (HttpContext.Items[requestedControllerKey] == null)
            {
                ViewBag.NavigationItem = filterContext.RouteData.Values["controller"];
                HttpContext.Items[requestedControllerKey] = ViewBag.NavigationItem;
            }
            else
            {
                ViewBag.NavigationItem = HttpContext.Items[requestedControllerKey];
            }

            base.OnActionExecuting(filterContext);
        }
Exemplo n.º 23
0
        public static CleaningResult Clean(this ITaskRepository repository, User user, ListFilter filter = null)
        {
            if (filter == null)
            {
                filter = new ListFilter
                    {
                        SortDirection = SortDirection.Ascending
                    };
            }

            var allTasks = repository.List(user, filter).Items;

            var oldTasks = allTasks.Where(x => x.Received || x.Expired).ToArray();

            foreach (var task in allTasks)
            {
                repository.Remove(task);
            }

            var result = new CleaningResult(filter, allTasks.Length, oldTasks.Length);

            return result;
        }
Exemplo n.º 24
0
        public static Computer Create(string name, User owner, DateTime? lastPing = null)
        {
            var result = new Computer
            {
                Name = name,
                LastPing = lastPing,
                Owner = owner
            };

            return result;
        }
Exemplo n.º 25
0
        public Computer Get(User user, string name)
        {
            var model = _computers
                .Where(x => x.Owner.Id == user.Id)
                .Where(x => x.Name == name)
                .FirstOrDefault();

            if (model == null)
            {
                return null;
            }

            return model.ToRepositoryType();
        }
Exemplo n.º 26
0
        public static Network Create(string address, User owner, string name, DateTime? lastPing = null, Computer attachedComputer = null, IEnumerable<Device> devices = null)
        {
            var result = new Network
            {
                Address = address,
                AttatchedComputer = attachedComputer,
                Devices = (devices == null) ? null : devices.ToArray(),
                LastPing = lastPing,
                Name = name,
                Owner = owner
            };

            return result;
        }
Exemplo n.º 27
0
        private static IEnumerable<IDeviceState> ProcessSentDevices(Message request, Message response, User user,  Network network, IRoomieDatabaseContext database)
        {
            var sentDevices = request.Payload.Select(x => x.ToDeviceState());
            sentDevices = sentDevices.Select(x => x.NewWithNetwork(network));

            return sentDevices;
        }
Exemplo n.º 28
0
        public static Task Create(User owner, string origin, Computer target, Script script)
        {
            var result = new Task
            {
                Expiration = DateTime.UtcNow.AddSeconds(30),
                Origin = origin,
                Owner = owner,
                Script = script,
                Target = target
            };

            return result;
        }
Exemplo n.º 29
0
        Page<WebHookSession> ISessionRepository.ListWebhookSessions(User user, ListFilter filter)
        {
            var result = _webHookSessions
                .Where(x => x.Computer.Owner.Id == user.Id)
                .Page(filter, x => x.Id)
                .Transform(x => x.ToRepositoryType());

            return result;
        }
Exemplo n.º 30
0
        private static Computer GetSerializableVersion(Computer computer)
        {
            User owner = null;
            if (computer.Owner != null)
            {
                owner = new User(
                    alias: computer.Owner.Alias,
                    email: null,
                    id: computer.Owner.Id,
                    registeredTimestamp: null,
                    secret: null,
                    token: null
                );
            }

            var result = new Computer(
                accessKey: computer.AccessKey,
                address: computer.Address,
                encryptionKey: computer.EncryptionKey,
                id: computer.Id,
                lastPing: computer.LastPing,
                lastScript: computer.LastScript,
                name: computer.Name,
                owner: owner
            );

            return result;
        }