public void AuthorizeUser(SecretSantaParticipant participant)
        {
            var claims = new[] { new Claim(ClaimTypes.Name, participant.PhoneNumber) };

            claims.Append(new Claim(ClaimTypes.Role, participant.Role));
            _identity = new ClaimsIdentity(claims, "apiauth_type");
            var user = new ClaimsPrincipal(_identity);

            NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(user)));
        }
Example #2
0
        /// <summary>
        /// Writes to a file the same thing that would be mailed out.
        /// </summary>
        public void WriteFile(SecretSantaParticipant gifter, SecretSantaParticipant recipient)
        {
            string path    = Path.Combine(RESULTS_DIRECTORY, string.Format("{0}.txt", gifter.Name));
            string content = string.Format(_settings.SantasMessage, gifter.Name, recipient.Name);

            // Replace </br> with new lines, and strip other html.
            content = Regex.Replace(content, "</br>", "\r\n");
            string noHTML = Regex.Replace(content, @"<[^>]+>|&nbsp;", "").Trim();

            File.WriteAllText(path, noHTML);
        }
Example #3
0
        /// <summary>
        /// Sends an email to the gifter who their recipient is.
        /// </summary>
        public void SendMail(SecretSantaParticipant gifter, SecretSantaParticipant recipient)
        {
            using (var mailMessage = new MailMessage())
            {
                mailMessage.From = new MailAddress(_settings.SantasEmail);
                mailMessage.To.Add(new MailAddress(gifter.Email));

                mailMessage.IsBodyHtml   = true;
                mailMessage.BodyEncoding = Encoding.UTF8;

                mailMessage.Subject = string.Format(_settings.SantasSubject, gifter.Name, recipient.Name);
                mailMessage.Body    = string.Format(_settings.SantasMessage, gifter.Name, recipient.Name);

                _smtpClient.Send(mailMessage);
            }
        }
Example #4
0
 public async Task NotifyUserOfUpdate(SecretSantaParticipant participant)
 {
     if (participant.Match != null)
     {
         var msg = $"Hello, this is Santa again, just wanted to let you know that your match {participant.Name} sent me some updates:" +
                   $" Their Address is {participant.Address}.";
         if (!string.IsNullOrEmpty(participant.GiftIdeas))
         {
             msg += $" And they indicated they'd want {participant.GiftIdeas}";
         }
         await _client.SmsClient.SendAnSmsAsync(new SendSmsRequest
         {
             To   = participant.Match.PhoneNumber,
             From = _config["VONAGE_NUMBER"],
             Text = msg
         });
     }
 }