Ejemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync(string returnUrl = null)
        {
            ReturnUrl = returnUrl;

            if (Input == null)
            {
                Input = new InputModel();
            }

            if (!string.IsNullOrEmpty(Request.Query?["PinDigit"]))
            {
                Input.PinDigit = Request.Query?["PinDigit"];
            }

            await _eventTrackingService.Create(new Shared.Functional.EventTrackingItem
            {
                Id          = Guid.NewGuid(),
                CreatedDate = DateTime.UtcNow,
                Category    = "LoginWithPinCode",
                Key         = "Start"
            });


            return(Page());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(string returnUrl = null)
        {
            ReturnUrl = returnUrl;

            InputExternalModel Input = new InputExternalModel();

            if (!string.IsNullOrEmpty(Request.Query?["PinDigit"]))
            {
                Input.PinCode = int.Parse(Request.Query?["PinDigit"]);
            }

            if (Input.PinCode > 0)
            {
                var user = await _userManager.Users.Where(u => u.PinDigit == Input.PinDigit).ToListAsync();

                if (user == null || user.Count == 0)
                {
                    return(Redirect($"./Register?PinDigit={Request.Query?["PinDigit"]}"));
                }
            }

            await _eventTrackingService.Create(new Shared.Functional.EventTrackingItem
            {
                Id          = Guid.NewGuid(),
                CreatedDate = DateTime.UtcNow,
                Category    = "Navigation",
                Key         = "login"
            });

            return(Page());
        }
        public async Task <IActionResult> OnGetAsync()
        {
            await _eventTrackingService.Create(new Shared.Functional.EventTrackingItem
            {
                Id          = Guid.NewGuid(),
                CreatedDate = DateTime.UtcNow,
                Category    = "ForgotPassword",
                Key         = "Start"
            });

            return(Page());
        }
        public async Task <ActionResult <ViewApplicationUser> > Get(string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return(BadRequest());
            }

            var user = await _userManager.Users.FirstOrDefaultAsync(u => u.PinDigit == userId || u.Id == userId || u.UserName == userId);

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

            if (Request.Query.Any())
            {
                if (QueryHelpers.ParseQuery(Request.QueryString.Value).TryGetValue("social", out var _social))
                {
                    await _eventTrackingService.Create(User.NameIdentifier(), $"ViewProfileFromSocial#{_social.ToString().ToLower()}", user.Id);
                }
            }

            user.NubmerOfView += 1;
            await _userManager.UpdateAsync(user);

            if (!User.Identity.IsAuthenticated)
            {
                await _eventTrackingService.Create(User.NameIdentifier(), "ViewProfile", user.Id);
            }
            else
            {
                await _eventTrackingService.Create(null, "ViewProfile", user.Id);
            }

            var view = (ViewApplicationUser)user;

            view.NumberOfContacts = (await _functionalUnitOfWork.ContactRepository.GetContacts(user.Id)).Count;
            view.NumberOfAds      = (await _functionalUnitOfWork.AdRepository.GetVisibledUser(user.Id)).Count;

            view.SocialNetworkConnected = await _functionalUnitOfWork
                                          .SocialNetworkRepository
                                          .GetSocialNetworkLinks(user.Id) ?? new List <SocialNetwork>();

            view.CustomLinks = await _functionalUnitOfWork
                               .CustomLinkRepository
                               .GetCustomLinkLinks(user.Id) ?? new List <CustomLink>();

            view.PhotoUrl = string.IsNullOrWhiteSpace(user.PhotoUrl) ? user.GravatarUrl() : user.PhotoUrl;

            return(Ok(view));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> OnGetAsync(string userId, string code, string returnUrl)
        {
            if (userId == null || code == null)
            {
                return(RedirectToPage("/Index"));
            }

            ReturnUrl = returnUrl;

            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{userId}'."));
            }

            code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
            var result = await _userManager.ConfirmEmailAsync(user, code);

            Success = result.Succeeded;

            if (Success)
            {
                await _eventTrackingService.Create(new Shared.Functional.EventTrackingItem
                {
                    Id          = Guid.NewGuid(),
                    CreatedDate = DateTime.UtcNow,
                    Category    = "profile",
                    Key         = "confirmEmail",
                    UserId      = user.Id
                });
            }

            return(Page());
        }
        private async Task NotifyAd(Shared.Functional.AdModel ad, string eventType, EmailTemplateEnum emailTemplate, NotificationTypeEnum notificationType, string callbackUrl)
        {
            _logger.LogInformation($"notify user {ad.OwnerId} for ad {ad.Id}");

            await _eventTrackingService.Create(ad.OwnerId, "Ad", eventType);

            var notification = new Notification
            {
                Id                = Guid.NewGuid(),
                CreatedDate       = DateTime.Now,
                CssClass          = "advalidate",
                ImageUrl          = "alert-advalidate",
                MessageTitle      = eventType,
                NotificationIcon  = "alert-advalidate",
                NotificationType  = notificationType.GetName(),
                NotificationUrl   = callbackUrl,
                UserId            = ad.OwnerId,
                DisplayMax        = 1,
                IsDisplayOnlyOnce = true
            };

            await _notificationService.Create(notification);

            await SendEmailTemplate(ad, emailTemplate, callbackUrl);
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> AddEventTrackingItem(EventTrackingItem EventTrackingItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _EventTrackingService.Create(EventTrackingItem);

            return(Ok());
        }
        public async Task <ActionResult <ApplicationUser> > GetUserProfileNoDetail(string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                userId = User.NameIdentifier();
            }

            var user = await _userManager
                       .FindByIdAsync(userId);


            user.NubmerOfView += 1;
            await _userManager.UpdateAsync(user);

            if (!User.Identity.IsAuthenticated)
            {
                await _eventTrackingService.Create(User.NameIdentifier(), "ViewProfile", userId);
            }
            else
            {
                await _eventTrackingService.Create(null, "ViewProfile", userId);
            }

            var view = (ViewApplicationUser)user;

            view.NumberOfContacts = (await _functionalUnitOfWork.ContactRepository.GetContacts(userId)).Count;
            view.NumberOfAds      = (await _functionalUnitOfWork.AdRepository.GetVisibledUser(userId)).Count;

            view.SocialNetworkConnected = await _functionalUnitOfWork
                                          .SocialNetworkRepository
                                          .GetSocialNetworkLinks(user.Id) ?? new List <SocialNetwork>();

            view.CustomLinks = await _functionalUnitOfWork
                               .CustomLinkRepository
                               .GetCustomLinkLinks(user.Id) ?? new List <CustomLink>();

            view.PhotoUrl = string.IsNullOrWhiteSpace(user.PhotoUrl) ? user.GravatarUrl() : user.PhotoUrl;

            return(Ok(view));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> OnGet(string returnUrl = null)
        {
            await _eventTrackingService.Create(new Shared.Functional.EventTrackingItem
            {
                Id          = Guid.NewGuid(),
                CreatedDate = DateTime.UtcNow,
                Category    = "Logout",
                Key         = "Get",
                UserId      = User.NameIdentifier()
            });

            await _signInManager.SignOutAsync();

            _logger.LogInformation("User logged out.");

            if (returnUrl != null)
            {
                return(LocalRedirect(returnUrl));
            }

            return(RedirectToPage());
        }
        public async Task OnGetAsync(string returnUrl = null)
        {
            ReturnUrl = returnUrl;

            if (Input == null)
            {
                Input = new InputModel();
            }

            if (Request?.Query?.ContainsKey("PinCode") == true)
            {
                Input.PinCode = int.Parse(Request.Query["PinCode"]);
            }

            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();

            await _eventTrackingService.Create(new Shared.Functional.EventTrackingItem
            {
                Id          = Guid.NewGuid(),
                CreatedDate = DateTime.UtcNow,
                Category    = "Register",
                Key         = "Start"
            });
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> OnGetAsync(string code = null)
        {
            if (code == null)
            {
                return(BadRequest("A code must be supplied for password reset."));
            }
            else
            {
                Input = new InputModel
                {
                    Code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code))
                };

                await _eventTrackingService.Create(new Shared.Functional.EventTrackingItem
                {
                    Id          = Guid.NewGuid(),
                    CreatedDate = DateTime.UtcNow,
                    Category    = "ResetPassword",
                    Key         = "Get"
                });

                return(Page());
            }
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> OnPostAsync(string provider, string returnUrl = null)
        {
            // Request a redirect to the external login provider.
            await _eventTrackingService.Create(new Shared.Functional.EventTrackingItem
            {
                Id          = Guid.NewGuid(),
                CreatedDate = DateTime.UtcNow,
                Category    = "externalLogin",
                Key         = "request"
            });

            var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl });
            var properties  = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            return(new ChallengeResult(provider, properties));
        }
