Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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());
            }
        }
Esempio n. 4
0
        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"));
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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());
            }
        }
Esempio n. 7
0
 public bool CanAccess(int accountId, AquariumUser user)
 {
     throw new NotImplementedException();
 }
Esempio n. 8
0
 public AquariumUser UpdateUser(AquariumUser user)
 {
     return(_aquariumDao.UpdateUser(user));
 }