예제 #1
0
        public TwitchUser GetTwitchUserFromSharedUser(SharedUser Followeruser, SharedUser StreamerUser)
        {
            var result = new TwitchUser()
            {
                ChatTime             = (uint)Followeruser.ChatTime,
                CompoundScore        = Followeruser.UserScore,
                DisplayName          = Followeruser.DisplayName,
                FirstTimeSeen        = Followeruser.FirstTimeSeen.GetValueOrDefault(),
                LastSeen             = Followeruser.LastSeen.GetValueOrDefault(),
                IsTurbo              = Followeruser.IsTurbo == 1 ? true:false,
                TotalChatMessages    = (uint)Followeruser.TotalChatMessages,
                ReferringStreamer    = Followeruser.ReferringStreamer,
                TotalTimesSeen       = (uint)Followeruser.TotalTimesSeen,
                TotalWhisperMessages = (uint)Followeruser.TotalWhisperMessages,
                UserId   = Followeruser.UserId,
                UserName = Followeruser.UserName,
                UserType = (Enums.UserType)Followeruser.UserType
            };
            var followdata = data.GetFollowsForFollowerUserId(Followeruser.Id, StreamerUser.Id);

            foreach (var item in followdata)
            {
                result.FollowDate.Add(item.FollowDate);
            }
            return(result);
        }
        public void Put(Guid id, [FromBody] SharedUser value)
        {
            var tempUser = model.Users.SingleOrDefault(x => x.PK_UserID == id);

            if (value.DateOfBirth != DateTime.MinValue)
            {
                tempUser.DateOfBirth = value.DateOfBirth;
            }
            if (!String.IsNullOrEmpty(value.FirstName))
            {
                tempUser.FirstName = value.FirstName;
            }
            if (!String.IsNullOrEmpty(value.LastName))
            {
                tempUser.LastName = value.LastName;
            }
            if (!String.IsNullOrEmpty(value.Password))
            {
                tempUser.Password = value.Password;
            }
            if (!String.IsNullOrEmpty(value.UserName))
            {
                tempUser.UserName = value.UserName;
            }

            model.SaveChanges();
        }
예제 #3
0
 private async Task <bool> IsSharedUser(Guid notificationId)
 {
     return
         (await
          SharedUser.AnyAsync(
              u => u.NotificationId == notificationId && u.UserId == UserContext.UserId.ToString()));
 }
        public async Task <IActionResult> ShareList(SharedUser model)
        {
            var thisUser = await _userManager.FindByNameAsync(User.Identity.Name);

            var sharedUser = await _userManager.FindByNameAsync(model.SharedUserEmail);

            if (sharedUser == null)
            {
                Response.StatusCode = 404;
                return(RedirectToAction("HttpsStatusCodeHandler", "Error", new { statusCode = 123 }));
            }

            sharedUser.SharedListId   = thisUser.ListID;
            sharedUser.RequestToShare = true;

            var result = await _userManager.UpdateAsync(sharedUser);

            if (result.Succeeded)
            {
                return(RedirectToAction("SharingSuccess", new { sharedUser.Email }));
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError("", error.Description);
            }

            return(View(model));
        }
예제 #5
0
 public void UserDelete(SharedUser user)
 {
     lock (m_userLock)
     {
         string sql = DeleteUserSQL;
         m_context.Database.ExecuteSqlCommand(sql, new SQLiteParameter[] { new SQLiteParameter(":id", user.Id) });
     }
 }
예제 #6
0
 public SharedFollow SaveFollow(SharedUser follower, SharedUser streamer, DateTime FollowDate)
 {
     return(data.SaveFollow(new SharedFollow()
     {
         FollowDate = FollowDate,
         FromUserId = follower.Id,
         ToUserId = streamer.Id,
     }));
 }
예제 #7
0
        public async Task AddSharedUserChecksAuthorization()
        {
            var shared = new SharedUser(notification.Id, sharedUser.Id, DateTimeOffset.Now);

            await repository.AddSharedUser(shared);

            A.CallTo(() => authorization.EnsureAccessIsOwnerAsync(shared.NotificationId)).MustHaveHappened();

            await context.SaveChangesAsync();
        }
