Exemplo n.º 1
0
        public void SendCommand(string command, string target)
        {
            var unit = _root.FindUnit(target);

            if (unit == null)
            {
                return;
            }

            _commands.AddOrUpdate(target, command, (k, v) => command);

            if (!_mqtt.IsConnected)
            {
                MqttReconnect(null, null);
            }

            //var cmd = String.Format("{{\"command\":\"{0}\", \"target\":\"{1}\"}}", command, target);
            //_mqtt.Publish("command/" + target.Replace("_", "/"), Encoding.ASCII.GetBytes(cmd));

            var cmd = JsonConvert.SerializeObject(new { Command = command, Target = unit.Id });

            //var user = User.Identity.GetUserName();
            var manager = HttpContext.GetOwinContext().GetUserManager <SmartHomeUserManager>();

            SmartHomeUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <SmartHomeUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

            var topic = String.Format("{0}/{1}/{2}", user.UserName, user.DefaultProfileName, unit.ClientId.Replace("_", "/"));

            _mqtt.Publish(topic, Encoding.UTF8.GetBytes(cmd));
        }
Exemplo n.º 2
0
        public HomeController(IHttpContextAccessor httpContextAccessor, UserManager <SmartHomeUser> userManager, IOptions <List <UserProfile> > userOptions)
        {
            var userId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var user   = userManager.FindByIdAsync(userId).GetAwaiter().GetResult();

            if (user != null)
            {
                user.Profiles = (from p in userOptions.Value
                                 from a in user.AvailableProfiles
                                 where p.Name.Equals(a)
                                 select p)
                                .ToList();

                user.Profiles.ForEach(p => p.Content.ForEach(c => c.UpdateParents()));

                _user = user;
            }
        }
Exemplo n.º 3
0
        private async Task SignInAsync(SmartHomeUser user, bool isPersistent)
        {
            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);

            ///Open Question- Hear it create claimIdentity. But we nothing add as such Claims but just User object.
            //public virtual Task<ClaimsIdentity> CreateIdentityAsync(TUser user, string authenticationType);

            var userManager = new SmartHomeUserManager();

            var identity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);

            //var identity = await UserManager1.CreateAsync(user);//, DefaultAuthenticationTypes.ApplicationCookie);

            AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                IsPersistent = isPersistent
            }, identity);
        }