Ejemplo n.º 13
0
        public async Task <ActionResult <AdViewModel> > Get(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest());
            }

            if (Request.Query.Any())
            {
                if (QueryHelpers.ParseQuery(Request.QueryString.Value).TryGetValue("social", out var _social))
                {
                    await _eventTrackingService.Create(User.NameIdentifier(), $"ViewAdFromSocial#{_social.ToString().ToLower()}", id.ToString());
                }
            }

            var model = await functionalUnitOfWork.AdRepository.FirstOrDefault(a => a.Id == id);

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

            var ad = (AdViewModel)(model);

            ad.Owner = await _userManager.FindByIdAsync(ad.OwnerId);

            ad.Owner.PhotoUrl ??= new GravatarUrlExtension.Gravatar().GetImageSource(ad.Owner.Email);

            await _eventTrackingService.Create(User.NameIdentifier(), "ViewAd", id.ToString());

            model.ViewCount += 1;
            await functionalUnitOfWork.AdRepository.Update(model);

            ad.ViewCount = model.ViewCount;

            var authorAds = await functionalUnitOfWork.AdRepository.GetVisibledUser(ad.OwnerId);

            ad.Owner.AdsCount = authorAds.Count;

            ad.OtherAds = authorAds.Select(a => new ListAdViewModel {
                Id = a.Id, ImageUrl1 = a.ImageUrl1, Title = a.Title, OrderNumber = a.OrderNumber
            })
                          .OrderBy(a => a.OrderNumber).ToList();

            ad.Owner.SocialNetworkConnected =
                await functionalUnitOfWork.SocialNetworkRepository.GetSocialNetworkLinks(ad.OwnerId);

            ad.Owner.CustomLinks = await functionalUnitOfWork.CustomLinkRepository.GetCustomLinkLinks(ad.OwnerId);

            var categorieIds = await _adsUnitOfWork.CategoryAdRepository.GetAllIdCatByAdId(ad.Id);

            List <string> categories = new();
            string        family     = string.Empty;

            foreach (Guid categoryId in categorieIds)
            {
                var category = await _adsUnitOfWork.CategoriesRepository.Get(categoryId);

                if (string.IsNullOrEmpty(family))
                {
                    var familyId = category.FamilyId;
                    var f        = await _adsUnitOfWork.FamiliesRepository.Get(familyId);

                    family = f.Code;
                }

                categories.Add(category.Code);
            }

            ad.Family         = family;
            ad.Categories     = categories;
            ad.ListIdCategory = categorieIds;

            var events = await _eventTrackingService.Where(c => c.Category == "ViewAd" && c.Key == id.ToString());

            if (events.Any())
            {
                var contactIds = events.OrderByDescending(e => e.CreatedDate).Select(e => e.UserId).Distinct().Take(10).ToArray();
                ad.LastViewers = await _userManager.Users.Where(u => contactIds.Contains(u.Id)).Select(u => (ViewApplicationUser)u).ToListAsync();
            }
            else
            {
                ad.LastViewers = new List <ViewApplicationUser> {
                    User
                };
            }

            return(Ok(ad));
        }
        public async Task <IActionResult> OnGetAsync(string data1, string data2)
        {
            if (string.IsNullOrEmpty(data1) || string.IsNullOrEmpty(data2))
            {
                return(RedirectToPage("/Index"));
            }
            var ownerId = CryptHelper.Rijndael.Decrypt(data1, _configuration["QrCode:Key"]);
            var userId  = CryptHelper.Rijndael.Decrypt(data2, _configuration["QrCode:Key"]);

            var owner = await _userManager.FindByIdAsync(ownerId);

            var user = await _userManager.FindByIdAsync(userId);

            if (user == null || owner == null)
            {
                return(NotFound($"Unable to load user with ID '{userId}'."));
            }

            var contact = await _UnitOfWork.ContactRepository.GetContact(ownerId, userId);

            contact.DateAccepted = DateTime.Now;
            contact.UserAccepted = EnumUserAccepted.ACCEPTED;
            await _UnitOfWork.ContactRepository.Update(contact);

            var invitation = await _UnitOfWork.InvitationRepository.GetInvitation(ownerId, userId);

            await _eventTrackingService.Create(new Shared.Functional.EventTrackingItem
            {
                Id          = Guid.NewGuid(),
                CreatedDate = DateTime.UtcNow,
                Category    = "contact",
                Key         = "confirmContact",
                UserId      = contact.OwnerId
            });

            if (invitation != null)
            {
                invitation.InvitationStat = (int)EnumUserAccepted.ACCEPTED;
                await _UnitOfWork.InvitationRepository.Update(invitation);
            }

            var contact2 = await _UnitOfWork.ContactRepository.GetContact(userId, ownerId);

            if (contact2 == null)
            {
                contact2              = new Contact();
                contact2.OwnerId      = contact.UserId;
                contact2.UserId       = contact.OwnerId;
                contact2.DateAccepted = DateTime.Now;
                contact2.UserAccepted = EnumUserAccepted.ACCEPTED;
                await _UnitOfWork.ContactRepository.Add(contact2);

                var invitation2 = await _UnitOfWork.InvitationRepository.GetInvitation(userId, ownerId);

                if (invitation2 != null)
                {
                    invitation.InvitationStat = (int)EnumUserAccepted.ACCEPTED;
                    await _UnitOfWork.InvitationRepository.Update(invitation);
                }
                else
                {
                    invitation2 = new Shared.Functional.Invitation
                    {
                        OwnedId        = contact.UserId,
                        ContactId      = contact.OwnerId,
                        CreatedDate    = DateTime.UtcNow,
                        InvitationStat = (int)EnumUserAccepted.ACCEPTED,
                        Id             = Guid.NewGuid()
                    };

                    await _UnitOfWork.InvitationRepository.Add(invitation2);

                    await _eventTrackingService.Create(new Shared.Functional.EventTrackingItem
                    {
                        Id          = Guid.NewGuid(),
                        CreatedDate = DateTime.UtcNow,
                        Category    = "contact",
                        Key         = "confirmContact",
                        UserId      = contact2.OwnerId
                    });
                }
            }

            DisplayName = user.DisplayName;

            return(Page());
        }
