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


C# IDatabase.GetUserCredentialsByUserId方法代码示例

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


在下文中一共展示了IDatabase.GetUserCredentialsByUserId方法的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: UserProfileModule

        public UserProfileModule( IDatabase database, IPasswordEncryptor passwordEncryptor )
            : base(database)
        {
            this.passwordEncryptor = passwordEncryptor;

            this.RequiresAuthentication();

            Get[Route.UserProfile] = o =>
            {
                return View[Route.UserProfile];
            };

            Get[Route.ChangePassword] = o =>
            {
                return View[Route.ChangePassword];
            };

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

                var user = this.CurrentUser;

                try
                {
                    var userCredentials = database.GetUserCredentialsByUserId( user.Id );

                    if ( string.IsNullOrWhiteSpace( request.CurrentPassword ) )
                    {
                        throw new Exception( "Incorrect password" );
                    }

                    if ( passwordEncryptor.Encrypt( request.CurrentPassword ) != userCredentials.EncryptedPassword )
                    {
                        throw new Exception( "Incorrect password" );
                    }

                    if ( request.NewPassword1 != request.NewPassword2 )
                    {
                        throw new Exception( "Passwords don't match" );
                    }

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

                    userCredentials.EncryptedPassword = passwordEncryptor.Encrypt( request.NewPassword1 );

                    database.UpdateUserCredentials( userCredentials );
                }
                catch ( Exception ex )
                {
                    this.AddUserMessage( ex.Message );
                    return View[Route.ChangePassword];
                }

                this.AddUserMessage( "Your password has been changed" );
                return View[Route.UserProfile];
            };

            Get[Route.SelectGames] = o =>
            {
                var model = new SelectGamesViewModel();

                var availableGames = database.GetGames();
                var gamesPlayedByUser = database.GetGamesPlayedByUser( ((UserIdentity)Context.CurrentUser).UserId );

                foreach ( var availableGame in availableGames )
                {
                    model.SelectableGames.Add( new Selectable<Game>
                    {
                        Item = availableGame,
                        IsSelected = gamesPlayedByUser.Any( game => game.Id == availableGame.Id )
                    } );
                }

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

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

                database.SetGamesPlayedByUser(((UserIdentity)Context.CurrentUser).UserId, request.GameIds);

                return Response.AsRedirect( Route.Home );
            };
        }
开发者ID:Breeto,项目名称:MatchMaker,代码行数:90,代码来源:UserProfileModule.cs


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