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