public async Task <IActionResult> OnGetAsync() { HopeLineUser CurrentUser = await _userManager.GetUserAsync(User); if (CurrentUser != null) { if (CurrentUser.AccountType == DataAccess.Entities.Account.User || CurrentUser.AccountType == DataAccess.Entities.Account.Guest) { isUser = true; } else { isUser = false; } } else { isUser = true; } Communities = _commonResource.GetCommunities().Select(c => new CommunityViewModel { Id = c.Id, Name = c.Name, Description = c.Description, URL = c.URL, ImageURL = c.ImageURL }).ToList(); return(Page()); }
public async Task <IActionResult> OnGetAsync() { HopeLineUser CurrentUser = await _userManager.GetUserAsync(User); if (CurrentUser != null) { if (CurrentUser.AccountType == DataAccess.Entities.Account.User || CurrentUser.AccountType == DataAccess.Entities.Account.Guest) { isUser = true; } else { isUser = false; } } else { isUser = true; } Topics = _commonResource.GetTopics().Select(t => new TopicViewModel { Id = t.Id, Name = t.Name }).ToList(); return(Page()); }
/// <summary> /// create claims for user /// </summary> /// <param name="user"></param> /// <returns></returns> private List <Claim> CreateClaims(HopeLineUser user) { var claims = new List <Claim> { new Claim(JwtRegisteredClaimNames.Sub, user.Email), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(ClaimTypes.NameIdentifier, user.Id) }; return(claims); }
public async Task <IActionResult> OnGetAsync() { HopeLineUser CurrentUser = await _userManager.GetUserAsync(User); if (CurrentUser != null) { if (CurrentUser.AccountType == DataAccess.Entities.Account.User || CurrentUser.AccountType == DataAccess.Entities.Account.Guest) { isUser = true; } else { isUser = false; } } else { isUser = true; } Resources = _commonResource.GetResources().Select(r => new ResourcesViewModel { Id = r.Id, Name = r.Name, Description = r.Description, URL = r.URL, ImageURL = r.ImageURL }).ToList(); foreach (var i in Resources) { if (i.Id > 99 && i.Id < 200) { DepressionRes.Add(i); } else if (i.Id > 199 && i.Id < 300) { AnxietyRes.Add(i); } else if (i.Id > 299 && i.Id < 400) { BullyingRes.Add(i); } else if (i.Id > 399 && i.Id < 500) { SuicideRes.Add(i); } } return(Page()); }
private async Task LoadSharedKeyAndQrCodeUriAsync(HopeLineUser 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); }
/// <summary> /// generate bearer token for auth controller /// </summary> /// <param name="username"></param> /// <param name="user"></param> /// <returns></returns> public object GenerateToken(string username, HopeLineUser user) { var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("SomeSecretofGroup")); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var expires = DateTime.Now.AddDays(Convert.ToDouble((30))); var claims = this.CreateClaims(user); // TODO : string const must be inside appsettings var token = new JwtSecurityToken( APIConstant.URL, APIConstant.URL, claims, expires: expires, signingCredentials: creds ); return(new JwtSecurityTokenHandler().WriteToken(token)); }
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 HopeLineUser { 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> OnGetAsync() { HopeLineUser CurrentUser = await _userManager.GetUserAsync(User); if (CurrentUser != null) { if (CurrentUser.AccountType == DataAccess.Entities.Account.Admin || CurrentUser.AccountType == DataAccess.Entities.Account.Mentor) { isUser = true; } else { isUser = false; } } else { isUser = true; } return(Page()); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new HopeLineUser { 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 c = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = c }, 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()); }