Пример #1
0
        public ActionResult Generate(int eventId)
        {
            Event e = eventUoW.Events.GetEventByID(eventId);

            if (e == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            if (User.Identity.GetUserId() != e.OwnerId)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }

            Guid       guid = Guid.NewGuid();
            InviteLink link = new InviteLink {
                EventId = eventId, LinkGUID = guid.ToString(), OneTimeUse = true, ModificationState = ModificationState.Added
            };

            eventUoW.InviteLinks.Attach(link);
            eventUoW.Save();

            UrlHelper urlHelper = new UrlHelper(HttpContext.Request.RequestContext);
            string    url       = urlHelper.Action("Details", "Event", new { id = eventId, guid = guid.ToString() }, urlHelper.RequestContext.HttpContext.Request.Url.Scheme);

            return(Json(new { url = url }));
        }
Пример #2
0
        public ActionResult Create(HellViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Create a new event.
                Event e = new Event();
                e.Brief             = model.CreateViewModel.Brief;
                e.Detailed          = model.CreateViewModel.Detailed;
                e.Visibility        = model.CreateViewModel.Visibility;
                e.Address           = model.CreateViewModel.Address;
                e.Latitude          = model.CreateViewModel.Latitude;
                e.Longitude         = model.CreateViewModel.Longitude;
                e.StartTime         = model.CreateViewModel.StartTime;
                e.ModificationState = ModificationState.Added;
                e.OwnerId           = User.Identity.GetUserId();
                eventUoW.Events.Attach(e);

                // Create a share link for this event.
                InviteLink link = new InviteLink();
                link.Event             = e;
                link.LinkGUID          = Guid.NewGuid().ToString();
                link.OneTimeUse        = false;
                link.ModificationState = ModificationState.Added;
                eventUoW.InviteLinks.Attach(link);

                // Save the changes.
                eventUoW.Save();

                return(RedirectToAction("Details", "Event", new { id = e.Id }));
            }

            return(View());
        }
Пример #3
0
        public static string GenerateToken(this InviteLink link)
        {
            string path = Path.GetRandomFileName();

            path = path.Replace(".", ""); // Remove period.
            return(path.Substring(0, 8));
        }
Пример #4
0
        public async Task <IActionResult> OnGetDelete(int id)
        {
            InviteLink link = (InviteLink)await applicationContext.FindAsync(typeof(InviteLink), new object[] { id });

            applicationContext.InviteLinks.Remove(link);
            await applicationContext.SaveChangesAsync();

            return(RedirectToAction(""));
        }
