本文整理汇总了C#中IUserManager.CreateUser方法的典型用法代码示例。如果您正苦于以下问题:C# IUserManager.CreateUser方法的具体用法?C# IUserManager.CreateUser怎么用?C# IUserManager.CreateUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUserManager
的用法示例。
在下文中一共展示了IUserManager.CreateUser方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AuthModule
public AuthModule(ILogger<AuthModule> logger,
IUserManager userManager,
ITokenizer tokenizer)
: base("auth")
{
Get["/setup"] = _ => !userManager.HasUsers();
Post["/login"] = _ =>
{
var userData = this.Bind<UserDto>();
// First login creates user
if (!userManager.HasUsers())
{
logger.Info("Creating user account {UserName}.", userData.UserName);
userManager.CreateUser(userData.UserName, userData.Password);
}
var user = userManager.GetUser(userData.UserName, userData.Password);
if (user == null)
{
logger.Warn("Invalid username/password: {UserName}.", userData.UserName);
return HttpStatusCode.Unauthorized;
}
var identity = new UserIdentity(user.UserName, user.Claims);
var token = tokenizer.Tokenize(identity, Context);
return new
{
Token = token
};
};
}
示例2: Initialize
public void Initialize() {
playlistManager = new PlaylistManager(new PlaylistRepository(new EFDbContext(ContextEnum.BeatBuddyTest)), new UserRepository(new EFDbContext(ContextEnum.BeatBuddyTest)));
userManager = new UserManager(new UserRepository(new EFDbContext(ContextEnum.BeatBuddyTest)));
user = userManager.CreateUser("[email protected]", "matthias", "test", "acidshards", "");
playlist = playlistManager.CreatePlaylistForUser("testplaylist", "gekke playlist om te testen", "125", 5, true, "", user);
trackProvider = new YouTubeTrackProvider();
albumArtProvider = new BingAlbumArtProvider();
playlistControllerWithAuthenticatedUser = MyWebApi.Controller<PlaylistController>()
.WithResolvedDependencyFor<IPlaylistManager>(playlistManager)
.WithResolvedDependencyFor<IUserManager>(userManager)
.WithResolvedDependencyFor<ITrackProvider>(trackProvider)
.WithResolvedDependencyFor<IAlbumArtProvider>(albumArtProvider)
.WithAuthenticatedUser(
u => u.WithIdentifier("NewId")
.WithUsername(user.Email)
.WithClaim(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Email, user.Email))
.WithClaim(new System.Security.Claims.Claim("sub", user.Email))
);
Track metallicaTrack = new Track()
{
Artist = "Metallica",
Title = "Master of Puppets (live)",
CoverArtUrl = "",
Duration = 800,
TrackSource = new TrackSource
{
SourceType = SourceType.YouTube,
Url = "https://www.youtube.com/watch?v=kV-2Q8QtCY4",
TrackId = "kV-2Q8QtCY4"
}
};
Track nickelbackTrack = new Track()
{
Artist = "Nickelback",
Title = "How You Remind Me",
CoverArtUrl = "",
Duration = 400,
TrackSource = new TrackSource
{
SourceType = SourceType.YouTube,
Url = "https://www.youtube.com/watch?v=1cQh1ccqu8M",
TrackId = "1cQh1ccqu8M"
}
};
_addedMetallicaTrack = playlistManager.AddTrackToPlaylist(playlist.Id, metallicaTrack);
_addedNickelbackTrack = playlistManager.AddTrackToPlaylist(playlist.Id, nickelbackTrack);
}
示例3: Create
public static ContainerUser Create(IUserManager userManager, string containerId)
{
var credentials = userManager.CreateUser(BuildContainerUserName(containerId));
return new ContainerUser(userManager, credentials);
}