-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make login more robust and improve mail handling
- Loading branch information
1 parent
5bd907a
commit 4c5b264
Showing
3 changed files
with
49 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,34 @@ public NotionWebsitePuppeteer(string seleniumHost, string notionUsername, string | |
|
||
private void Login() | ||
{ | ||
void TryLoginWithLink() | ||
{ | ||
Console.WriteLine("Trying login-code login..."); | ||
// Query mail for login code | ||
|
||
MailGrabber mg = new MailGrabber(MailHost, MailUser, MailPassword); | ||
string loginUrl = ""; | ||
bool foundUrl = false; | ||
|
||
while (!foundUrl) | ||
{ | ||
Thread.Sleep(2000); | ||
Console.WriteLine("Waiting for login code email..."); | ||
List<string> loginUrls = mg.FindUrl("[email protected]", "https://www\\.notion\\.so/loginwithemail.*?(?=\")"); | ||
|
||
if (loginUrls.Count == 0) continue; | ||
|
||
loginUrl = loginUrls.First(); | ||
foundUrl = true; | ||
mg.Purge("[email protected]","login code"); | ||
|
||
} | ||
|
||
Console.WriteLine("Logging in using URL..."); | ||
_driver.Navigate().GoToUrl(loginUrl); | ||
Thread.Sleep(5000); | ||
} | ||
|
||
bool FirstLoginStep() | ||
{ | ||
bool needsLoginCode = false; | ||
|
@@ -93,32 +121,7 @@ bool FirstLoginStep() | |
|
||
if (needsLoginCode) | ||
{ | ||
Console.WriteLine("Trying login-code login..."); | ||
// Query mail for login code | ||
|
||
MailGrabber mg = new MailGrabber(MailHost, MailUser, MailPassword); | ||
string loginUrl = ""; | ||
bool foundUrl = false; | ||
|
||
while (!foundUrl) | ||
{ | ||
Thread.Sleep(2000); | ||
Console.WriteLine("Waiting for login code email..."); | ||
List<string> loginUrls = mg.FindUrl("[email protected]", "https://www\\.notion\\.so/loginwithemail.*?(?=\")"); | ||
|
||
if (loginUrls.Count == 0) continue; | ||
|
||
loginUrl = loginUrls.First(); | ||
foundUrl = true; | ||
mg.Purge("[email protected]"); | ||
|
||
} | ||
|
||
Console.WriteLine("Logging in using URL..."); | ||
_driver.Navigate().GoToUrl(loginUrl); | ||
Thread.Sleep(5000); | ||
|
||
|
||
TryLoginWithLink(); | ||
} | ||
else | ||
{ | ||
|
@@ -135,6 +138,7 @@ bool FirstLoginStep() | |
catch | ||
{ | ||
Console.WriteLine("bad login"); | ||
TryLoginWithLink(); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,8 +135,8 @@ async Task<Cookie> FileCookie() | |
} | ||
|
||
// Purge Emails | ||
mail.Purge("[email protected]"); | ||
mail.Purge("[email protected]"); | ||
mail.Purge("[email protected]","workspace export"); | ||
mail.Purge("[email protected]", "workspace export"); | ||
|
||
|
||
} | ||
|