Пример #5
0
        public ActionResult Details(int id, string guid)
        {
            var vm = new DetailsViewModel();

            vm.Event = eventUoW.Events.GetEventByID(id);

            if (vm.Event == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            vm.Event.AppUser = eventUoW.Users.GetUserById(vm.Event.OwnerId);
            vm.Invites       = eventUoW.Invites.GetInvitedToEvent(vm.Event);
            vm.ShareLink     = eventUoW.InviteLinks.GetShareLink(vm.Event);
            vm.IsOwner       = User.Identity.IsAuthenticated && User.Identity.GetUserId() == vm.Event.OwnerId;

            if (!vm.IsOwner)
            {
                if (User.Identity.IsAuthenticated)
                {
                    var user = eventUoW.Users.GetUserById(User.Identity.GetUserId());
                    if (user == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
                    }

                    if (eventUoW.Invites.IsInvited(vm.Event, user))
                    {
                        vm.IsInvited  = true;
                        vm.UserInvite = eventUoW.Invites.GetInviteByEventAndUser(vm.Event, user);
                    }
                }

                if (!vm.IsInvited)
                {
                    if (guid != null)
                    {
                        InviteLink link = eventUoW.InviteLinks.GetLinkGraphByGuid(guid);
                        if (link == null)
                        {
                            return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
                        }

                        vm.IsInvited = true;
                        vm.Link      = link;
                    }
                }
            }

            return(View(new HellViewModel {
                DetailsViewModel = vm
            }));
        }
Пример #6
0
        public string UseKey(string key)
        {
            InviteLink link = context.InviteLinks.First(l => l.Key == key);

            if (link != null && !IsExpired(link))
            {
                context.InviteLinks.Remove(link);
                context.SaveChanges();
                return(link.Role);
            }

            throw new Exception("Invalid key used");
        }
Пример #7
0
        public async Task <string> CreateNewInviteLink(string role)
        {
            string     key  = GenerateKey() + GenerateKey();
            InviteLink link = new InviteLink(key, role);

            DbSet <InviteLink> inviteLinks = context.InviteLinks;

            inviteLinks.Add(link);

            await context.SaveChangesAsync();

            return(key);
        }
Пример #8
0
        public IActionResult Generate()
        {
            // Generate random 12-character string
            const string chars  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            var          random = new Random();
            var          link   = new string(Enumerable.Repeat(chars, 12)
                                             .Select(s => s[random.Next(s.Length)]).ToArray());

            var inviteLink = new InviteLink();

            inviteLink.UserID = UserId;
            inviteLink.Link   = link;

            this._dbContext.InviteLinks.Add(inviteLink);
            this._dbContext.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
Пример #9
0
        public ActionResult Delete(string guid)
        {
            InviteLink link = eventUoW.InviteLinks.GetLinkGraphByGuid(guid);

            if (link == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            if (User.Identity.GetUserId() != link.Event.OwnerId)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }

            // Simply remove the link.
            eventUoW.InviteLinks.Remove(link);
            eventUoW.Save();

            return(RedirectToAction("Details", "Event", new { id = link.EventId }));
        }
Пример #10
0
        public void Start()
        {
            if (!SkipJoin)
            {
                if (InviteLink.Length < 8)
                {
                    Console.WriteLine($"Invalid invite link. {InviteLink}");
                    Environment.Exit(0);
                }
                InviteCode = InviteLink.Substring(InviteLink.Length - _discordInviteCodeLenght);

                var urlToJoinChannel = $"{_discordApiUrlBase}/invites/{InviteCode}";
                JoinChannel(urlToJoinChannel);
            }

            var urlToSendMessage = $"{_discordApiUrlBase}/channels/{ChannelId}/messages";
            var t = new Thread(() => SendMessages(urlToSendMessage));

            t.Start();
        }
Пример #11
0
        public InviteLink AddInvite(string orgID, Invite invite)
        {
            invite.InvitedUser = invite.InvitedUser.ToLower();

            var organization = RemotelyContext.Organizations
                .Include(x => x.InviteLinks)
                .FirstOrDefault(x => x.ID == orgID);

            var newInvite = new InviteLink()
            {
                DateSent = DateTimeOffset.Now,
                InvitedUser = invite.InvitedUser,
                IsAdmin = invite.IsAdmin,
                Organization = organization,
                OrganizationID = organization.ID
            };
            organization.InviteLinks.Add(newInvite);
            RemotelyContext.SaveChanges();
            return newInvite;
        }
        public async Task <Result <InviteLinkDto> > Handle(CreateInviteCommand request, CancellationToken cancellationToken)
        {
            // Get the classroom.
            var classroom = await _context.Classrooms.FindAsync(request.ClassroomId);

            // No classroom  was found with the given id.
            if (classroom is null)
            {
                return(Result <InviteLinkDto> .Failure("Unable to find classroom."));
            }

            // Get the currently authorized user.
            var user = await _context.Users.SingleOrDefaultAsync(x =>
                                                                 x.UserName == _userAccessor.GetCurrentUsername());

            // Create a new entry in the InviteLink table.
            var link = new InviteLink {
                Id                  = request.Id,
                Token               = new ShortGuid(Guid.NewGuid()),
                ExpiryDate          = DateTime.Now.AddDays(1),
                ExpireAfterFirstUse = false,
                Hits                = 0
            };

            _context.InviteLinks.Add(link);

            var linkToReturn = _mapper.Map <InviteLink, InviteLinkDto>(link);

            // Save changes to the database.
            var success = await _context.SaveChangesAsync() > 0;

            if (success)
            {
                return(Result <InviteLinkDto> .Success(linkToReturn));
            }

            return(Result <InviteLinkDto> .Failure("There was a problem saving changes."));
        }
Пример #13
0
        public ActionResult Decline(string guid)
        {
            InviteLink link = eventUoW.InviteLinks.GetLinkGraphByGuid(guid);

            if (link == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            // Make sure the user is not the owner.
            if (link.Event.OwnerId == User.Identity.GetUserId())
            {
                return(RedirectToAction("Details", "Event", new { id = link.EventId }));
            }

            // Make sure the user is not already invited.
            AppUser user = eventUoW.Users.GetUserById(User.Identity.GetUserId());

            if (eventUoW.Invites.IsInvited(link.Event, user))
            {
                return(RedirectToAction("Details", "Event", new { id = link.EventId }));
            }

            // Create an invite.
            eventUoW.Invites.Attach(new Invite {
                Event = link.Event, AppUser = user, Status = InviteStatus.Declined, Seen = true, ModificationState = ModificationState.Added
            });

            // Remove the invite if it is one time use.
            if (link.OneTimeUse)
            {
                eventUoW.InviteLinks.Remove(link);
            }

            eventUoW.Save();

            return(RedirectToAction("Details", "Event", new { id = link.EventId }));
        }
Пример #14
0
        public InviteLink AddInvite(string requesterUserName, Invite invite)
        {
            invite.InvitedUser = invite.InvitedUser.ToLower();

            var requester    = RemotelyContext.Users.FirstOrDefault(x => x.UserName == requesterUserName);
            var organization = RemotelyContext.Organizations
                               .Include(x => x.InviteLinks)
                               .FirstOrDefault(x => x.ID == requester.OrganizationID);

            var newInvite = new InviteLink()
            {
                DateSent       = DateTime.Now,
                InvitedUser    = invite.InvitedUser,
                IsAdmin        = invite.IsAdmin,
                Organization   = organization,
                OrganizationID = organization.ID,
                ResetUrl       = invite.ResetUrl
            };

            organization.InviteLinks.Add(newInvite);
            RemotelyContext.SaveChanges();
            return(newInvite);
        }
Пример #15
0
        internal InviteLink AddInvite(string requesterUserName, Invite invite, string requestOrigin)
        {
            invite.InvitedUser = invite.InvitedUser.ToLower();

            var requester = RemotelyContext.Users
                            .Include(x => x.Organization)
                            .ThenInclude(x => x.InviteLinks)
                            .Include(x => x.Organization)
                            .ThenInclude(x => x.RemotelyUsers)
                            .FirstOrDefault(x => x.UserName == requesterUserName);

            var newInvite = new InviteLink()
            {
                DateSent     = DateTime.Now,
                InvitedUser  = invite.InvitedUser,
                IsAdmin      = invite.IsAdmin,
                Organization = requester.Organization
            };

            requester.Organization.InviteLinks.Add(newInvite);
            RemotelyContext.SaveChanges();
            return(newInvite);
        }
Пример #16
0
 public bool IsExpired(InviteLink link)
 {
     return(link.ExpiryTime.Subtract(DateTime.UtcNow).TotalSeconds <= 0);
 }
Пример #17
0
 public void Attach(InviteLink entity)
 {
     context.InviteLinks.Add(entity);
     ContextStateHelper.ApplyStateChanges(context);
 }
Пример #18
0
 public void Remove(InviteLink link)
 {
     context.InviteLinks.Remove(link);
 }
Пример #19
0
 public InviteService(string connectionString)
 {
     _iLink = new InviteLink(connectionString);
 }