本文整理汇总了C#中Microsoft.AspNet.Identity.UserLoginInfo类的典型用法代码示例。如果您正苦于以下问题:C# UserLoginInfo类的具体用法?C# UserLoginInfo怎么用?C# UserLoginInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserLoginInfo类属于Microsoft.AspNet.Identity命名空间,在下文中一共展示了UserLoginInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddLogin
public void AddLogin(IdentityUser user, UserLoginInfo login)
{
_db[_tables.UsersLogins].Insert(
LoginProvider: login.LoginProvider,
ProviderKey: login.ProviderKey,
UserId: user.Id);
}
示例2: RemoveLogin
public void RemoveLogin(IdentityUser user, UserLoginInfo login)
{
_db[_tables.UsersLogins].Delete(
UserId: user.Id,
LoginProvider: login.LoginProvider,
ProviderKey: login.ProviderKey);
}
示例3: Handler_ReturnsNullRemoteMembership_WhenNotFound_ByUserId
public void Handler_ReturnsNullRemoteMembership_WhenNotFound_ByUserId()
{
var userId = FakeData.Id();
var otherUserId = FakeData.Id(userId);
var loginProvider = FakeData.String();
var providerKey = FakeData.String();
var userLoginInfo = new UserLoginInfo(loginProvider, providerKey);
var remoteMemberships = new[]
{
new ProxiedRemoteMembership(loginProvider, providerKey)
{ UserId = otherUserId, },
new ProxiedRemoteMembership(FakeData.String(), FakeData.String())
{ UserId = userId, },
};
var data = remoteMemberships.AsQueryable();
var query = new RemoteMembershipByUser(userId, userLoginInfo);
var dbSet = new Mock<DbSet<RemoteMembership>>(MockBehavior.Strict).SetupDataAsync(data);
var entities = new Mock<IReadEntities>(MockBehavior.Strict);
var entitySet = new EntitySet<RemoteMembership>(dbSet.Object, entities.Object);
entities.Setup(x => x.Query<RemoteMembership>()).Returns(entitySet);
var handler = new HandleRemoteMembershipByUserQuery(entities.Object);
RemoteMembership result = handler.Handle(query).Result;
result.ShouldBeNull();
entities.Verify(x => x.Query<RemoteMembership>(), Times.Once);
}
示例4: Add_Should_Add_New_Login_Just_After_UserManager_CreateAsync_Get_Called
public async Task Add_Should_Add_New_Login_Just_After_UserManager_CreateAsync_Get_Called()
{
const string userName = "Tugberk";
const string loginProvider = "Twitter";
const string providerKey = "12345678";
using (IDocumentStore store = CreateEmbeddableStore())
{
using (IAsyncDocumentSession ses = store.OpenAsyncSession())
{
ses.Advanced.UseOptimisticConcurrency = true;
RavenUserStore<RavenUser> userStore = new RavenUserStore<RavenUser>(ses);
UserManager<RavenUser> userManager = new UserManager<RavenUser>(userStore);
RavenUser user = new RavenUser(userName);
UserLoginInfo loginToAdd = new UserLoginInfo(loginProvider, providerKey);
await userManager.CreateAsync(user);
await userManager.AddLoginAsync(user.Id, loginToAdd);
await ses.SaveChangesAsync();
}
using (IAsyncDocumentSession ses = store.OpenAsyncSession())
{
ses.Advanced.UseOptimisticConcurrency = true;
IUserLoginStore<RavenUser, string> userLoginStore = new RavenUserStore<RavenUser>(ses);
RavenUser user = await ses.LoadAsync<RavenUser>(RavenUser.GenerateKey(userName));
RavenUserLogin foundLogin = await ses.LoadAsync<RavenUserLogin>(RavenUserLogin.GenerateKey(loginProvider, providerKey));
// Assert
Assert.Equal(1, user.Logins.Count());
Assert.NotNull(foundLogin);
}
}
}
示例5: ByUserLoginInfoAsync
public static Task<RemoteMembership> ByUserLoginInfoAsync(this IQueryable<RemoteMembership> set,
UserLoginInfo userLoginInfo, bool allowNull = true)
{
return allowNull
? set.SingleOrDefaultAsync(ByUserLoginInfo(userLoginInfo))
: set.SingleAsync(ByUserLoginInfo(userLoginInfo));
}
示例6: AccountController
public AccountController()
: this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
{
var rm = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
try
{
if (!rm.RoleExists("admin"))
{
rm.Create(new IdentityRole("admin"));
var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var user = new ApplicationUser() { UserName = "adminn" };
um.Create(user, "asdfgh");
UserLoginInfo info = new UserLoginInfo("Google",
"https://www.google.com/accounts/o8/id?id=AItOawka6ZSrKNn7UY3ZUcjFRZMSLhMqQNKArWQ");
um.AddToRole(user.Id, "admin");
um.AddLogin(user.Id, info);
}
}
catch (TimeoutException)
{
//CreateAdmin();
}
}
示例7: AzureLogin
public AzureLogin(string ownerId, UserLoginInfo info)
: this()
{
UserId = ownerId;
LoginProvider = info.LoginProvider;
ProviderKey = info.ProviderKey;
}
示例8: CreateUserWithSocialProvider
public IdentityUser CreateUserWithSocialProvider(UserLoginInfo login, ClaimsIdentity identity)
{
var userProfile = _userProfileSocialService.GetFromSocialProvider(login.LoginProvider, identity);
var user = new IdentityUser(GenerateUserName())
{
Email = userProfile.Email
};
var userCreationResult = _userManager.Create(user);
if (userCreationResult.Succeeded)
{
var userLoginResult = _userManager.AddLogin(user.Id, login);
if (!userLoginResult.Succeeded)
{
foreach (var error in userLoginResult.Errors)
{
throw new Exception(error);
}
}
}
else
{
foreach (var error in userCreationResult.Errors)
{
throw new Exception(error);
}
}
userProfile.UserId = user.Id;
_userProfileRepository.Add(userProfile);
_userProfileRepository.SaveChanges();
return user;
}
示例9: UserLogin
/// <summary>
/// Create a new UserLogin for the specified info and user
/// </summary>
/// <param name="loginInfo">Information about the login</param>
/// <param name="userId">ID of the user the login is for</param>
public UserLogin(UserLoginInfo loginInfo, string userId)
{
LoginProvider = loginInfo.LoginProvider;
ProviderDisplayName = loginInfo.ProviderDisplayName;
ProviderKey = loginInfo.ProviderKey;
UserId = userId;
}
示例10: AreEqual
public static bool AreEqual(this UserLoginInfo thisObj, UserLoginInfo obj)
{
if (thisObj == null && obj == null) return true; // both objects are null
if (thisObj == null || obj == null) return false; // only one of the objects are null
return thisObj.LoginProvider.Equals(obj.LoginProvider, StringComparison.OrdinalIgnoreCase) &&
thisObj.ProviderKey.Equals(obj.ProviderKey, StringComparison.OrdinalIgnoreCase);
}
示例11: WhenHaveNoUser
public void WhenHaveNoUser()
{
var login = new UserLoginInfo("ProviderTest", "ProviderKey");
var store = new UserStore<IdentityUser>(_session);
var user = store.FindAsync(login).Result;
Assert.IsNull(user);
}
示例12: Equal
public static void Equal(UserLoginInfo expected, UserLoginInfo actual)
{
Assert.True((expected == null && actual == null) || (expected != null && actual != null));
Assert.Equal(expected.LoginProvider, actual.LoginProvider);
Assert.Equal(expected.ProviderKey, actual.ProviderKey);
Assert.Equal(expected.ProviderDisplayName, actual.ProviderDisplayName);
}
示例13: CanAddLogin
public void CanAddLogin()
{
var user = IdentityUserMother.EmptyUser();
var login = new UserLoginInfo("test", "testing");
user.AddLogin(login).ShouldBe(true);
user.Logins.ShouldContain(login);
}
示例14: CanCheckIfLoginExists
public void CanCheckIfLoginExists()
{
var user = IdentityUserMother.EmptyUser();
var login = new UserLoginInfo("test", "testing");
user.AddLogin(login).ShouldBe(true);
user.HasLogin(login).ShouldBe(true);
}
示例15: Should_return_null_if_user_not_found
public void Should_return_null_if_user_not_found()
{
var login = new UserLoginInfo("Yahoo", "ghi");
var task = _target.FindAsync(login);
task.Wait();
Assert.That(task.Result, Is.Null);
}