comparison Agendas/trunk/src/Agendas.Web/Services/AccountMembershipService.cs @ 93:65f0b3d70c18

Reordenando clases e interfaces
author Nelo@Kenia.neluz.int
date Sat, 04 Jun 2011 00:07:20 -0300
parents
children
comparison
equal deleted inserted replaced
92:7027cda13de3 93:65f0b3d70c18
1 using System;
2 using System.Web.Security;
3
4 namespace AltNetHispano.Agendas.Web.Services
5 {
6 public class AccountMembershipService : IMembershipService
7 {
8 private readonly MembershipProvider _provider;
9
10 public AccountMembershipService()
11 : this(null)
12 {
13 }
14
15 public AccountMembershipService(MembershipProvider provider)
16 {
17 _provider = provider ?? Membership.Provider;
18 }
19
20 public int MinPasswordLength
21 {
22 get
23 {
24 return _provider.MinRequiredPasswordLength;
25 }
26 }
27
28 public bool ValidateUser(string userName, string password)
29 {
30 if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
31 if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");
32
33 return _provider.ValidateUser(userName, password);
34 }
35
36 public MembershipCreateStatus CreateUser(string userName, string password, string email)
37 {
38 if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
39 if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");
40 if (String.IsNullOrEmpty(email)) throw new ArgumentException("Value cannot be null or empty.", "email");
41
42 MembershipCreateStatus status;
43 _provider.CreateUser(userName, password, email, null, null, true, null, out status);
44 return status;
45 }
46
47 public bool ChangePassword(string userName, string oldPassword, string newPassword)
48 {
49 if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
50 if (String.IsNullOrEmpty(oldPassword)) throw new ArgumentException("Value cannot be null or empty.", "oldPassword");
51 if (String.IsNullOrEmpty(newPassword)) throw new ArgumentException("Value cannot be null or empty.", "newPassword");
52
53 // The underlying ChangePassword() will throw an exception rather
54 // than return false in certain failure scenarios.
55 try
56 {
57 MembershipUser currentUser = _provider.GetUser(userName, true /* userIsOnline */);
58 return currentUser.ChangePassword(oldPassword, newPassword);
59 }
60 catch (ArgumentException)
61 {
62 return false;
63 }
64 catch (MembershipPasswordException)
65 {
66 return false;
67 }
68 }
69 }
70 }