GetUserLikes(LikesParams likesParams) { var users = _context.Users.OrderBy(x => x.UserName).AsQueryable(); var likes = _context.Likes.AsQueryable(); if (likesParams.Predicate == "liked") { likes = likes.Where(x => x.SourceUserId == likesParams.UserId); users = likes.Select(x => x.LikedUser); } if (likesParams.Predicate == "likedBy") { likes = likes.Where(x => x.LikedUserId == likesParams.UserId); users = likes.Select(x => x.SourceUser); } var likedUsers = users .Select(user => new LikeDto { Username = user.UserName, KnownAs = user.KnownAs, Age = user.DateOfBirth.CalculateAge(), PhotoUrl = PhotosHelper.GetMainPhoto(user.Photos), City = user.City, Id = user.Id }); return(await PagedList <LikeDto> .CreateAsync(likedUsers, likesParams.PageNumber, likesParams.PageSize)); }
public async Task <ActionResult <UserDto> > Login(LoginDto loginDto) { var user = await _userManager .Users .Include(x => x.Photos.Where(x => x.IsApproved)) .SingleOrDefaultAsync(x => x.UserName == loginDto.Username.ToLower()); if (user == null) { return(Unauthorized("Invalid username")); } // using var hmac = new HMACSHA512(user.PasswordSalt); // var computedHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(loginDto.Password)); // if (!user.PasswordHash.SequenceEqual(computedHash)) return Unauthorized("Invalid username or password"); var result = await _signInManager .CheckPasswordSignInAsync(user, loginDto.Password, false); if (!result.Succeeded) { return(Unauthorized()); } return(new UserDto { Username = user.UserName, Token = await _tokenService.CreateToken(user), PhotoUrl = PhotosHelper.GetMainPhoto(user.Photos), knownAs = user.KnownAs, Gender = user.Gender }); }
/// <summary> /// The route handler for the request, which retrieves and stores photos. /// </summary> /// <param name="context">The request and response context.</param> public override void ProcessRequest(HttpContext context) { User user = GetUser(context); PhotosHelper photosUtility = new PhotosHelper(); bool hasThemeIdParam = (context.Request["themeId"] != null); bool hasUserIdParam = (context.Request["userId"] != null); bool hasPhotoIdParam = (context.Request["photoId"] != null); bool isFriends = (context.Request["friends"] != null && context.Request["friends"].Equals("true")); int userId = 0, photoId = 0; Theme selectedTheme = ThemesHelper.GetSelectedTheme(context.Request["themeId"]); if (hasPhotoIdParam) { photoId = int.Parse(context.Request["photoId"]); } if (hasUserIdParam) { if (context.Request["userId"].Equals("me")) { if (user != null) { userId = user.id; } } else { userId = int.Parse(context.Request["userId"]); } } // Handle file upload. if (context.Request.Files["image"] != null) { Photo dbPhoto = PhotoHunt.utils.PhotosHelper.UploadPhoto(context, user, selectedTheme); // Now that the photo has been uploaded to the application, write an app activity to // Google for the photo upload using the Google+ API. photosUtility.WriteGooglePlusPhotoAppActivity(user, dbPhoto); SendResponse(context, dbPhoto); return; } // Delete or return a single photo. if (hasPhotoIdParam) { // Retrieve the photo from the id specific to the PhotoHunt photos data. PhotohuntContext db = new PhotohuntContext(); Photo selectedPhoto = db.Photos.First(p => p.id == photoId); // Remove the photo if this is a DELETE request. if (context.Request.RequestType.Equals("DELETE")) { PhotoHunt.utils.PhotosHelper.DeletePhoto(context, user, selectedPhoto); } SendResponse(context, selectedPhoto); return; } // Return a list of photos based on the current request. SendResponse(context, PhotoHunt.utils.PhotosHelper.GetPhotos(hasThemeIdParam, hasUserIdParam, isFriends, userId, selectedTheme)); return; }