예제 #8
0
        public async Task HandleAsync(NotificationSharedUserAddedEvent @event)
        {
            var sharedUser = new SharedUser(
                @event.NotificationId,
                @event.UserId,
                SystemTime.UtcNow);

            await repository.AddSharedUser(sharedUser);

            await context.SaveChangesAsync();
        }
예제 #9
0
        private async void GetData()
        {
            // Get the User
            string     tempUserId = (string)Windows.Storage.ApplicationData.Current.LocalSettings.Values["CurrentUser"];
            HttpClient client     = new HttpClient();
            string     temp       = await client.GetStringAsync(new Uri("http://localhost:51070/api/User/" + tempUserId));

            SharedUser user = JsonConvert.DeserializeObject <SharedUser>(temp);

            PK_UserID = user.PK_UserID;
            UserName  = user.UserName;
            Firstname = user.FirstName;
            Lastname  = user.LastName;
            Birthday  = user.DateOfBirth;
            Type      = user.Type;


            if (user.Type == "Entrepreneur")
            {
                Visible = Visibility.Visible;

                // Get the Company
                temp = await client.GetStringAsync(new Uri("http://localhost:51070/api/Company/" + user.FK_CompanyID));

                SharedCompany company = JsonConvert.DeserializeObject <SharedCompany>(temp);
                FK_CompanyID = user.FK_CompanyID;
                CompanyName  = company.Name;
                Street       = company.Street;
                Postalcode   = company.ZipCode;
                City         = company.City;
                Facebook     = company.Facebook;
                Image        = company.Image;
                Description  = company.Description;

                // Get the Events
                temp = await client.GetStringAsync(new Uri("http://localhost:51070/api/Event?companyID=" + user.FK_CompanyID));

                Events = new ObservableCollection <SharedEvent>(JsonConvert.DeserializeObject <List <SharedEvent> >(temp));

                // Get the Promotions
                temp = await client.GetStringAsync(new Uri("http://localhost:51070/api/Promotion?companyID=" + user.FK_CompanyID));

                Promotions = new ObservableCollection <SharedPromotion>(JsonConvert.DeserializeObject <List <SharedPromotion> >(temp));
            }
            else
            {
                Visible = Visibility.Collapsed;
            }
        }
