public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens) { using (var uow = GetUnitOfWork()) { var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuth(); var oAuthProvider = uow.GetSession().QueryOver<UserOAuthProviderPersistenceDto>() .Where(x => x.Provider == tokens.Provider) .And(x => x.UserId == tokens.UserId) .SingleOrDefault(); if (oAuthProvider == null) { oAuthProvider = new UserOAuthProviderPersistenceDto { Provider = tokens.Provider, UserId = tokens.UserId, }; } oAuthProvider.PopulateMissing(tokens); userAuth.PopulateMissing(oAuthProvider); userAuth.Email = oAuthProvider.Email; userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.CreatedDate == default(DateTime)) userAuth.CreatedDate = userAuth.ModifiedDate; var userAuthId = 0; if (userAuth.Id == 0) { var camper = new Camper() {Email = userAuth.PrimaryEmail}; uow.Save(camper); var userAuthDto = new UserAuthPersistenceDto(userAuth); uow.Save(userAuthDto); userAuthId = userAuthDto.Id; } else { userAuthId = userAuth.Id; } //oAuthProvider.UserAuthId = userAuth.Id; oAuthProvider.UserAuthId = (int) userAuthId; if (oAuthProvider.CreatedDate == default(DateTime)) oAuthProvider.CreatedDate = userAuth.ModifiedDate; oAuthProvider.ModifiedDate = userAuth.ModifiedDate; uow.Save(oAuthProvider); uow.CommitTransaction(); return oAuthProvider.UserAuthId.ToString(CultureInfo.InvariantCulture); } }
public virtual BaseResponse HandleRequest(IAuthSession request) { int userAuthId = int.Parse(request.UserAuthId); ISession session = getSession(); var user = session.QueryOver <ServiceStackUser>() .JoinQueryOver(x => x.AuthenticatedUser) .Where(x => x.Id == userAuthId) .SingleOrDefault() ; if (user == null) //user doesn't exist yet, first time registration { UserAuthPersistenceDto auth = session.Get <UserAuthPersistenceDto>(userAuthId); user = new ServiceStackUser(auth); session.Save(user); } return(new BaseResponse()); }
public ServiceStackUser(UserAuthPersistenceDto userAuth) { AuthenticatedUser = userAuth; }