本文整理汇总了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 );
};
}
示例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 );
};
}