@@ -44,12 +44,11 @@ public string GetAnonymousId(int accountId)
4444 return state ;
4545 }
4646
47- public async Task LinkAccount ( string state , string code )
47+ public async Task < bool > LinkAccount ( string state , string code )
4848 {
4949 try
5050 {
5151 int accountId ;
52- Trace . TraceInformation ( "Linking discord id..." ) ;
5352 if ( ! userIds . TryGetValue ( state , out accountId ) )
5453 {
5554 Trace . TraceWarning ( "Invalid state " + state ) ;
@@ -69,15 +68,12 @@ public async Task LinkAccount(string state, string code)
6968 var response = await new HttpClient ( ) . SendAsync ( request ) ;
7069 response . EnsureSuccessStatusCode ( ) ;
7170
72- Trace . TraceInformation ( "Sent discord identify request..." ) ;
7371 var payload = JObject . Parse ( await response . Content . ReadAsStringAsync ( ) ) ;
7472 var token = payload . Value < string > ( "access_token" ) ;
7573
7674 var discord = new DiscordRestClient ( ) ;
77- Trace . TraceInformation ( "Logging in discord client..." ) ;
7875 await discord . LoginAsync ( TokenType . Bearer , token ) ;
7976 var discordId = discord . CurrentUser . Id ;
80- Trace . TraceInformation ( "Got discord id " + discordId ) ;
8177 using ( var db = new ZkDataContext ( ) )
8278 {
8379 var existing = db . Accounts . FirstOrDefault ( x => x . DiscordID == discordId ) ;
@@ -87,15 +83,17 @@ public async Task LinkAccount(string state, string code)
8783 existing . DiscordID = ( decimal ? ) null ;
8884 db . SaveChanges ( ) ;
8985 }
90- Trace . TraceInformation ( "Linking discord id " + discordId + " to Account " + existing . Name ) ;
86+ Trace . TraceInformation ( "Linking discord id " + discordId + " to Account " + accountId ) ;
9187 db . Accounts . FirstOrDefault ( x => x . AccountID == accountId ) . DiscordID = discordId ;
9288 db . SaveChanges ( ) ;
9389 }
9490 }
9591 catch ( Exception ex )
9692 {
9793 Trace . TraceError ( "Error linking discord ID " + ex ) ;
94+ return false ;
9895 }
96+ return true ;
9997 }
10098 }
10199
0 commit comments