Пример #1
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            Log log = new Log()
            {
                LogDate = DateTime.Now, LogType = "LOGIN"
            };

            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    var user = await _userManager.FindByEmailAsync(model.Email);

                    if (user.Banned)
                    {
                        log.LogValue = "BANNED";
                        _context.Add(log);
                        _context.SaveChanges();
                        await _signInManager.SignOutAsync();

                        return(Redirect("~/"));
                    }

                    log.LogValue = "SUCCESSFUL";
                    _context.Add(log);
                    _context.SaveChanges();
                    _logger.LogInformation(1, _localizer["Label_UserLogged"]);
                    NewLocation();
                    return(Redirect("~/"));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    log.LogValue = "LOCKED";
                    _context.Add(log);
                    _context.SaveChanges();
                    _logger.LogWarning(2, _localizer["Error_BannedUser"]);
                    return(View("Lockout"));
                }

                else
                {
                    log.LogValue = "FAIL";
                    _context.Add(log);
                    _context.SaveChanges();
                    ModelState.AddModelError(string.Empty, _localizer["Error_InvalidLoginAt"]);
                    return(View(model));
                }
            }

            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> NewRequest(int?id, [Bind("AnimalId,AdoptionType,StartDate,EndDate,Details")] AdoptionRequests request)
        {
            AdoptionRequests newRequest = new AdoptionRequests()
            {
                AnimalId     = int.Parse(id.ToString()),
                UserId       = (await _userManager.GetUserAsync(User)).Id,
                AdoptionType = request.AdoptionType,
                ProposalDate = DateTime.Now,
                StartDate    = request.StartDate,
                EndDate      = request.EndDate,
                Details      = request.Details
            };

            _context.AdoptionRequests.Add(newRequest);
            _context.SaveChanges();

            AdoptionLogs newLog = new AdoptionLogs()
            {
                AdoptionRequestId = newRequest.AdoptionRequestId,
                AdoptionStateId   = 1,
                Date    = newRequest.ProposalDate,
                Details = newRequest.Details,
                UserId  = newRequest.UserId
            };

            _context.AdoptionLogs.Add(newLog);
            _context.SaveChanges();

            Animal animal = _context.Animals.FirstOrDefault(a => a.AnimalId == id);
            String preSex;

            if (animal.Gender[0] == 'M')
            {
                preSex = "ao";
            }
            else
            {
                preSex = "à";
            }

            String message = "<p>O seu pedido de adoção " + preSex + " " + animal.Name + " encontra-se para análise. Quando tivermos uma resposta" +
                             " será notificado.<p/> <img class='card - img - top img - fluid' id='pet - image' style='margin:auto; height: 25vw; object-fit: contain; ' src='" + newRequest.Animal.Image + "' alt='Card image cap'>";

            _notificationService.Register(_context, new UserNotification()
            {
                Title            = "Pedido de Adoção",
                Message          = message,
                NotificationDate = DateTime.Now,
                UserId           = newRequest.UserId
            }, _emailSender);
            return(RedirectToAction("MyNotifications", "UserNotifications"));
        }
Пример #3
0
        /// <summary>
        /// Used to register a new notification, can send email
        /// </summary>
        /// <param name="context">AdotAquiDbContext</param>
        /// <param name="notification">Notification Details</param>
        /// <param name="emailService">Email Details (optional)</param>
        public void Register(AdotAquiDbContext context, UserNotification notification, IEmailSender emailService = null)
        {
            context.UserNotification.Add(notification);
            context.SaveChanges();

            if (emailService != null)
            {
                var user = context.Users.Find(notification.UserId);
                emailService.SendEmailAsync(user.Email, "Nova Notificação", "Olá, <p>Gostariamos de informar que tem uma nova notificação!</p><p>Visite <a href='http://eswapp.azurewebsites.net/'>Adotaqui</a> para mais detalhes</p>");
            }
        }
        public IActionResult Edit(int id, [Bind("Date")] AnimalIntervention animalIntervention)
        {
            var intervention = _context.AnimalIntervention.Include(u => u.User).Include(a => a.Animal).Where(i => i.InterventionId == id).FirstOrDefault();

            intervention.Date = animalIntervention.Date;
            _context.SaveChanges();

            var animal = _context.Animals.Find(intervention.Animal.AnimalId);
            var owner  = _context.Users.Find(animal.UserId);

            _notificationService.Register(_context, new UserNotification()
            {
                UserId           = owner.Id,
                Title            = "Intervenção Médica Reagendada",
                Message          = "A intervenção médica do " + intervention.Animal.Name + " foi reagendada para " + intervention.Date + " com o veterinario(a) " + intervention.User.Name,
                NotificationDate = DateTime.Now
            }, _emailSender);

            return(RedirectToAction(nameof(Index)));
        }
        /// <summary>
        /// Used to see the details of a notication
        /// </summary>
        /// <param name="id">Notification ID</param>
        /// <returns>Details View</returns>
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var userNotification = await _context.UserNotification
                                   .FirstOrDefaultAsync(m => m.UserNotificationId == id);

            if (userNotification == null)
            {
                return(NotFound());
            }

            if (!userNotification.HasRead)
            {
                userNotification.HasRead = true;
                _context.SaveChanges();
            }

            return(View(userNotification));
        }