Skip to content

Commit

Permalink
server/RDSFactor/Sender.cs: Harmonize logging of sent passcodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarb committed Apr 23, 2016
1 parent c2ec6d6 commit 5615e8c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions server/RDSFactor/Sender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void SendSMS(string number, string passcode)
}
else
{
Logger.LogDebug("Sending OTP: " + passcode + " to: " + number);
Logger.LogDebug("Begin HTTP call to send SMS pass code.");

string url = _provider;
url = url.Replace("***TEXTMESSAGE***", WebUtility.UrlEncode(passcode));
Expand All @@ -77,12 +77,10 @@ public static void SendSMS(string number, string passcode)

if (response.IsSuccessStatusCode)
{
if (url.IndexOf("cpsms.dk") != -1)
{
// NOTE: Yes cpsms does indeed return HTTP 200 on errors!?!
if (content.IndexOf("error") != -1)
throw new SMSSendException(content);
}
if (url.IndexOf("cpsms.dk") != -1 && content.IndexOf("error") != -1)
throw new SMSSendException(content);

LogPassCodeSentSuccessfully(passcode, "SMS", number);
}
else
{
Expand All @@ -91,6 +89,7 @@ public static void SendSMS(string number, string passcode)
}
}


public static bool SendEmail(string email, string passcode)
{
var mail = new MailMessage();
Expand All @@ -105,7 +104,7 @@ public static bool SendEmail(string email, string passcode)
try
{
smtp.Send(mail);
Logger.LogDebug("Mail sent to: " + email);
LogPassCodeSentSuccessfully(passcode, "EMAIL", email);
return true;
}
catch (Exception ex)
Expand All @@ -117,5 +116,11 @@ public static bool SendEmail(string email, string passcode)
return false;
}
}


private static void LogPassCodeSentSuccessfully(string passcode, string method, string destination)
{
Logger.LogInfo($"One time password {passcode} sent to: ({method}) {destination}");
}
}
}

0 comments on commit 5615e8c

Please sign in to comment.