ravendb / ravendb.contrib

External Contributions to RavenDB
http://ravendb.net
MIT License
30 stars 14 forks source link

Associate oauth client with existing account - error #23

Closed vindberg closed 8 years ago

vindberg commented 11 years ago

Sequence contains more than one element

Line 278:            using (var db = _store.OpenSession())
Line 279:            {
Line 280:                var user = db.Query<Account>()
Line 281:                             .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite())
Line 282:                             .SingleOrDefault(a => a.UserName == userName);
vindberg commented 11 years ago

Suggested solution:

In the AuthProvider add:

        public void CreateExternalAccount(string userName, string identifier, string providerName)
        {
...
                var queryExistingUser = db.Query<Account>()
                              .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite())
                              .Where(a => a.UserName == userName);

                if (queryExistingUser.Any())
                    throw new DuplicateUserNameException(userName);

...

And then add appropriate try catch in the ExternalLoginConfirmation action in AccountController. :+1:

CMircea commented 11 years ago

Hi!

Thanks for the report!

Unfortunately I've been extremely busy the last couple of months and haven't been able to do any work on the auth providers. I'd love a pull request, that would be great.