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


C# IUserRepository.GetByUserName方法代码示例

本文整理汇总了C#中IUserRepository.GetByUserName方法的典型用法代码示例。如果您正苦于以下问题:C# IUserRepository.GetByUserName方法的具体用法?C# IUserRepository.GetByUserName怎么用?C# IUserRepository.GetByUserName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IUserRepository的用法示例。


在下文中一共展示了IUserRepository.GetByUserName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RequestInfoModule

 public RequestInfoModule(IUserRepository userRepository)
 {
     Get["/RequestInfo/{username}"] = _ =>
     {
         //var user = userRepository.Get(Context.CurrentUser.UserName);
         var user = userRepository.GetByUserName(_.username);
         return user == null ? null : Mapper.Map<User, RequestInfoDto>(user);
     };
 }
开发者ID:rjonker1,项目名称:lightstone-data-platform,代码行数:9,代码来源:RequestInfoModule.cs

示例2: MetaDetailModule

        public MetaDetailModule(IUserRepository userRepository)
        {
            Get["/Meta/User/{username}"] = parameters =>
            {
                var username = (String) parameters.username;
                var dto = Mapper.Map<User, MetaDetailDto>(userRepository.GetByUserName(username));

                return Response.AsJson(dto);
            };
        }
开发者ID:rjonker1,项目名称:lightstone-data-platform,代码行数:10,代码来源:MetaDetailModule.cs

示例3: TestInitialize

		public void TestInitialize()
		{
			mocks = new MockRepository();
			smsSender = mocks.CreateMock<ISmsSender>();

			user = new User("sally", "1234");

			userRepository = mocks.Stub<IUserRepository>();
			SetupResult.For(userRepository.GetByUserName("sally"))
				.Return(user);
		}
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:11,代码来源:RhinoMocks101.cs

示例4: AuthModule

        public AuthModule(IUmAuthenticator authenticator, IUserRepository userRepository, ITokenizer tokenizer, IBus bus)
        {
            //Post["/authenticate"] = parameters =>
            //{
            //    _log.InfoFormat("authenticate");

            //    //var token = Context.AuthorizationHeaderToken();
            //    var token = tokenizer.Tokenize(userIdentity, Context);

            //    return string.IsNullOrWhiteSpace(token) ? Response.AsJson((string)null) : Response.AsJson(authenticator.GetUserIdentity(token));
            //};

            Post["/login"] = parameters =>
            {
                var username = Context.Request.Headers["Username"].FirstOrDefault();
                var password = Context.Request.Headers["Password"].FirstOrDefault();
                var userIdentity = authenticator.GetUserIdentity(username, password);

                //foreach (var roleValue in userIdentity.Claims)
                //{
                //    var role = roles.Where(r => r.Value == roleValue);
                //}

                //.Where(x => x.Roles.Select(r => r.Value == "AccountOwner").FirstOrDefault());

                if (userIdentity != null)
                {
                    var user = userRepository.GetByUserName(userIdentity.UserName);
                    if (user != null)
                    {
                        var userType = user.UserType;
                        if (userType != UserType.Internal)
                        {
                            userIdentity = null;
                            this.Error(() => "Log in attempt failed: User {0}, ActionedUserType: {1}".FormatWith(username, userType));
                        }
                    }
                }

                return userIdentity == null
                    ? HttpStatusCode.Unauthorized
                    : Response.AsText(tokenizer.Tokenize(userIdentity, Context));
            };

            Post["/login/api"] = parameters =>
            {
                var username = Context.Request.Headers["Username"].FirstOrDefault();
                var password = Context.Request.Headers["Password"].FirstOrDefault();
                var userIdentity = authenticator.GetUserIdentity(username, password);

                this.Info(() => "UserIdentity: {0}, log in attempt".FormatWith(userIdentity));

                if (userIdentity != null)
                {
                    var user = userRepository.GetByUserName(userIdentity.UserName);
                    if (user != null)
                    {
                        var userType = user.UserType;
                        if (userType != UserType.Internal && userType != UserType.External)
                        {
                            userIdentity = null;
                            this.Error(() => "Log in attempt failed: User {0}, ActionedUserType: {1}".FormatWith(username, userType));
                        }
                    }
                }

                return userIdentity == null
                    ? HttpStatusCode.Unauthorized
                    : Response.AsText(tokenizer.Tokenize(userIdentity, Context));
            };

            Put[UserManagementApiRoute.User.RequestResetPassword] = _ =>
            {
                var username = (string)(_.username + "");
                var entity = userRepository.GetByUserName(username);
                if (entity == null) throw new LightstoneAutoException("Could not find username {0}".FormatWith(username));
                var token = entity.AssignResetPasswordToken();
                var url = ConfigurationManager.AppSettings["LiveAutoBaseUrl"] + LiveAutoApiRoute.Authorization.GetChangePassword.Replace("{token}", token + "");
                var body = "<a href='{0}'>Please click here to navigate to the change password web page</a>".FormatWith(url);
                
                bus.Publish(new CreateUpdateEntity(entity, "Update"));
                bus.Publish(new EmailMessage(new[] { entity.UserName }, "LIVE Auto password reset", body));

                return Response.AsText("Password reset mail sent");
            };

            Put[UserManagementApiRoute.User.ResetPassword] = _ =>
            {
                var model = this.Bind<ResetPasswordDto>();

                var token = (Guid)_.token;
                if (token == new Guid()) throw new ArgumentException();

                var user = userRepository.GetByResetToken(token);
                user.HashPassword(model.Password);
                user.ClearResetPasswordToken();

                return Response.AsText("Password changed");
            };
        }
开发者ID:rjonker1,项目名称:lightstone-data-platform,代码行数:100,代码来源:AuthModule.cs


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