public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens) { var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuth(); return dbFactory.Exec(dbCmd => { var oAuthProvider = dbCmd.FirstOrDefault<UserOAuthProvider>( "Provider = {0} AND UserId = {1}", tokens.Provider, tokens.UserId); if (oAuthProvider == null) { oAuthProvider = new UserOAuthProvider { Provider = tokens.Provider, UserId = tokens.UserId, }; } oAuthProvider.PopulateMissing(tokens); userAuth.PopulateMissing(oAuthProvider); dbCmd.Save(userAuth); oAuthProvider.UserAuthId = userAuth.Id != default(int) ? userAuth.Id : (int) dbCmd.GetLastInsertId(); dbCmd.Save(oAuthProvider); return oAuthProvider.UserAuthId.ToString(); }); }
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens) { using (var redis = factory.GetClient()) { UserOAuthProvider oAuthProvider = null; var oAuthProviderId = GetAuthProviderByUserId(redis, tokens.Provider, tokens.UserId); if (!oAuthProviderId.IsNullOrEmpty()) oAuthProvider = redis.As<UserOAuthProvider>().GetById(oAuthProviderId); var userAuth = GetUserAuth(redis, authSession, tokens) ?? new UserAuth { Id = redis.As<UserAuth>().GetNextSequence(), }; if (oAuthProvider == null) { oAuthProvider = new UserOAuthProvider { Id = redis.As<UserOAuthProvider>().GetNextSequence(), UserAuthId = userAuth.Id, Provider = tokens.Provider, UserId = tokens.UserId, }; var idx = IndexProviderToUserIdHash(tokens.Provider); redis.SetEntryInHash(idx, tokens.UserId, oAuthProvider.Id.ToString()); } oAuthProvider.PopulateMissing(tokens); userAuth.PopulateMissing(oAuthProvider); redis.Store(userAuth); redis.Store(oAuthProvider); redis.AddItemToSet(IndexUserAuthAndProviderIdsSet(userAuth.Id), oAuthProvider.Id.ToString()); return userAuth.Id.ToString(); } }
public void PopulateMissing(UserOAuthProvider authProvider) { if (!authProvider.FirstName.IsNullOrEmpty()) this.FirstName = authProvider.FirstName; if (!authProvider.LastName.IsNullOrEmpty()) this.LastName = authProvider.LastName; if (!authProvider.DisplayName.IsNullOrEmpty()) this.DisplayName = authProvider.DisplayName; if (!authProvider.Email.IsNullOrEmpty()) this.Email = authProvider.Email; }
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens) { var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuth(); using (var session = _documentStore.OpenSession()) { var oAuthProvider = session.Load<UserOAuthProvider>().FirstOrDefault(q => q.Provider == tokens.Provider && q.UserId == tokens.UserId); if (oAuthProvider == null) { oAuthProvider = new UserOAuthProvider { Provider = tokens.Provider, UserId = tokens.UserId, }; } oAuthProvider.PopulateMissing(tokens); userAuth.PopulateMissing(oAuthProvider); userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.CreatedDate == default(DateTime)) userAuth.CreatedDate = userAuth.ModifiedDate; session.Store(userAuth); session.SaveChanges(); //oAuthProvider.UserAuthId = userAuth.Id != default(int) // ? userAuth.Id // : (int)db.GetLastInsertId(); if (oAuthProvider.CreatedDate == default(DateTime)) oAuthProvider.CreatedDate = userAuth.ModifiedDate; oAuthProvider.ModifiedDate = userAuth.ModifiedDate; session.Store(oAuthProvider); session.SaveChanges(); return oAuthProvider.UserAuthId.ToString(CultureInfo.InvariantCulture); } }
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens) { var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuth(); return(dbFactory.Exec(dbCmd => { var oAuthProvider = dbCmd.Select <UserOAuthProvider>(q => q.Provider == tokens.Provider && q.UserId == tokens.UserId).FirstOrDefault(); if (oAuthProvider == null) { oAuthProvider = new UserOAuthProvider { Provider = tokens.Provider, UserId = tokens.UserId, }; } oAuthProvider.PopulateMissing(tokens); userAuth.PopulateMissing(oAuthProvider); userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.CreatedDate == default(DateTime)) { userAuth.CreatedDate = userAuth.ModifiedDate; } dbCmd.Save(userAuth); oAuthProvider.UserAuthId = userAuth.Id != default(int) ? userAuth.Id : (int)dbCmd.GetLastInsertId(); if (oAuthProvider.CreatedDate == default(DateTime)) { oAuthProvider.CreatedDate = userAuth.ModifiedDate; } oAuthProvider.ModifiedDate = userAuth.ModifiedDate; dbCmd.Save(oAuthProvider); return oAuthProvider.UserAuthId.ToString(CultureInfo.InvariantCulture); })); }
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens) { var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuth(); return dbFactory.Exec(dbCmd => { var oAuthProvider = dbCmd.Select<UserOAuthProvider>(q => q.Provider == tokens.Provider && q.UserId == tokens.UserId).FirstOrDefault(); if (oAuthProvider == null) { oAuthProvider = new UserOAuthProvider { Provider = tokens.Provider, UserId = tokens.UserId, }; } oAuthProvider.PopulateMissing(tokens); userAuth.PopulateMissing(oAuthProvider); userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.CreatedDate == default(DateTime)) userAuth.CreatedDate = userAuth.ModifiedDate; dbCmd.Save(userAuth); oAuthProvider.UserAuthId = userAuth.Id != default(int) ? userAuth.Id : (int)dbCmd.GetLastInsertId(); if (oAuthProvider.CreatedDate == default(DateTime)) oAuthProvider.CreatedDate = userAuth.ModifiedDate; oAuthProvider.ModifiedDate = userAuth.ModifiedDate; dbCmd.Save(oAuthProvider); return oAuthProvider.UserAuthId.ToString(CultureInfo.InvariantCulture); }); }
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens) { using (var redis = factory.GetClient()) { UserOAuthProvider oAuthProvider = null; var oAuthProviderId = GetAuthProviderByUserId(redis, tokens.Provider, tokens.UserId); if (!oAuthProviderId.IsNullOrEmpty()) { oAuthProvider = redis.As <UserOAuthProvider>().GetById(oAuthProviderId); } var userAuth = GetUserAuth(redis, authSession, tokens) ?? new UserAuth { Id = redis.As <UserAuth>().GetNextSequence(), }; if (oAuthProvider == null) { oAuthProvider = new UserOAuthProvider { Id = redis.As <UserOAuthProvider>().GetNextSequence(), UserAuthId = userAuth.Id, Provider = tokens.Provider, UserId = tokens.UserId, }; var idx = IndexProviderToUserIdHash(tokens.Provider); redis.SetEntryInHash(idx, tokens.UserId, oAuthProvider.Id.ToString()); } oAuthProvider.PopulateMissing(tokens); userAuth.PopulateMissing(oAuthProvider); redis.Store(userAuth); redis.Store(oAuthProvider); redis.AddItemToSet(IndexUserAuthAndProviderIdsSet(userAuth.Id), oAuthProvider.Id.ToString()); return(userAuth.Id.ToString()); } }
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens) { var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuth(); using (_session) { var oAuthProvider = _session .Query<ServiceStack_UserAuth_ByOAuthProvider.Result, ServiceStack_UserAuth_ByOAuthProvider>() .Customize(x => x.WaitForNonStaleResultsAsOfNow()) .Where(q => q.Provider == tokens.Provider && q.UserId == tokens.UserId) .OfType<UserOAuthProvider>() .FirstOrDefault(); if (oAuthProvider == null) { oAuthProvider = new UserOAuthProvider { Provider = tokens.Provider, UserId = tokens.UserId, }; } oAuthProvider.PopulateMissing(tokens); userAuth.PopulateMissing(oAuthProvider); userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.CreatedDate == default(DateTime)) userAuth.CreatedDate = userAuth.ModifiedDate; _session.Store(userAuth); _session.SaveChanges(); oAuthProvider.UserAuthId = userAuth.Id; if (oAuthProvider.CreatedDate == default(DateTime)) oAuthProvider.CreatedDate = userAuth.ModifiedDate; oAuthProvider.ModifiedDate = userAuth.ModifiedDate; _session.Store(oAuthProvider); _session.SaveChanges(); return oAuthProvider.UserAuthId.ToString(CultureInfo.InvariantCulture); } }
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens) { var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuth(); var query = Query.And( Query.EQ("Provider", tokens.Provider), Query.EQ("UserId", tokens.UserId) ); var providerCollection = mongoDatabase.GetCollection<UserOAuthProvider>("UserOAuthProvider"); var oAuthProvider = providerCollection.FindOne(query); if (oAuthProvider == null) { oAuthProvider = new UserOAuthProvider { Provider = tokens.Provider, UserId = tokens.UserId, }; } oAuthProvider.PopulateMissing(tokens); userAuth.PopulateMissing(oAuthProvider); userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.CreatedDate == default(DateTime)) userAuth.CreatedDate = userAuth.ModifiedDate; var userAuthCollection = mongoDatabase.GetCollection<UserAuth>("UserAuth"); userAuthCollection.Save(userAuth); oAuthProvider.UserAuthId = userAuth.Id; if (oAuthProvider.CreatedDate == default(DateTime)) oAuthProvider.CreatedDate = userAuth.ModifiedDate; oAuthProvider.ModifiedDate = userAuth.ModifiedDate; providerCollection.Save(oAuthProvider); return oAuthProvider.UserAuthId.ToString(CultureInfo.InvariantCulture); }
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens) { UserAuth userAuth = this.GetUserAuth(authSession, tokens) ?? new UserAuth(); IMongoQuery query = Query.And(Query.EQ("Provider", (BsonValue)tokens.Provider), Query.EQ("UserId", (BsonValue)tokens.UserId)); MongoCollection<UserOAuthProvider> collection = this.mongoDatabase.GetCollection<UserOAuthProvider>(CitySDKMongoDBAuthRepository.UserOAuthProvider_Col); UserOAuthProvider userOauthProvider = collection.FindOne(query); if (userOauthProvider == null) userOauthProvider = new UserOAuthProvider() { Provider = tokens.Provider, UserId = tokens.UserId }; userOauthProvider.PopulateMissing(tokens); userAuth.PopulateMissing(userOauthProvider); userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.CreatedDate == new DateTime()) userAuth.CreatedDate = userAuth.ModifiedDate; this.SaveUser(userAuth); if (userOauthProvider.Id == 0) userOauthProvider.Id = this.IncUserOAuthProviderCounter(); userOauthProvider.UserAuthId = userAuth.Id; if (userOauthProvider.CreatedDate == new DateTime()) userOauthProvider.CreatedDate = userAuth.ModifiedDate; userOauthProvider.ModifiedDate = userAuth.ModifiedDate; collection.Save(userOauthProvider); return userOauthProvider.UserAuthId.ToString((IFormatProvider)CultureInfo.InvariantCulture); }
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens) { var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuth(); var oAuthProvider = Session.QueryOver<UserOAuthProvider>() .Where(x => x.Provider == tokens.Provider) .And(x => x.UserId == tokens.UserId) .SingleOrDefault(); if (oAuthProvider == null) { oAuthProvider = new UserOAuthProvider { Provider = tokens.Provider, UserId = tokens.UserId, }; } oAuthProvider.PopulateMissing(tokens); userAuth.PopulateMissing(oAuthProvider); userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.CreatedDate == default(DateTime)) userAuth.CreatedDate = userAuth.ModifiedDate; Session.Save(new UserAuthPersistenceDto(userAuth)); oAuthProvider.UserAuthId = userAuth.Id; if (oAuthProvider.CreatedDate == default(DateTime)) oAuthProvider.CreatedDate = userAuth.ModifiedDate; oAuthProvider.ModifiedDate = userAuth.ModifiedDate; Session.Save(oAuthProvider); return oAuthProvider.UserAuthId.ToString(CultureInfo.InvariantCulture); }
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens) { UserAuth userAuth = this.GetUserAuth(authSession, tokens) ?? new UserAuth(); return OrmLiteConnectionFactoryExtensions.Run<string>(this.dbFactory, (Func<IDbConnection, string>) (db => { IDbConnection temp_16 = db; ParameterExpression local_2 = Expression.Parameter(typeof (UserOAuthProvider), "q"); // ISSUE: method reference // ISSUE: field reference // ISSUE: method reference // ISSUE: method reference // ISSUE: method reference // ISSUE: field reference // ISSUE: method reference // ISSUE: method reference Expression<Func<UserOAuthProvider, bool>> temp_66 = Expression.Lambda<Func<UserOAuthProvider, bool>>((Expression) Expression.AndAlso((Expression) Expression.Equal((Expression) Expression.Property((Expression) local_2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (UserOAuthProvider.get_Provider))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) this), FieldInfo.GetFieldFromHandle(__fieldref (OrmLiteAuthRepository.\u003C\u003Ec__DisplayClass24.tokens))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (IOAuthTokens.get_Provider))), false, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (string.op_Equality))), (Expression) Expression.Equal((Expression) Expression.Property((Expression) local_2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (UserOAuthProvider.get_UserId))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) this), FieldInfo.GetFieldFromHandle(__fieldref (OrmLiteAuthRepository.\u003C\u003Ec__DisplayClass24.tokens))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (IOAuthTokens.get_UserId))), false, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (string.op_Equality)))), new ParameterExpression[1] { local_2 }); UserOAuthProvider local_0 = Enumerable.FirstOrDefault<UserOAuthProvider>((IEnumerable<UserOAuthProvider>) ReadConnectionExtensions.Select<UserOAuthProvider>(temp_16, temp_66)); if (local_0 == null) local_0 = new UserOAuthProvider() { Provider = tokens.Provider, UserId = tokens.UserId }; local_0.PopulateMissing(tokens); userAuth.PopulateMissing(local_0); userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.CreatedDate == new DateTime()) userAuth.CreatedDate = userAuth.ModifiedDate; OrmLiteWriteConnectionExtensions.Save<UserAuth>(db, userAuth); local_0.UserAuthId = userAuth.Id != 0 ? userAuth.Id : (int) OrmLiteReadConnectionExtensions.GetLastInsertId(db); if (local_0.CreatedDate == new DateTime()) local_0.CreatedDate = userAuth.ModifiedDate; local_0.ModifiedDate = userAuth.ModifiedDate; OrmLiteWriteConnectionExtensions.Save<UserOAuthProvider>(db, local_0); return local_0.UserAuthId.ToString((IFormatProvider) CultureInfo.InvariantCulture); })); }
public virtual void PopulateMissing(UserOAuthProvider authProvider) { //Don't explicitly override after if values exist if (!authProvider.DisplayName.IsNullOrEmpty() && this.DisplayName.IsNullOrEmpty()) { this.DisplayName = authProvider.DisplayName; } if (!authProvider.Email.IsNullOrEmpty() && this.PrimaryEmail.IsNullOrEmpty()) { this.PrimaryEmail = authProvider.Email; } if (!authProvider.FirstName.IsNullOrEmpty()) { this.FirstName = authProvider.FirstName; } if (!authProvider.LastName.IsNullOrEmpty()) { this.LastName = authProvider.LastName; } if (!authProvider.FullName.IsNullOrEmpty()) { this.FullName = authProvider.FullName; } if (authProvider.BirthDate != null) { this.BirthDate = authProvider.BirthDate; } if (!authProvider.BirthDateRaw.IsNullOrEmpty()) { this.BirthDateRaw = authProvider.BirthDateRaw; } if (!authProvider.Country.IsNullOrEmpty()) { this.Country = authProvider.Country; } if (!authProvider.Culture.IsNullOrEmpty()) { this.Culture = authProvider.Culture; } if (!authProvider.Gender.IsNullOrEmpty()) { this.Gender = authProvider.Gender; } if (!authProvider.MailAddress.IsNullOrEmpty()) { this.MailAddress = authProvider.MailAddress; } if (!authProvider.Nickname.IsNullOrEmpty()) { this.Nickname = authProvider.Nickname; } if (!authProvider.PostalCode.IsNullOrEmpty()) { this.PostalCode = authProvider.PostalCode; } if (!authProvider.TimeZone.IsNullOrEmpty()) { this.TimeZone = authProvider.TimeZone; } }