public IActionResult Details(string id) { var profile = _context.Users.Find(id); string userid; CB8_TeamYBD_GroupProject_MVCUser user = new CB8_TeamYBD_GroupProject_MVCUser(); try { userid = User.FindFirst(ClaimTypes.NameIdentifier).Value; user = _context.Users.Find(userid); } catch { userid = ""; } List <Article> articles = _context.Articles.Where(x => x.Author == profile).ToList(); List <SubscriptionListing> listings = _context.SubscriptionListings.Where(x => x.User == profile).ToList(); List <Follow> follows = _context.Follows.Include(x => x.Follower).Where(x => x.User == profile).ToList(); UserViewModel vm = new UserViewModel() { UserId = userid, User = profile, Articles = articles, Listings = listings, Follows = follows }; return(View(vm)); }
public async Task <IActionResult> Read(int Id) { string userId; CB8_TeamYBD_GroupProject_MVCUser user = new CB8_TeamYBD_GroupProject_MVCUser(); try { userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; user = _context.Users.Find(userId); } catch { userId = ""; } Article article = _context.Articles.Include("Author").First(x => x.Id == Id); CB8_TeamYBD_GroupProject_MVCUser author = article.Author; bool paywall = article.Paid; DateTime dateTime = article.PostDateTime; List <ArticleLike> likes = _context.ArticleLikes.Include("User").Where(x => x.Article == article).ToList(); List <Comment> comments = _context.Comments.Include("User").Where(x => x.Article == article).OrderBy(x => x.CommentDateTime).ToList(); List <CommentLike> commentLikes = _context.CommentLikes.Include("User").Include("Comment").Where(x => x.Comment.Article == article).ToList(); List <CommentResponse> commentResponses = _context.CommentResponses.Include("User").Include("Comment").Where(x => x.Comment.Article == article).OrderBy(x => x.ResponseDateTime).ToList(); List <CommentResponseLike> commentResponseLikes = _context.CommentResponseLikes.Include("User").Include(x => x.Response.Comment).Where(x => x.Response.Comment.Article == article).ToList(); if (paywall == false || ( paywall == true && ( user == author || user.Premium == true || (_context.ArticlePurchases.Where(x => x.Article == article && x.User == user).Count() > 0) || (_context.UserSubcriptions.Where(x => x.Subscriber == user && x.Subscription.User == author && x.EndDate.CompareTo(DateTime.Now) > 0).Count() > 0) ) ) ) { ReadViewModel vm = new ReadViewModel() { UserId = userId, Article = article, Author = author, Likes = likes, Comments = comments, ArticlePostDateTime = dateTime, CommentLikes = commentLikes, CommentResponses = commentResponses, CommentResponseLikes = commentResponseLikes }; return(View(vm)); } else { article.Content = "<h5 style='color: white;'>This article is paid. Please login/register and purchase either this article, a subscription to the author, or a premium ReedMie account.</h5>"; ReadViewModel vm = new ReadViewModel() { UserId = userId, Article = article, Author = author, Likes = likes, Comments = comments, ArticlePostDateTime = dateTime, CommentLikes = commentLikes, CommentResponses = commentResponses, CommentResponseLikes = commentResponseLikes }; return(View(vm)); } }
public IActionResult Favorites() { List <CB8_TeamYBD_GroupProject_MVCUser> favorites = new List <CB8_TeamYBD_GroupProject_MVCUser>(); if (User.Identity.IsAuthenticated) { string userid = User.FindFirst(ClaimTypes.NameIdentifier).Value; CB8_TeamYBD_GroupProject_MVCUser user = _context.Users.Find(userid); favorites = _context.Follows.Where(x => x.Follower == user).Select(x => x.User).ToList(); } return(View(favorites)); }
private async Task LoadSharedKeyAndQrCodeUriAsync(CB8_TeamYBD_GroupProject_MVCUser user) { // Load the authenticator key & QR code URI to display on the form var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); if (string.IsNullOrEmpty(unformattedKey)) { await _userManager.ResetAuthenticatorKeyAsync(user); unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); } SharedKey = FormatKey(unformattedKey); var email = await _userManager.GetEmailAsync(user); AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey); }
public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); // Get the information about the user from the external login provider var info = await _signInManager.GetExternalLoginInfoAsync(); if (info == null) { ErrorMessage = "Error loading external login information during confirmation."; return(RedirectToPage("./Login", new { ReturnUrl = returnUrl })); } if (ModelState.IsValid) { var user = new CB8_TeamYBD_GroupProject_MVCUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user); if (result.Succeeded) { result = await _userManager.AddLoginAsync(user, info); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } LoginProvider = info.LoginProvider; ReturnUrl = returnUrl; return(Page()); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new CB8_TeamYBD_GroupProject_MVCUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }