private async Task <FactorsCredentialCreationResult> CreatePhoneCredentialAsync(IFactorsApplication instance, string credentialKey, bool runAsAsync, params KeyValuePair <string, string>[] parameters) { // // Sets up our return model on the event of a successful // credential creation // var credentialResult = new FactorsCredentialCreationResult { IsSuccess = true, VerificationMessageSent = true, Message = "Account registered as pending verification, validation token sent", }; // // Creates the new "pending verification" credential // var credentailDetails = new FactorsCredential { UserAccountId = instance.UserAccount, FeatureTypeGuid = _featureType.FeatureGuid, CredentialKey = credentialKey }; try { credentialResult.CredentailDetails = runAsAsync ? await instance.Configuration.StorageDatabase.CreateCredentialAsync(credentailDetails).ConfigureAwait(false) : instance.Configuration.StorageDatabase.CreateCredential(credentailDetails); } catch (Exception ex) { return(new FactorsCredentialCreationResult { IsSuccess = false, VerificationMessageSent = false, Message = $"There was an issue when creating the credential: {ex.Message}" }); } var sendTokenResult = runAsAsync ? await this.BeginTokenRequestAsync(instance, credentialKey, parameters).ConfigureAwait(false) : this.BeginTokenRequest(instance, credentialKey, parameters); if (!sendTokenResult.IsSuccess) { return(new FactorsCredentialCreationResult { IsSuccess = false, Message = sendTokenResult.Message }); } // // And finally return our result // credentialResult.TokenDetails = sendTokenResult.TokenDetails; return(credentialResult); }
private async Task <FactorsCredential> CreateCredentialAsync(FactorsCredential model, bool runAsAsync) { // // Fill out the basic model details // model.Id = 0; model.CreatedDateUtc = DateTime.UtcNow; model.ModifiedDateUtc = DateTime.UtcNow; model.CredentialIsValidated = false; using (var db = (runAsAsync ? await _dbConnection.OpenAsync().ConfigureAwait(false) : _dbConnection.Open())) { // // Check to see if the credential already exists in the database // var hasExistingCredential = runAsAsync ? await db.ExistsAsync <FactorsCredential>(fc => fc.UserAccountId == model.UserAccountId && fc.FeatureTypeGuid == model.FeatureTypeGuid && fc.CredentialKey == model.CredentialKey ) .ConfigureAwait(false) : db.Exists <FactorsCredential>(fc => fc.UserAccountId == model.UserAccountId && fc.FeatureTypeGuid == model.FeatureTypeGuid && fc.CredentialKey == model.CredentialKey ); // // If it is an existing credential exit out // if (hasExistingCredential) { throw new Exception("Credential already exists in database for specified user"); } // // If not, let's add it // var credentialId = runAsAsync ? await db.InsertAsync(model, selectIdentity : true).ConfigureAwait(false) : db.Insert(model, selectIdentity: true); model.Id = credentialId; return(model); } }
public Task <FactorsCredential> CreateCredentialAsync(FactorsCredential model) { return(this.CreateCredentialAsync(model, true)); }
public FactorsCredential CreateCredential(FactorsCredential model) { return(this.CreateCredentialAsync(model, false).GetAwaiter().GetResult()); }