Example #1
0
        public async Task SendBotMessage(string messageText, BotUserDataDto botUserDataDto)
        {
            MicrosoftAppCredentials.TrustServiceUrl("https://smba.trafficmanager.net/apis");

            var conversationId = botUserDataDto.UserConversationId;
            var userAccount    = new Microsoft.Bot.Connector.ChannelAccount(botUserDataDto.UserConversationId, botUserDataDto.UserName);
            var botAccount     = new Microsoft.Bot.Connector.ChannelAccount(botUserDataDto.BotConversationId, botUserDataDto.BotName);
            var connector      = new ConnectorClient(new Uri("https://smba.trafficmanager.net/apis"), "[KEY]", "[KEY]");

            // Create a new message.
            Microsoft.Bot.Connector.IMessageActivity message = Activity.CreateMessageActivity();
            if (!string.IsNullOrEmpty(conversationId) && !string.IsNullOrEmpty(botUserDataDto.ChannelId))
            {
                // If conversation ID and channel ID was stored previously, use it.
                message.ChannelId = "skype";
            }
            else
            {
                // Conversation ID was not stored previously, so create a conversation.
                // Note: If the user has an existing conversation in a channel, this will likely create a new conversation window.
                conversationId = (await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount)).Id;
            }

            // Set the address-related properties in the message and send the message.
            message.From         = botAccount;
            message.Recipient    = userAccount;
            message.Conversation = new ConversationAccount(id: conversationId);
            message.Text         = messageText;
            message.Locale       = "es-us";
            await connector.Conversations.SendToConversationAsync((Activity)message);
        }
Example #2
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null, string codeaccess = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User logged in.");

                    var appUser = _userManager.Users.SingleOrDefault(r => r.Email == model.Email);

                    var tokenManager             = new JwtManager();
                    var expirationTokenInMinutes = 180;

                    var token = tokenManager.GenerateJwtToken(model.Email, appUser.Id, expirationTokenInMinutes);

                    var todo = _context.BotLogin.ToList();

                    var newBotLogin = new BotLogin();
                    newBotLogin.ExpirationTime = DateTime.UtcNow.AddMinutes(Convert.ToDouble(expirationTokenInMinutes));
                    newBotLogin.Jwt            = token;
                    newBotLogin.UserName       = model.Email;

                    if (model.Email.ToLower() == "*****@*****.**")
                    {
                        newBotLogin.SkypeUserName = "******";
                    }

                    if (model.Email.ToLower() == "*****@*****.**")
                    {
                        newBotLogin.SkypeUserName = "******";
                    }

                    if (model.Email.ToLower() == "*****@*****.**")
                    {
                        newBotLogin.SkypeUserName = "******";
                    }

                    _context.BotLogin.Add(newBotLogin);
                    _context.SaveChanges();

                    var botService = new BotService();

                    var userData = _context.BotProactiveMessage.Where(botProactiveMessage => botProactiveMessage.UserName == newBotLogin.SkypeUserName).FirstOrDefault();

                    var botuserDataDto = new BotUserDataDto {
                        BotConversationId  = userData.FromID,
                        UserConversationId = userData.Conversation,
                        BotName            = userData.FromName,
                        UserName           = userData.UserName,
                        ChannelId          = userData.ChannelId
                    };

                    await botService.SendBotMessage("El usuario ha sido autenticado", botuserDataDto);

                    return(RedirectToAction("LoginSucceded"));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToAction(nameof(LoginWith2fa), new { returnUrl, model.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToAction(nameof(Lockout)));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(View(model));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }