当前位置: 首页>>代码示例>>C#>>正文


C# IUserRepository.GetByUsername方法代码示例

本文整理汇总了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);
            };
        }
开发者ID:pomonav,项目名称:Heinz95729,代码行数:27,代码来源:ExampleSecureModule.cs

示例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;
        }
开发者ID:BeefboosterDevelopment,项目名称:beefbooster.public,代码行数:11,代码来源:PreferencesController.cs

示例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;
 }
开发者ID:ehsan-davoudi,项目名称:webstack,代码行数:24,代码来源:Cohort.UserManagement.cs


注:本文中的IUserRepository.GetByUsername方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。