Esempio n. 1
0
        private bool CheckPassword(long chatId, string password)
        {
            IMessageManager messageManager = ModulesManager.GetModulesManager().GetMessageManager();

            if (string.IsNullOrEmpty(password))
            {
                messageManager.SendTextMessage(chatId, TextResponse.Get(ResponseType.PasswordEmpty));
                return(false);
            }

            if (password.Length < 12)
            {
                messageManager.SendTextMessage(chatId, TextResponse.Get(ResponseType.PasswordMinLength));
                return(false);
            }

            if (password.Length > 25)
            {
                messageManager.SendTextMessage(chatId, TextResponse.Get(ResponseType.PasswordMaxLength));
                return(false);
            }

            if (!Regex.IsMatch(password, @"^[a-zA-Z0-9!""#$%&'()*+,-./:;<=>?@[\]^_`{|}~]+$"))
            {
                messageManager.SendTextMessage(chatId, TextResponse.Get(ResponseType.PasswordCharacters));
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        private void Logout(long chatId, IChatStateHandlerContext context)
        {
            IMessageManager messageManager = ModulesManager.GetModulesManager().GetMessageManager();
            IUserManager    userManager    = ModulesManager.GetModulesManager().GetUserManager();

            userManager.LogoutUser(chatId);
            messageManager.SendTextMessage(chatId, TextResponse.Get(ResponseType.Logout));
            context.ChangeChatState(chatId, Session.ChatSessionState.Start);
        }
Esempio n. 3
0
        private void RegistrationUser(ITelegramUserMessage message, IChatStateHandlerContext context)
        {
            IMessageManager messageManager = ModulesManager.GetModulesManager().GetMessageManager();
            IUserManager    userManager    = ModulesManager.GetModulesManager().GetUserManager();

            if (CheckPassword(message.ChatId, message.Message))
            {
                userManager.CreateNewUser(message.ChatId, message.Message);
                messageManager.SendTextMessage(message.ChatId, TextResponse.Get(ResponseType.SuccessRegistration));
                context.ChangeChatState(message.ChatId, Session.ChatSessionState.Start);
            }
        }
Esempio n. 4
0
        public void HandleUserMessage(ITelegramUserMessage message, IChatStateHandlerContext context)
        {
            if (message == null || context == null)
            {
                return;
            }

            IMessageManager messageManager = ModulesManager.GetModulesManager().GetMessageManager();

            messageManager.SendTextMessage(message.ChatId, TextResponse.Get(ResponseType.WelcomeMessage));
            context.ChangeChatState(message.ChatId, ChatSessionState.Start);
        }
Esempio n. 5
0
        private void LoginUser(ITelegramUserMessage message,
                               IChatStateHandlerContext context)
        {
            IMessageManager messageManager = ModulesManager.GetModulesManager().GetMessageManager();
            IUserManager    userManager    = ModulesManager.GetModulesManager().GetUserManager();

            bool success = userManager.LoginUser(message.ChatId, message.Message);

            if (success)
            {
                messageManager.SendTextMessage(message.ChatId, TextResponse.Get(ResponseType.SuccessAuthorisation));
                context.ChangeChatState(message.ChatId, Session.ChatSessionState.Authorized);
            }
            else
            {
                messageManager.SendTextMessage(message.ChatId, TextResponse.Get(ResponseType.FailAuthorisation));
            }
        }
        private void GetStash(long chatId, IChatStateHandlerContext context)
        {
            IDatabaseManager databaseManager = ModulesManager.GetDatabaseManager();
            IMessageManager  messageManager  = ModulesManager.GetMessageManager();

            IUser user = databaseManager.GetUser(chatId);

            if (user != null && user.IsAuthorized)
            {
                ICollection <IStashMessage> messagesFromStash = databaseManager.GetMessagesFromStash(chatId);
                if (messagesFromStash.Count == 0)
                {
                    messageManager.SendTextMessageAsync(chatId, TextResponse.Get(ResponseType.EmptyStash), null);
                }
                else
                {
                    foreach (IStashMessage stashMessage in messagesFromStash)
                    {
                        stashMessage.Decrypt(user);
                        stashMessage.Send();
                    }
                }
            }
        }
Esempio n. 7
0
        public void StartStateMessage(long chatId)
        {
            IMessageManager messageManager = ModulesManager.GetModulesManager().GetMessageManager();

            messageManager.SendTextMessage(chatId, TextResponse.Get(ResponseType.RegistrationReady));
        }
Esempio n. 8
0
        public void Handle(long chatId)
        {
            IMessageManager messageManager = ModulesManager.GetMessageManager();

            messageManager.SendTextMessageAsync(chatId, TextResponse.Get(ResponseType.FullStashError), null);
        }
Esempio n. 9
0
        private void Information(long chatId, IChatStateHandlerContext context)
        {
            IMessageManager messageManager = ModulesManager.GetMessageManager();

            messageManager.SendTextMessageAsync(chatId, TextResponse.Get(ResponseType.Information), null);
        }
Esempio n. 10
0
        public void StartStateMessage(long chatId)
        {
            IMessageManager messageManager = ModulesManager.GetMessageManager();

            messageManager.SendTextMessageAsync(chatId, TextResponse.Get(ResponseType.MainCommands), chatCommands.CreateReplyKeyboard());
        }
Esempio n. 11
0
        public void StartStateMessage(long chatId)
        {
            IMessageManager messageManager = ModulesManager.GetModulesManager().GetMessageManager();

            messageManager.SendTextMessage(chatId, TextResponse.Get(ResponseType.MainCommands));
        }