public OnboardResult CompleteFirstStepForeignUserOnboard(string handle, Customer.ForeignUserTypes type, string token = null, string tokenSecret = null) { OnboardResult r = new OnboardResult(); Customer c = RepoFactory.GetCustomerRepo().GetWithForeignUserID(handle, type); if (c == null) { Customer newCust = new Customer() { ForeignUserID = handle, ForeignUserType = (int)type, Type = (int)Customer.TypeCodes.Unclaimed, BillingType = (int)BillingSystem.BillingProcessorFactory.SupportedBillingProcessor.None }; newCust.ID = RepoFactory.GetCustomerRepo().Add(newCust); RepoFactory.GetCustomerRepo().AddForeignNetworkForCustomer(newCust.ID, handle, type); r.Customer = newCust; } else { // we don't put this in the repo, we're just // using it as a DTO to get the token and secret // back to the controller r.Customer = c; } OnboardToken newToken = new OnboardToken() { CustomerID = r.Customer.ID, VerificationString = System.Guid.NewGuid().ToString(), Token = token, Secret = tokenSecret, AccountType = (int)type, ForeignUserID = handle }; RepoFactory.GetOnboardTokenRepo().Add(newToken); r.OnboardToken = newToken; return r; }
/* private OnboardResult CoreCompleteFirstStepForeignUserOnboard(string handle, Customer.ForeignUserTypes type, string token=null, string tokenSecret=null) { OnboardResult r = new OnboardResult(); Customer c = RepoFactory.GetCustomerRepo().GetWithForeignUserID(handle, type); if (c == null) { Customer newCust = new Customer() { ForeignUserID = handle, ForeignUserType = (int)type, Type = (int)Customer.TypeCodes.Unclaimed, BillingType = (int)BillingSystem.BillingProcessorFactory.SupportedBillingProcessor.Stripe }; newCust.ID = RepoFactory.GetCustomerRepo().Add(newCust); RepoFactory.GetCustomerRepo().AddForeignNetworkForCustomer(newCust.ID, handle, type); r.Customer = newCust; } else { // we don't put this in the repo, we're just // using it as a DTO to get the token and secret // back to the controller r.Customer = c; } OnboardToken newToken = new OnboardToken() { CustomerID = r.Customer.ID, VerificationString = System.Guid.NewGuid().ToString(), Token = token, Secret = tokenSecret, AccountType = (int)type, ForeignUserID = handle }; RepoFactory.GetOnboardTokenRepo().Add(newToken); r.OnboardToken = newToken; return r; } */ private OnboardResult CoreCompleteTwitter(string oauth_token, string oauth_verifier) { OnboardResult r=new OnboardResult(); var requestToken = new OAuthRequestToken { Token = oauth_token }; TwitterService service = new TwitterService(_twitterAuthKey, _twitterConsumerSecret); OAuthAccessToken accessToken = service.GetAccessToken(requestToken, oauth_verifier); service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret); TwitterUser user = service.VerifyCredentials(); string handle = "@"+user.ScreenName; if (handle == null || handle.Equals("")) return null; return _obm.CompleteFirstStepForeignUserOnboard(handle, Customer.ForeignUserTypes.Twitter, accessToken.Token, accessToken.TokenSecret); }
public bool LinkForeignUserToCustomer(Customer custToLink, string handle, Customer.ForeignUserTypes type) { ICustomerRepository custRepo=RepoFactory.GetCustomerRepo(); OnboardResult res = new OnboardResult(); if (type == Customer.ForeignUserTypes.Twitter) { if (!handle.StartsWith("@")) handle = "@" + handle.ToLower(); } Customer c = custRepo.GetWithForeignUserID(handle, type); if (c != null) { if (c.ID == custToLink.ID) return true; if (c.Type != (int)Customer.TypeCodes.Unclaimed) return false; try { RepoFactory.GetChallengeRepo().MoveChallengesToCustomer(c.ID, custToLink.ID); custRepo.RemoveForeignNetworkForCustomer(c.ID, handle, type); } catch (Exception e) { System.Diagnostics.Trace.WriteLine("Onboard Exception: " + e.ToString()); } custRepo.Remove(c.ID); } custRepo.AddForeignNetworkForCustomer(custToLink.ID, handle, type); return true; }