Ejemplo n.º 1
0
        public async Task <IActionResult> AuthUserToChannel(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var channel = await context.Channels.FirstOrDefaultAsync(c => c.Id == id);

            var currentUser = await cookieService.CurrentUser(Request);

            if (channel == null || currentUser == null)
            {
                return(NotFound());
            }

            var auth = await channelAuthService.UserIsAuthed(channel, currentUser);

            if (auth)
            {
                return(Redirect(Constants.Routes.EngageChannel + "/" + channel.Id.ToString()));
            }

            // User is not already authed, they need to enter the password
            ViewBag.Channel = channel;
            return(View());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Login()
        {
            var currentUser = await cookie.CurrentUser(Request);

            if (currentUser != null)
            {
                return(Redirect(Constants.Routes.Home));
            }

            return(View());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> ViewAll()
        {
            var cookie      = new CookieService(context);
            var currentUser = await cookie.CurrentUser(Request);

            if (currentUser == null)
            {
                return(Redirect(Constants.Routes.Login));
            }

            ViewBag.CurrentUser = currentUser;
            ViewBag.Channels    = await context.Channels.ToListAsync();

            return(View());
        }
Ejemplo n.º 4
0
        public async Task<IActionResult> Engage(Guid? id)
        {
            if (id == null)
                return NotFound();

            var channel = await context.Channels.FirstOrDefaultAsync(x => x.Id == id);
            if (channel == null)
                return NotFound();

            // Check the current user is authorised
            var cookie = new CookieService(context);
            var currentUser = await cookie.CurrentUser(Request);
            if (currentUser == null)
                return Redirect(Constants.Routes.Login);

            var channelAuth = new ChannelAuthService(context);
            var auth = await channelAuth.UserIsAuthed(channel, currentUser);
            if (!auth)
                return Redirect(Constants.Routes.AuthUserToChannel + id.ToString());

            return View();
        }