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


C# IDatabase.GetUserByName方法代码示例

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


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

示例1: AuthenticationModule

        public AuthenticationModule( IDatabase database, IPasswordEncryptor passwordEncryptor )
        {
            Get[Route.Login] = o => View[Route.Login, new LoginRequest()];

            Post[Route.Login] = o =>
            {
                var request = this.Bind<LoginRequest>();

                try
                {
                    // TODO: Use validation attributes, or call Validate on LoginRequest

                    if ( string.IsNullOrWhiteSpace(request.UserName) || string.IsNullOrWhiteSpace(request.Password) )
                    {
                        throw new Exception("Username and password are required");
                    }

                    var user = database.GetUserByName( request.UserName );

                    if ( null == user )
                    {
                        throw new Exception( LoginFailureMessage );
                    }

                    var credentials = database.GetUserCredentialsByUserId( user.Id );

                    if ( passwordEncryptor.Encrypt(request.Password) != credentials.EncryptedPassword )
                    {
                        throw new Exception( LoginFailureMessage );
                    }

                    var expiry = DateTime.MaxValue;

                    return this.LoginAndRedirect( credentials.AuthId, expiry, Route.Home );
                }
                catch ( Exception exception )
                {
                    this.AddUserMessage(exception.Message);

                    return View[Route.Login, request];
                }
            };

            Get[Route.Logout] = o =>
            {
            //				this.AddUserMessage("You have been logged out");

                return this.LogoutAndRedirect( Route.Login );
            };
        }
开发者ID:Breeto,项目名称:MatchMaker,代码行数:50,代码来源:AuthenticationModule.cs

示例2: RegistrationModule

        public RegistrationModule( IDatabase database, IEmailAddressFormatValidator emailAddressFormatValidator, IPasswordEncryptor passwordEncryptor )
        {
            this.database = database;
            this.passwordEncryptor = passwordEncryptor;

            Get[Route.Register] = o =>
            {
                var model = new RegistrationRequest();

                return View[Route.Register, model];
            };

            Post[Route.Register] = o =>
            {
                RegistrationRequest request = this.Bind<RegistrationRequest>();

                try
                {
                    if ( string.IsNullOrWhiteSpace(request.UserName) || !App.Settings.UserNameSizeRange.Contains( request.UserName.Length ) )
                    {
                        throw new Exception( string.Format( "User name must be between {0} and {1} characters long", App.Settings.UserNameSizeRange.Min, App.Settings.UserNameSizeRange.Max ) );
                    }

                    if ( !request.UserName.IsAlphanumeric() )
                    {
                        throw new Exception( "User name can contain only alphanumeric characters" );
                    }

                    if ( null != database.GetUserByName( request.UserName ) )
                    {
                        throw new Exception("An account with that name already exists");
                    }

            //					if ( !emailAddressFormatValidator.IsValidFormat(request.EmailAddress) )
            //					{
            //						throw new Exception("Invalid email address");
            //					}
            //
            //					if ( null != database.GetUserCredentialsByEmailAddress( request.EmailAddress ) )
            //					{
            //						throw new Exception("That email address is already in use");
            //					}

                    var result = PasswordValidator.Validate( request.Password1 );
                    if ( !result.IsValid )
                    {
                        throw new Exception( string.Join( ", ", result.ValidationErrors ) );
                    }

                    if ( request.Password1 != request.Password2 )
                    {
                        throw new Exception( "Passwords do not match" );
                    }

                    AddUserFor( request );
                }
                catch ( Exception e )
                {
                    this.AddUserMessage(e.Message);
                    return View[Route.Register, request];
                }

                this.AddUserMessage("Registration successful");
                return Response.AsRedirect( Route.SelectGames );
            };
        }
开发者ID:Breeto,项目名称:MatchMaker,代码行数:66,代码来源:RegistrationModule.cs


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