Esempio n. 1
0
 public UnitOfWork(ApplicationDbContext context)
 {
     _context   = context;
     Gigs       = new GigRepository(_context);
     Attendance = new AttendanceRepository(_context);
     Follow     = new FollowRepository(_context);
     Genre      = new GenreRepository(_context);
 }
Esempio n. 2
0
        private async Task CheckFollowAysnc(string followed, string follower)
        {
            IFollowRepository followRepository = new FollowRepository();
            var follow = await followRepository.FollowedUser(followed, follower);

            var follback = await followRepository.FollowingUser(followed, follower);

            ViewBag.followed = follow != null;
            ViewBag.folback  = follback != null;
        }
 public UnitOfWork(ApplicationDbContext context)
 {
     _context          = context;
     Gigs              = new GigRepository(context);
     Attendances       = new AttendanceRepository(context);
     Follows           = new FollowRepository(context);
     Genres            = new GenreRepository(context);
     Users             = new ApplicationUserRepository(context);
     Notifications     = new NotificationRepository(context);
     UserNotifications = new UserNotificationRepository(context);
 }
Esempio n. 4
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "track/{trackId}/follow")] HttpRequest req, string trackId, TraceWriter log)
        {
            try
            {
                // check postId and trackId provided
                if (!Tools.IsValidGuid(trackId))
                {
                    return(new UnauthorizedResult());
                }

                string authToken = req.Headers["Authorization"];

                if (authToken == null)
                {
                    return(new UnauthorizedResult());
                }

                // validate authKey
                AuthClaim authClaim = AuthRepository.ValidateAuthClaim(authToken);
                if (authClaim == null)
                {
                    return(new UnauthorizedResult());
                }

                // get the track
                TrackAuth track = await TrackRepository.GetTrack(trackId);

                if (track == null || (track.is_private && track.PartitionKey != authClaim.user_id))
                {
                    return(new UnauthorizedResult());
                }

                // trackFollow body
                string         requestBody = new StreamReader(req.Body).ReadToEnd();
                TrackFollowDTO dto         = JsonConvert.DeserializeObject <TrackFollowDTO>(requestBody);

                // insert or update the follow
                TrackFollow trackFollow = new TrackFollow();
                trackFollow.feed_follow_type          = dto.feed?.ToLower() == "all" || dto.feed?.ToLower() == "none" ? dto.feed.ToLower() : null;
                trackFollow.notifications_follow_type = dto.notifications?.ToLower() == "all" || dto.notifications?.ToLower() == "none" ? dto.notifications.ToLower() : null;
                trackFollow.criteria = dto.criteria;
                trackFollow.user_id  = authClaim.user_id;
                trackFollow.track_id = track.RowKey;

                FollowRepository.InsertOrReplaceTrackFollow(trackFollow);

                return(new OkResult());
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return(new UnauthorizedResult());
            }
        }
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "track/{trackId}/follow")] HttpRequest req, string trackId, TraceWriter log)
        {
            try
            {
                // check postId and trackId provided
                if (!Tools.IsValidGuid(trackId))
                {
                    return(new UnauthorizedResult());
                }

                string authToken = req.Headers["Authorization"];

                if (authToken == null)
                {
                    return(new UnauthorizedResult());
                }

                // validate authKey
                AuthClaim authClaim = AuthRepository.ValidateAuthClaim(authToken);
                if (authClaim == null)
                {
                    return(new UnauthorizedResult());
                }

                // get the track
                TrackAuth track = await TrackRepository.GetTrack(trackId);

                if (track == null || track.is_private)
                {
                    return(new UnauthorizedResult());
                }

                // insert or update the follow
                var result = await FollowRepository.DeleteTrackFollow(authClaim.user_id, track.RowKey);

                if (!result)
                {
                    return(new BadRequestResult());
                }

                return(new OkResult());
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return(new UnauthorizedResult());
            }
        }
Esempio n. 6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            ConfigureConsul(services);

            var secret = "eBCatxoffIIq6ESdrDZ8LKI3zpxhYkYM";
            var key    = Encoding.ASCII.GetBytes(secret);

            services.AddAuthentication(option =>
            {
                option.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                option.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.SaveToken                 = true;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuerSigningKey = true,
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });

            services.AddAuthorization();

            services.AddMessagePublishing("FollowService", builder =>
            {
                builder.WithHandler <ForgetUserMessageHandler>("ForgetUserMessage");
            });

            var config = new ServerConfig();

            Configuration.Bind(config);

            var followContext = new FollowContext(config.MongoDB);
            var repo          = new FollowRepository(followContext);

            services.AddSingleton <IFollowRepository>(repo);

            services.AddScoped <IFollowService, Services.FollowService>();
        }
Esempio n. 7
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "tracks")] HttpRequest req, TraceWriter log)
        {
            try
            {
                string authToken = req.Headers["Authorization"];

                // validate authKey
                AuthClaim authClaim = AuthRepository.ValidateAuthClaim(authToken);
                if (authClaim == null)
                {
                    return(new UnauthorizedResult());
                }

                List <TrackDTO> tracks = await FollowRepository.GetUserFollows(authClaim.user_id);

                return(new OkObjectResult(new { count = tracks.Count, data = tracks }));
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return(new UnauthorizedResult());
            }
        }
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var track = new TrackAuth(user.Id, Guid.NewGuid().ToString())
            {
                description = Input.Description,
                is_private  = Input.IsPrivate,
                name        = Input.Name,
                tags        = string.IsNullOrWhiteSpace(Input.Tags) ? null : string.Join(",", Tools.ValidateTags(Input.Tags.Split(',').ToList()))
            };

            // generate small thumb
            if (Input.UploadTrackImage != null)
            {
                using (MemoryStream uploadStream = new MemoryStream())
                {
                    await Input.UploadTrackImage.CopyToAsync(uploadStream);

                    byte[] data = uploadStream.ToArray();

                    using (MemoryStream input = new MemoryStream(data))
                    {
                        using (MemoryStream output = new MemoryStream())
                        {
                            Images.CropSquare(150, input, output);

                            await BlobRepository.UploadFileAsync(BlobRepository.TracksContainer, output.ToArray(), track.RowKey + "/thumb");
                        }
                    }

                    using (MemoryStream input = new MemoryStream(data))
                    {
                        using (MemoryStream output = new MemoryStream())
                        {
                            Images.CropSquare(32, input, output);

                            await BlobRepository.UploadFileAsync(BlobRepository.TracksContainer, output.ToArray(), track.RowKey + "/thumb_mini");
                        }
                    }

                    track.has_image = true;
                }
            }

            // create track
            TrackAuth createdTrack = await TrackRepository.CreateTrack(track);

            FollowRepository.InsertOrReplaceTrackFollow(new TrackFollow()
            {
                track_id                  = createdTrack.RowKey,
                user_id                   = user.Id,
                feed_follow_type          = "none",
                notifications_follow_type = "none"
            });

            _logger.LogInformation($"Track with ID '{createdTrack.RowKey}' has been created by '{user.Id}'.");
            return(RedirectToPage("./Index"));
        }
 public FollowController()
 {
     db        = new FollowRepository(new SocialNetworkContext());
     dbProfile = new ProfileRepository(new SocialNetworkContext());
 }
Esempio n. 10
0
        public static async void Run([QueueTrigger("process-new-post-add-to-cosmos", Connection = "QUEUESTORAGE_CONNECTION")] CloudQueueMessage myQueueItem, TraceWriter log)
        {
            Post post = JsonConvert.DeserializeObject <Post>(myQueueItem.AsString);

            List <string> tags = !string.IsNullOrEmpty(post.tags) ? post.tags.Split(',').ToList() : new List <string>();

            // get subscribers
            List <TrackFollow> followers = await FollowRepository.GetTrackFollows(post.PartitionKey, Enums.FollowMode.Feed);

            List <string> followersToFeed = new List <string>();

            // determine who gets feed
            foreach (TrackFollow follower in followers)
            {
                foreach (TagCriteria criterion in follower.criteria.Where(c => c.feed))
                {
                    if (ContainsAllItems(tags, criterion.tags))
                    {
                        followersToFeed.Add(follower.user_id);
                        break;
                    }
                }
            }

            IEnumerable <List <string> > splitFollowers = splitList(followersToFeed, 1000);
            int i = 1;

            if (splitFollowers.Count() == 0)
            {
                PostCosmos postCosmos = new PostCosmos()
                {
                    id              = Guid.NewGuid().ToString(),
                    post_id         = post.RowKey,
                    track_id        = post.PartitionKey,
                    date_created    = post.date_created,
                    track_name      = post.track_name,
                    summary         = post.summary,
                    tags            = tags,
                    has_image       = post.has_image,
                    title           = post.title,
                    type            = post.type,
                    url             = post.url,
                    subscriber_list = new List <string>(),
                    is_root_post    = true
                };

                await PostRepository.InsertPostToCosmos(postCosmos);

                log.Info($"Added post to Cosmos: {post.RowKey}");
            }
            else
            {
                foreach (List <string> list in splitFollowers)
                {
                    PostCosmos postCosmos = new PostCosmos()
                    {
                        id              = Guid.NewGuid().ToString(),
                        post_id         = post.RowKey,
                        track_id        = post.PartitionKey,
                        date_created    = post.date_created,
                        track_name      = post.track_name,
                        summary         = post.summary,
                        tags            = tags,
                        has_image       = post.has_image,
                        title           = post.title,
                        type            = post.type,
                        url             = post.url,
                        subscriber_list = list,
                        is_root_post    = i == 1 ? true : false
                    };

                    i++;
                    await PostRepository.InsertPostToCosmos(postCosmos);

                    log.Info($"Added post to Cosmos: {post.RowKey}");
                }
            }
        }
Esempio n. 11
0
 public FollowBDC()
 {
     this._followRepo = new FollowRepository();
 }