From 1dfdccb8118aeaa3cd844ac8de2a672c93312166 Mon Sep 17 00:00:00 2001 From: mokhan Date: Sat, 21 Feb 2009 21:44:27 +0000 Subject: git-svn-id: http://svn.xp-dev.com/svn/mokhan-sait@2 da190166-9cfc-4ee1-ae03-434a172be219 --- slips/src/app/Marina/Task/AuthenticationTask.cs | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 slips/src/app/Marina/Task/AuthenticationTask.cs (limited to 'slips/src/app/Marina/Task/AuthenticationTask.cs') diff --git a/slips/src/app/Marina/Task/AuthenticationTask.cs b/slips/src/app/Marina/Task/AuthenticationTask.cs new file mode 100644 index 0000000..75424a9 --- /dev/null +++ b/slips/src/app/Marina/Task/AuthenticationTask.cs @@ -0,0 +1,41 @@ +using Marina.Domain.Interfaces; +using Marina.Domain.Repositories; +using Marina.Presentation.DTO; +using Marina.Web.Http; + +namespace Marina.Task { + public class AuthenticationTask : IAuthenticationTask { + public AuthenticationTask( ICustomerRepository customers, IHttpGateway gateway ) { + _customers = customers; + _gateway = gateway; + } + + public DisplayResponseLineDTO AuthenticateUserUsing( LoginCredentialsDTO credentials ) { + if ( CheckIfPasswordMatches( credentials, _customers.FindBy( credentials.Username ) ) ) { + _gateway.AddAuthenticationCookieFor( credentials.Username, _customers.FindBy( credentials.Username ).ID( ) ); + return ValidCredentialsMessage( credentials.Username ); + } + else { + return InvalidCredentialsMessage( ); + } + } + + private static DisplayResponseLineDTO ValidCredentialsMessage( string username ) { + return new DisplayResponseLineDTO( string.Format( "Currently logged in as {0}", username ) ); + } + + private static DisplayResponseLineDTO InvalidCredentialsMessage() { + return new DisplayResponseLineDTO( "Invalid credentials specified" ); + } + + private static bool CheckIfPasswordMatches( LoginCredentialsDTO credentials, ICustomer customer ) { + if ( customer != null && customer.Registration( ) != null ) { + return customer.Registration( ).Password( ).Equals( credentials.Password ); + } + return false; + } + + private readonly ICustomerRepository _customers; + private readonly IHttpGateway _gateway; + } +} \ No newline at end of file -- cgit v1.2.3