public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (_signInManager.IsSignedIn(User)) { return(LocalRedirect(returnUrl)); } if (ModelState.IsValid) { var user = new AnimuluUser { UserName = Input.Username, Email = Input.Email }; if (await _userManager.FindByEmailAsync(user.Email) != null) { ModelState.AddModelError(string.Empty, "Email is taken."); return(Page()); } if (await _userManager.FindByNameAsync(user.UserName) != null) { ModelState.AddModelError(string.Empty, "Username is taken."); return(Page()); } 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); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page( "ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your account on Animulu", $"Hello {Input.Username}, please confirm your Animulu account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); if (_userManager.Options.SignIn.RequireConfirmedAccount) { return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl })); } else { await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(Page()); }
public async Task CheckPermissionAsync(AnimuluUser user) { if (await _userManager.IsInRoleAsync(user, "Admin")) { Permission = true; } else { Permission = false; } }
private async Task LoadAsync(AnimuluUser user) { var email = await _userManager.GetEmailAsync(user); Email = email; Input = new InputModel { NewEmail = "", }; }
public async Task <Like> GetLikeAsync(Episode episode, AnimuluUser user) { try { var result = await(from l in _context.Likes where l.EpisodeId == episode.Id where l.UserId == user.Id select l).FirstAsync(); return(result); } catch { return(null); } }
public async Task <Review> GetRatingAsync(Show show, AnimuluUser user) { try { var result = await(from r in _context.Reviews where r.ShowId == show.Id where r.UserId == user.Id select r).FirstAsync(); return(result); } catch { return(null); } }
public async Task PostRatingAsync(Show show, int score, AnimuluUser user) { var rate = await GetRatingAsync(show, user); if (rate == null) { await _context.Reviews.AddAsync(new Review { ShowId = show.Id, UserId = user.Id, Value = score }); await _context.SaveChangesAsync(); } else { rate.Value = score; await _context.SaveChangesAsync(); } }
private async Task LoadAsync(AnimuluUser user) { var userName = await _userManager.GetUserNameAsync(user); if (user.ProfilePicExist) { ProfilePic = user.ProfilePicName + ".png"; } else { ProfilePic = "default.png"; } Input = new InputModel { Username = userName, Password = "" }; }
public async Task PostLikeAsync(Episode episode, bool positive, AnimuluUser user) { var like = await GetLikeAsync(episode, user); if (like == null) { await _context.Likes.AddAsync(new Like { EpisodeId = episode.Id, Positive = positive, UserId = user.Id }); await _context.SaveChangesAsync(); } else { if (like.Positive == positive) { _context.Likes.Remove(like); await _context.SaveChangesAsync(); } else { like.Positive = positive; await _context.SaveChangesAsync(); } } }