diff options
| author | mokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219> | 2009-02-21 21:44:27 +0000 |
|---|---|---|
| committer | mokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219> | 2009-02-21 21:44:27 +0000 |
| commit | 1dfdccb8118aeaa3cd844ac8de2a672c93312166 (patch) | |
| tree | 4b19e7f816ab1019f180a46b68572af4b66fe4bc /slips/src/app/Marina/Task/AuthenticationTask.cs | |
| parent | 42d66bcab8262c7b8b2452615df535e694a3ec1c (diff) | |
git-svn-id: http://svn.xp-dev.com/svn/mokhan-sait@2 da190166-9cfc-4ee1-ae03-434a172be219
Diffstat (limited to 'slips/src/app/Marina/Task/AuthenticationTask.cs')
| -rw-r--r-- | slips/src/app/Marina/Task/AuthenticationTask.cs | 41 |
1 files changed, 41 insertions, 0 deletions
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 |
