示例#1
0
        public async Task ForgotPassword(string email, NotificationServiceType type)
        {
            switch (type)
            {
            case NotificationServiceType.Email:

                User user = await Uow.UserRepository.GetByEmail(email);

                if (user == null)
                {
                    throw new Exception($"User with {email} email not found");
                }

                string hostUrl = "http://localhost:4200";    //httpAccessor.HttpContext.Request.Host.ToString();
                string url     =
                    $"{hostUrl}/restoring-password/{Hasher.ByteToString(user.PasswordHash)}";

                var message = new NotificationMessage
                {
                    Title = "Restoring password",
                    To    = email,
                    Body  = $"Click a link to restore password: {url}",
                };
                NotificationServiceFactory factory = new NotificationServiceFactory();
                await factory.CreateService(type).Send(message);

                break;

            default:
                throw new ArgumentException();
            }
        }
示例#2
0
        public EventSubscription(
            long userId,
            string userEmail,
            string eventCode,
            DateTimeOffset eventStartTime,
            TimeSpan eventDuration,
            string eventName,
            string eventDescription,
            string eventRoom,
            bool enablePushNotification,
            NotificationServiceType notificationService,
            string notificationToken)
        {
            Id = Guid.NewGuid();

            UserId                 = userId;
            UserEmail              = userEmail;
            EventCode              = eventCode;
            EventStartTime         = eventStartTime;
            EventDuration          = eventDuration;
            EventName              = eventName;
            EventDescription       = eventDescription;
            EventRoom              = eventRoom;
            EnablePushNotification = enablePushNotification;
            NotificationService    = notificationService;
            NotificationToken      = notificationToken;
        }
        private static void StartHost(string consumerGroupSuffix)
        {
            Trace.WriteLine("Starting Worker...");
#if DEBUG_LOG
            RoleEnvironment.TraceSource.TraceInformation("Starting Worker...");
#endif

            _Config = ConfigurationLoader.GetConfig();
            if (_Config == null)
            {
                return;
            }
            _Config.ConsumerGroupPrefix += consumerGroupSuffix;

            _NotificationService =
                (NotificationServiceType)Enum.Parse(typeof(NotificationServiceType), _Config.NotificationService);

            var credentials = new NetworkCredential(_Config.EmailServiceUserName, _Config.EmailServicePassword);

            PrepareMailAddressInstances();

            switch (_NotificationService)
            {
            case NotificationServiceType.Smtp:
            {
                _SmtpClient = new SmtpClient
                {
                    Port                  = _Config.SmtpEnableSSL ? 587 : 25,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    EnableSsl             = false,
                    Host                  = _Config.SmtpHost,
                    Credentials           = credentials
                };
            }
            break;

            case NotificationServiceType.SendGridWeb:
            {
                _SendGridTransportWeb = new Web(credentials);
            }
            break;

            case NotificationServiceType.Twilio:
            case NotificationServiceType.TwilioCall:
            {
                string ACCOUNT_SID = _Config.EmailServiceUserName;
                string AUTH_TOKEN  = _Config.EmailServicePassword;

                _TwilioRestClient = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
            }
            break;
            }

            _EventHubReader = new EventHubReader(_Config.ConsumerGroupPrefix, OnMessage);

            Process();
        }
示例#4
0
        public INotificationService CreateService(NotificationServiceType type)
        {
            switch (type)
            {
            case NotificationServiceType.Email:
                return(new EmailNotificationService());

            default:
                throw new NotImplementedException("Notification service does not exist");
            }
        }
 public SubscribeToEventResponse(EventSubscription subscription)
 {
     Id                     = subscription.Id;
     Email                  = subscription.UserEmail;
     EventCode              = subscription.EventCode;
     EventName              = subscription.EventName;
     EventDescription       = subscription.EventDescription;
     EventRoom              = subscription.EventRoom;
     EventStartTime         = subscription.EventStartTime;
     EventDuration          = subscription.EventDuration;
     EnablePushNotification = subscription.EnablePushNotification;
     NotificationService    = subscription.NotificationService;
 }
示例#6
0
        private static void StartHost(string consumerGroupSuffix)
        {
            Trace.WriteLine("Starting Worker...");
#if DEBUG_LOG
            RoleEnvironment.TraceSource.TraceInformation("Starting Worker...");
#endif

            _Config = ConfigurationLoader.GetConfig();
            if (_Config == null)
            {
                return;
            }
            _Config.ConsumerGroupPrefix += consumerGroupSuffix;

            _NotificationService =
                  (NotificationServiceType)Enum.Parse(typeof(NotificationServiceType), _Config.NotificationService);

            var credentials = new NetworkCredential(_Config.EmailServiceUserName, _Config.EmailServicePassword);

            PrepareMailAddressInstances();

            switch (_NotificationService)
            {
                case NotificationServiceType.Smtp:
                    {
                        _SmtpClient = new SmtpClient
                        {
                            Port = _Config.SmtpEnableSSL ? 587 : 25,
                            DeliveryMethod = SmtpDeliveryMethod.Network,
                            UseDefaultCredentials = false,
                            EnableSsl = false,
                            Host = _Config.SmtpHost,
                            Credentials = credentials
                        };
                    }
                    break;
                case NotificationServiceType.SendGridWeb:
                    {
                        _SendGridTransportWeb = new Web(credentials);
                    }
                    break;
                case NotificationServiceType.Twilio:
                case NotificationServiceType.TwilioCall:
                    {
                        string ACCOUNT_SID = _Config.EmailServiceUserName;
                        string AUTH_TOKEN = _Config.EmailServicePassword;

                        _TwilioRestClient = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
                    }
                    break;
            }

            _EventHubReader = new EventHubReader(_Config.ConsumerGroupPrefix, OnMessage);

            Process();
        }