annotate Agendas/trunk/src/Agendas.Web/Services/AccountMembershipService.cs @ 115:7a2eeb9e9bf9

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