예제 #1
0
        public async Task <IActionResult> AuthUserToChannel(Guid?id, ChannelAuth channelAuth)
        {
            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 hashedInput = EncryptionService.Sha256(channelAuth.HashedKey);

            if (hashedInput == channel.KeyHash)
            {
                var authResult = await channelAuthService.CreateAuth(channel, currentUser);

                if (authResult)
                {
                    return(Redirect(Constants.Routes.EngageChannel + "/" + channel.Id));
                }
                else
                {
                    ViewBag.Error   = "There was a problem authorising you to this channel.";
                    ViewBag.Channel = channel;
                    return(View());
                }
            }

            ViewBag.Error   = "Incorrect password";
            ViewBag.Channel = channel;
            return(View());
        }
예제 #2
0
        public async Task <bool> CreateAuth(Channel channel, User user)
        {
            if (channel == null || user == null)
            {
                return(false);
            }
            if (await UserIsAuthed(channel, user))
            {
                return(false);
            }

            var channelAuth = new ChannelAuth
            {
                User      = user.Name,
                Channel   = channel.Id,
                HashedKey = channel.KeyHash
            };

            context.Add(channelAuth);
            await context.SaveChangesAsync();

            return(true);
        }