Ejemplo n.º 15
0
        public async Task <ActionResult <Contact> > AcceptInvitation(Guid contactId, Contact link)
        {
            if (contactId == Guid.Empty)
            {
                return(BadRequest());
            }

            if (contactId != link.Id)
            {
                return(BadRequest());
            }

            var contact = await _UnitOfWork.ContactRepository.GetContact(contactId);

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

            contact.DateAccepted = DateTime.Now;
            contact.UserAccepted = EnumUserAccepted.ACCEPTED;

            await _UnitOfWork.ContactRepository.Update(contact);

            var invitation = await _UnitOfWork.InvitationRepository.GetInvitation(contact.OwnerId, contact.UserId);

            await _eventTrackingService.Create(new Shared.Functional.EventTrackingItem
            {
                Id          = Guid.NewGuid(),
                CreatedDate = DateTime.UtcNow,
                Category    = "contact",
                Key         = "confirmContact",
                UserId      = contact.OwnerId
            });

            if (invitation != null)
            {
                invitation.InvitationStat = (int)EnumUserAccepted.ACCEPTED;
                await _UnitOfWork.InvitationRepository.Update(invitation);
            }

            var contact2 = await _UnitOfWork.ContactRepository.GetContact(contact.UserId, contact.OwnerId);

            if (contact2 == null)
            {
                contact2 = new Contact
                {
                    OwnerId      = contact.UserId,
                    UserId       = contact.OwnerId,
                    DateAccepted = DateTime.Now,
                    UserAccepted = EnumUserAccepted.ACCEPTED
                };

                await _UnitOfWork.ContactRepository.Add(contact2);

                var invitation2 = await _UnitOfWork.InvitationRepository.GetInvitation(contact.UserId, contact.OwnerId);

                if (invitation2 != null)
                {
                    invitation.InvitationStat = (int)EnumUserAccepted.ACCEPTED;
                    await _UnitOfWork.InvitationRepository.Update(invitation);
                }
                else
                {
                    invitation2 = new Shared.Functional.Invitation
                    {
                        OwnedId        = contact.UserId,
                        ContactId      = contact.OwnerId,
                        CreatedDate    = DateTime.UtcNow,
                        InvitationStat = (int)EnumUserAccepted.ACCEPTED,
                        Id             = Guid.NewGuid()
                    };

                    await _UnitOfWork.InvitationRepository.Add(invitation2);

                    await _eventTrackingService.Create(new Shared.Functional.EventTrackingItem
                    {
                        Id          = Guid.NewGuid(),
                        CreatedDate = DateTime.UtcNow,
                        Category    = "contact",
                        Key         = "confirmContact",
                        UserId      = contact2.OwnerId
                    });
                }
            }

            return(Ok(contact));
        }