public string IssueUserLoginToken(AquariumUser aquariumUser) { var claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, aquariumUser.Id.ToString()), new Claim(ClaimTypes.Email, aquariumUser.Email), new Claim(ClaimTypes.Role, aquariumUser.Role), new Claim(ClaimTypes.Name, aquariumUser.Username) }; return(GenerateLoginToken(claims)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } AquariumUser = await _context.AquariumUser.FirstOrDefaultAsync(m => m.Id == id); if (AquariumUser == null) { return(NotFound()); } return(Page()); }
public IActionResult UpdateAccount([FromBody] AquariumUser account) { try { int userId = Convert.ToInt16(User.FindFirst(ClaimTypes.NameIdentifier).Value); var data = _aquariumService.GetAccountDetailed(userId, userId); return(new OkObjectResult(data)); } catch (Exception ex) { _logger.LogError($"GET /v1/Account/Current endpoint caught exception: { ex.Message } Details: { ex.ToString() }"); return(NotFound()); } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } AquariumUser = await _context.AquariumUser.FindAsync(id); if (AquariumUser != null) { _context.AquariumUser.Remove(AquariumUser); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public string IssueDeviceLoginToken(AquariumUser aquariumUser, int?aquariumId = null) { if (aquariumId.HasValue) { var aqId = Convert.ToInt16(aquariumId); var aquarium = _aquariumDao.GetAquariumById(aqId); if (aquarium.OwnerId != aquariumUser.Id) { throw new UnauthorizedAccessException("You do not own this aquarium"); } } var claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, aquariumUser.Id.ToString()), new Claim(ClaimTypes.Role, "Device"), new Claim(ClaimTypes.Name, aquariumId.ToString()), }; return(GenerateLoginToken(claims, false)); }
public async System.Threading.Tasks.Task <IActionResult> OnPostAsync(string mail, string password) { var enc = CipherService.Encrypt(password); AquariumUser = await _context.AquariumUser.FirstOrDefaultAsync(m => m.Email == mail && m.Password == enc); string a = CipherService.Encrypt(password); if (AquariumUser != null) { HttpContext.Session.SetString("username", AquariumUser.FirstName + " " + AquariumUser.LastName); HttpContext.Session.SetString("role", AquariumUser.Type == UserTypes.Admin ? UserTypes.Admin.ToString() : AquariumUser.Type == UserTypes.User ? UserTypes.User.ToString() : UserTypes.Guest.ToString()); return(RedirectToPage("Index")); } else { Msg = "Invalid"; return(Page()); } }
public bool CanAccess(int accountId, AquariumUser user) { throw new NotImplementedException(); }
public AquariumUser UpdateUser(AquariumUser user) { return(_aquariumDao.UpdateUser(user)); }