예제 #10
0
        public SharedUser GetUserById(int UserId)
        {
            if (UserId == 0)
            {
                return(null);
            }
            SharedUser user = null;

            lock (m_userLock)
            {
                string sql = "select " + SelectUserSQLFields + " from TwitchUser where Id=:id;";
                user = m_context.Database.SqlQuery <SharedUser>(sql, new SQLiteParameter[] { new SQLiteParameter(":id", UserId) }).FirstOrDefault();
            }
            return(user);
        }
        public async Task SharedUserNotificationAccess()
        {
            // Setup.
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);
            var aspnetInternalUser = UserFactory.Create(Guid.NewGuid(), "Internal", "Internal Last", "12345",
                                                        "*****@*****.**");
            var aspnetSharedUser = UserFactory.Create(Guid.NewGuid(), "External", "Shared", "12345",
                                                      "*****@*****.**");
            var localArea = new LocalArea(Guid.NewGuid(), "Test Area", (int)UKCompetentAuthority.England);

            context.NotificationApplications.Add(notification);
            context.Users.Add(aspnetInternalUser);
            context.Users.Add(aspnetSharedUser);
            context.LocalAreas.Add(localArea);
            await context.SaveChangesAsync();

            var internalUser = new InternalUser(aspnetInternalUser.Id, "test", UKCompetentAuthority.England,
                                                localArea.Id);
            var sharedUser = new SharedUser(notification.Id, aspnetSharedUser.Id, DateTimeOffset.Now);

            context.InternalUsers.Add(internalUser);
            context.SharedUser.Add(sharedUser);
            await context.SaveChangesAsync();

            // Set the shared user to be the user context.
            A.CallTo(() => userContext.UserId).Returns(Guid.Parse(sharedUser.UserId));

            var authorization = new NotificationApplicationAuthorization(context, userContext);

            // Assert.
            // There's no assertion for 'does not throw exception' so just executing it as normal.
            await authorization.EnsureAccessAsync(notification.Id);

            // Clear data.
            context.DeleteOnCommit(internalUser);
            context.DeleteOnCommit(sharedUser);
            await context.SaveChangesAsync();

            context.Entry(aspnetInternalUser).State = EntityState.Deleted;
            context.Entry(aspnetSharedUser).State   = EntityState.Deleted;
            context.Entry(localArea).State          = EntityState.Deleted;
            await context.SaveChangesAsync();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
        public async Task RandomExternalUserAccessThrowsException()
        {
            // Setup.
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);
            var aspnetInternalUser = UserFactory.Create(Guid.NewGuid(), "Internal", "Internal Last", "12345",
                                                        "*****@*****.**");
            var aspnetSharedUser = UserFactory.Create(Guid.NewGuid(), "External", "Shared", "12345",
                                                      "*****@*****.**");
            var localArea = new LocalArea(Guid.NewGuid(), "Test Area", (int)UKCompetentAuthority.England);

            context.NotificationApplications.Add(notification);
            context.Users.Add(aspnetInternalUser);
            context.Users.Add(aspnetSharedUser);
            context.LocalAreas.Add(localArea);
            await context.SaveChangesAsync();

            var internalUser = new InternalUser(aspnetInternalUser.Id, "test", UKCompetentAuthority.England,
                                                localArea.Id);
            //Shared user is different to the user context.
            var sharedUser = new SharedUser(notification.Id, aspnetSharedUser.Id, DateTimeOffset.Now);

            context.SharedUser.Add(sharedUser);
            await context.SaveChangesAsync();

            context.InternalUsers.Add(internalUser);
            await context.SaveChangesAsync();

            var authorization = new NotificationApplicationAuthorization(context, userContext);

            // Assert.
            await Assert.ThrowsAsync <SecurityException>(() => authorization.EnsureAccessAsync(notification.Id));

            // Clear data.
            context.DeleteOnCommit(internalUser);
            context.DeleteOnCommit(sharedUser);
            await context.SaveChangesAsync();

            context.Entry(aspnetInternalUser).State = EntityState.Deleted;
            context.Entry(aspnetSharedUser).State   = EntityState.Deleted;
            context.Entry(localArea).State          = EntityState.Deleted;
            await context.SaveChangesAsync();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
예제 #13
0
        private async void Update()
        {
            SharedEvent tempEvent = new SharedEvent()
            {
                Name        = Name,
                Date        = Date.DateTime,
                Street      = Street,
                ZipCode     = ZipCode,
                City        = City,
                Image       = Image,
                Description = Description
            };

            if (PK_EventID == Guid.Empty)
            {
                tempEvent.PK_EventID = Guid.NewGuid();

                string     tempUserId = (string)Windows.Storage.ApplicationData.Current.LocalSettings.Values["CurrentUser"];
                HttpClient client     = new HttpClient();
                string     temp       = await client.GetStringAsync(new Uri("http://localhost:51070/api/User/" + tempUserId));

                SharedUser user = JsonConvert.DeserializeObject <SharedUser>(temp);
                tempEvent.FK_CompanyID = user.FK_CompanyID;

                var myContent   = JsonConvert.SerializeObject(tempEvent);
                var buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
                var byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var newEvent = await client.PostAsync(new Uri("http://localhost:51070/api/Event/"), byteContent);
            }
            else
            {
                HttpClient client      = new HttpClient();
                var        myContent   = JsonConvert.SerializeObject(tempEvent);
                var        buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
                var        byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var result = await client.PutAsync(new Uri("http://localhost:51070/api/Event/" + PK_EventID), byteContent);
            }

            NavigationService.Navigate(typeof(Views.UserAdministrationPage));
        }
