/// <summary> /// Gets the local user id for an oauth user id and provider /// </summary> public int? GetLocalUserIdFromOAuthUserInfo(OAuthUserInfo oAuthUserInfo) { return this.Repository.GetSet<UserOAuthUserId>() .Where(x => x.OAuthProviderId == (int)oAuthUserInfo.SourceProvider) .Where(x => x.OAuthUserId == oAuthUserInfo.OAuthUserId) .Select(x => x.UserId) .Cast<int?>() .FirstOrDefault(); }
/// <summary> /// Connects a local user to an oauthprovider /// </summary> public void ConnectLocalUserToOAuthProvider(int userId, OAuthUserInfo oAuthUserInfo) { var userOAuthUserId = new UserOAuthUserId { UserId = userId, OAuthProviderId = (int)oAuthUserInfo.SourceProvider, OAuthUserId = oAuthUserInfo.OAuthUserId }; this.Repository.Add(userOAuthUserId); }
/// <summary> /// Registers a new user using OAuth Info /// </summary> public User RegisterNewUser(OAuthUserInfo oAuthUserInfo) { if (oAuthUserInfo == null) { throw new ArgumentNullException("oAuthUserInfo"); } var user = Mapper.Map(oAuthUserInfo, new User()); user.Password = this.Hasher.Hash(Guid.NewGuid().ToString()); user.IsActive = true; user.DateCreated = DateTime.Now; user.Username = Guid.NewGuid().ToString().Replace("-", ""); user.HasCustomUsername = false; // Connect the User user.UserOAuthUserIds = new List<UserOAuthUserId> { new UserOAuthUserId { OAuthProviderId = (int) oAuthUserInfo.SourceProvider, OAuthUserId = oAuthUserInfo.OAuthUserId } }; this.UserService.SubscribeUserToDefaultNotifications(user); this.Repository.Add(user); return user; }