private async Task <IList <MimeMessage> > GetMessages(EmailData data)
        {
            var userInfo = data.UserInfo ?? await _userInfo.Get(data.UserId);

            var messages = new List <MimeMessage>();
            var text     = GetBody(data.Body, data.Files);

            foreach (var email in userInfo.Emails)
            {
                var emailMessage = new MimeMessage();
                emailMessage.From.Add(new MailboxAddress(_config.NameService, _config.EmailFrom));
                emailMessage.To.Add(new MailboxAddress(userInfo.SimpleFio, email));
                emailMessage.Subject = String.IsNullOrEmpty(data.Header) ? "Новое уведомление" : data.Header;
                emailMessage.Body    = new TextPart(TextFormat.Text)
                {
                    Text = text
                };

                messages.Add(emailMessage);
            }

            return(messages);
        }
Exemple #2
0
        public static async Task <ReturnResult> VerifyDevice(IDeviceAuth device,
                                                             IUserInfo userInfoContext, string location, IBot botContext)
        {
            UserInfo userInfo;
            var      usersInfo = await userInfoContext.Get(device.CurrentDeviceName(), device.GetCurrentUserIp());

            if (usersInfo == null || !usersInfo.UserLocation.Equals(location))
            {
                var deviceAuth = device.GetDeviceDetails();

                if (deviceAuth.Client != null && deviceAuth.OsInfo != null)
                {
                    // future upgrade use for notification if the device location differs
                    userInfo = new UserInfo
                    {
                        BrowserId    = device.GetBrowserId(),
                        DeviceName   = device.CurrentDeviceName(),
                        OsName       = deviceAuth.OsInfo.Name,
                        OsPlatForm   = deviceAuth.OsInfo.PlatForm,
                        OsSuccess    = deviceAuth.OsInfo.Success,
                        OsVersion    = deviceAuth.OsInfo.Version,
                        OsShortName  = deviceAuth.OsInfo.ShortName,
                        UserIpHost   = device.GetCurrentUserIp(),
                        UserLocation = device.GetUserLocation(location),
                    };
                    var result = await userInfoContext.Add(userInfo);

                    if (result.Succeeded)
                    {
                        return(new ReturnResult
                        {
                            Succeeded = true
                        });
                    }
                }
                else
                {
                    BotInfo bot = new BotInfo();
                    bot.Category    = deviceAuth.Bot.Category;
                    bot.Name        = deviceAuth.Bot.Name;
                    bot.Producer    = deviceAuth.Bot.Producer;
                    bot.ProducerUrl = deviceAuth.Bot.ProducerUrl;
                    bot.Url         = deviceAuth.Bot.Url;
                    bot.Success     = deviceAuth.Bot.Success;
                    var result = await botContext.Add(bot);

                    if (result.Succeeded)
                    {
                        return(new ReturnResult
                        {
                            Succeeded = true
                        });
                    }
                }
            }

            return(new ReturnResult
            {
                Succeeded = false,
                Error = "verification failed"
            });
        }
Exemple #3
0
 public T Get <T>() where T : class
 {
     return(_user.Get <T>());
 }