예제 #14
0
        public void Post([FromBody] SharedUser value)
        {
            var user = new User()
            {
                DateOfBirth = value.DateOfBirth,
                FirstName   = value.FirstName,
                LastName    = value.LastName,
                Password    = value.Password,
                PK_UserID   = value.PK_UserID,
                UserName    = value.UserName,
                Type        = value.Type
            };

            if (value.FK_CompanyID != Guid.Empty)
            {
                user.FK_CompanyID = value.FK_CompanyID;
            }
            model.Users.Add(user);
            model.SaveChanges();
        }
예제 #15
0
        public SharedUser GetUserByUserName(string UserName)
        {
            if (string.IsNullOrEmpty(UserName) || string.IsNullOrWhiteSpace(UserName))
            {
                return(null);
            }

            SharedUser user = null;

            lock (m_userLock)
            {
                try
                {
                    string sql = "select " + SelectUserSQLFields + " from TwitchUser where UserName=:username;";
                    user = m_context.Database.SqlQuery <SharedUser>(sql, new SQLiteParameter[] { new SQLiteParameter(":username", UserName) }).FirstOrDefault();
                }
                catch
                {
                    return(null);
                }
            }
            return(user);
        }
예제 #16
0
        public SharedUser UserSave(SharedUser user)
        {
            SQLiteParameter[] sQLiteParameters = new SQLiteParameter[]
            {
                new SQLiteParameter(":userid", user.UserId),
                new SQLiteParameter(":username", user.UserName),
                new SQLiteParameter(":displayname", user.DisplayName),
                new SQLiteParameter(":usertype", user.UserType),
                new SQLiteParameter(":isturbo", user.IsTurbo),
                new SQLiteParameter(":firsttimeseen", user.FirstTimeSeen),
                new SQLiteParameter(":lastseen", user.LastSeen),
                new SQLiteParameter(":chattime", user.ChatTime),
                new SQLiteParameter(":referringstreamer", user.ReferringStreamer),
                new SQLiteParameter(":totaltimesseen", user.TotalTimesSeen),
                new SQLiteParameter(":totalchatmessages", user.TotalChatMessages),
                new SQLiteParameter(":totalwhispermessages", user.TotalWhisperMessages),
                new SQLiteParameter(":userscore", user.UserScore),
                new SQLiteParameter(":processstatus", user.ProcessStatus),
                new SQLiteParameter(":id", user.Id)
            };
            if (user.Id != 0)
            {
                // Update
                SharedUser result = user;
                try
                {
                    lock (m_userLock)
                    {
                        string sql = UpdateUserSQL + " id=:id";
                        m_context.Database.ExecuteSqlCommand(sql, sQLiteParameters);
                    }

                    result = GetUserByUserName(user.UserName);
                }
                catch
                {
                    return(user);
                }

                return(result);
            }
            else
            {
                // Insert
                SharedUser result = user;
                lock (m_userLock)
                {
                    try
                    {
                        string sql = InsertUserSQL;
                        m_context.Database.ExecuteSqlCommand(sql, sQLiteParameters);

                        int resultid = m_context.Database.SqlQuery <int>(GetLastInsertedUserSQL, new SQLiteParameter[] { }).FirstOrDefault();
                        result = GetUserById(resultid);
                    }
                    catch
                    { }
                }
                return(result);
            }
        }
예제 #17
0
        public async Task AddSharedUser(SharedUser sharedUser)
        {
            await authorization.EnsureAccessIsOwnerAsync(sharedUser.NotificationId);

            context.SharedUser.Add(sharedUser);
        }
예제 #18
0
 public SharedUser SaveUser(SharedUser user)
 {
     return(data.UserSave(user));
 }
예제 #19
0
        private async void Update()
        {
            var list = new List <bool>();

            list.Add(this.Firstname != null && this.Firstname.Length > 0); //1
            list.Add(this.Lastname != null && this.Lastname.Length > 0);   //2
            list.Add(this.UserName != null && this.UserName.Length > 0);   //3
            list.Add(this.Password == this.PasswordConfirm);               //4
            list.Add(this.Password == this.PasswordConfirm);               //5
            list.Add(this.Birthday != null);                               //6
            if (this.CompanyName != null)
            {
                list.Add(this.CompanyName != null && this.CompanyName?.Length > 0); //7
                list.Add(this.Street != null && this.Street?.Length > 0);           //8
                list.Add(this.Postalcode != null && this.Postalcode?.Length > 0);   //9
                list.Add(this.City != null && this.City?.Length > 0);               //10
                list.Add(this.Facebook != null && this.Facebook.Length > 0);        //11
                list.Add(this.Image != null && this.Image.Length > 0);              //12
                list.Add(this.Description != null && this.Description.Length > 0);  //13
            }
            Formcontrol = list;
            if (Formcontrol.Count > 0)
            {
                FormControl1 = Formcontrol.ElementAt(0) ? green : red; //1
                FormControl2 = Formcontrol.ElementAt(1) ? green : red; //2
                FormControl3 = Formcontrol.ElementAt(2) ? green : red; //3
                FormControl4 = Formcontrol.ElementAt(3) ? green : red; //4
                FormControl5 = Formcontrol.ElementAt(4) ? green : red; //5
                FormControl6 = Formcontrol.ElementAt(5) ? green : red; //6
                if (this.CompanyName != null)
                {
                    FormControl7  = Formcontrol.ElementAt(6) ? green : red;  //7
                    FormControl8  = Formcontrol.ElementAt(7) ? green : red;  //8
                    FormControl9  = Formcontrol.ElementAt(8) ? green : red;  //9
                    FormControl10 = Formcontrol.ElementAt(9) ? green : red;  //10
                    FormControl11 = Formcontrol.ElementAt(10) ? green : red; //11
                    FormControl12 = Formcontrol.ElementAt(11) ? green : red; //12
                    FormControl13 = Formcontrol.ElementAt(12) ? green : red; //13
                }
            }
            if (Formcontrol.All(f => f))
            {
                SharedUser tempUser = new SharedUser()
                {
                    DateOfBirth = Birthday.DateTime,
                    FirstName   = Firstname,
                    LastName    = Lastname,
                    Password    = HashMethods.ComputeMD5(Password),
                    UserName    = UserName
                };
                HttpClient client      = new HttpClient();
                var        myContent   = JsonConvert.SerializeObject(tempUser);
                var        buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
                var        byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var result = await client.PutAsync(new Uri("http://localhost:51070/api/User/" + PK_UserID), byteContent);

                if (Type == "Entrepreneur")
                {
                    SharedCompany tempCompany = new SharedCompany()
                    {
                        City        = City,
                        Description = Description,
                        Facebook    = Facebook,
                        Name        = CompanyName,
                        Street      = Street,
                        ZipCode     = Postalcode,
                        Image       = Image
                    };
                    myContent   = JsonConvert.SerializeObject(tempCompany);
                    buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
                    byteContent = new ByteArrayContent(buffer);
                    byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    result = await client.PutAsync(new Uri("http://localhost:51070/api/Company/" + FK_CompanyID), byteContent);
                }
                FormControl1 = gray;
                FormControl2 = gray;
                FormControl3 = gray;
                FormControl4 = gray;
                FormControl5 = gray;
                FormControl6 = gray;
                if (this.CompanyName != null)
                {
                    FormControl7  = gray;
                    FormControl8  = gray;
                    FormControl9  = gray;
                    FormControl10 = gray;
                    FormControl11 = gray;
                    FormControl12 = gray;
                    FormControl13 = gray;
                }
                NavigationService.Navigate(typeof(Views.MainPage));
            }
        }
예제 #20
0
 public void DeleteUser(SharedUser user)
 {
     data.UserDelete(user);
 }