本文整理汇总了C#中IUserRepository.GetByUsername方法的典型用法代码示例。如果您正苦于以下问题:C# IUserRepository.GetByUsername方法的具体用法?C# IUserRepository.GetByUsername怎么用?C# IUserRepository.GetByUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUserRepository
的用法示例。
在下文中一共展示了IUserRepository.GetByUsername方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExampleSecureModule
public ExampleSecureModule(IUserRepository userRepo)
{
this.RequiresAuthentication();
this.Get["/api/examples/ambientContext"] = args =>
{
ICustomClaimsIdentity currentUser = AmbientContext.CurrentClaimsPrinciple.ClaimsIdentity;
string guid = currentUser.GetAttribute(AmbientContext.UserPrincipalGuidAttributeKey).ToString();
var user = userRepo.Get(guid);
user.Password = null;
return JsonConvert.SerializeObject(user);
//return 200;
};
this.Get["/api/examples/context"] = args =>
{
var currentUser = this.Context.CurrentUser;
string username = currentUser.UserName;
var user = userRepo.GetByUsername(username);
user.Password = null;
return JsonConvert.SerializeObject(user);
};
}
示例2: PreferencesController
public PreferencesController(IPreferenceRepository prefRepository,
IUserRepository userRepository,
IPreferenceServices prefServices)
{
_prefRepository = prefRepository;
_prefServices = prefServices;
User u = userRepository.GetByUsername(System.Web.HttpContext.Current.User.Identity.Name);
if (u == null) return;
_currentUserId = u.UserId;
}
示例3: ResolveUserByWindowsIdentity
private static User ResolveUserByWindowsIdentity(IUserRepository repository, WindowsIdentity windowsIdentity)
{
// 1. User is already registered by Windows identity
var user = repository.GetByUsername(windowsIdentity.Name);
if (user == null)
{
// 2. User is already registered, but not associated with a Windows identity
var email = UserPrincipal.Current.EmailAddress;
user = repository.GetByEmail(email);
if (user == null)
{
// 3. User is not registered, but is authenticated
user = repository.CreateFromWindowsIdentity(windowsIdentity);
}
else
{
// Associate registered user with this identity
user.Username = windowsIdentity.Name;
user.IsActivated = true;
}
repository.Save(user);
}
return user;
}