Mercurial > altnet-hispano
annotate Agendas/trunk/src/Agendas.Web/Models/AccountModels.cs @ 130:0ea32a748453
Se termina el publicador via el calendario de google, además se realizan las pruebas unitarias.
author | alabra |
---|---|
date | Sun, 10 Jul 2011 18:50:11 -0400 |
parents | 1eb5a0e531bf |
children |
rev | line source |
---|---|
10 | 1 using System; |
2 using System.Collections.Generic; | |
3 using System.ComponentModel.DataAnnotations; | |
4 using System.Globalization; | |
5 using System.Web.Mvc; | |
6 using System.Web.Security; | |
7 | |
34
475be11edf56
Ajuste en los nombre de los assemblies y namespaces
nelo@MTEySS.neluz.int
parents:
10
diff
changeset
|
8 namespace AltNetHispano.Agendas.Web.Models |
10 | 9 { |
10 | |
11 #region Models | |
12 | |
13 public class ChangePasswordModel | |
14 { | |
15 [Required] | |
16 [DataType(DataType.Password)] | |
17 [Display(Name = "Current password")] | |
18 public string OldPassword { get; set; } | |
19 | |
20 [Required] | |
21 [ValidatePasswordLength] | |
22 [DataType(DataType.Password)] | |
23 [Display(Name = "New password")] | |
24 public string NewPassword { get; set; } | |
25 | |
26 [DataType(DataType.Password)] | |
27 [Display(Name = "Confirm new password")] | |
28 [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] | |
29 public string ConfirmPassword { get; set; } | |
30 } | |
31 | |
32 public class LogOnModel | |
33 { | |
34 [Required] | |
35 [Display(Name = "User name")] | |
36 public string UserName { get; set; } | |
37 | |
38 [Required] | |
39 [DataType(DataType.Password)] | |
40 [Display(Name = "Password")] | |
41 public string Password { get; set; } | |
42 | |
43 [Display(Name = "Remember me?")] | |
44 public bool RememberMe { get; set; } | |
45 } | |
46 | |
47 | |
48 public class RegisterModel | |
49 { | |
96
1eb5a0e531bf
Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents:
93
diff
changeset
|
50 [Required] |
1eb5a0e531bf
Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents:
93
diff
changeset
|
51 public string Nombre { get; set; } |
1eb5a0e531bf
Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents:
93
diff
changeset
|
52 |
1eb5a0e531bf
Funcionamiento con cuenta interna y con cuenta de twitter, falta unificar usuarios
Nelo@Kenia.neluz.int
parents:
93
diff
changeset
|
53 [Required] |
10 | 54 [Display(Name = "User name")] |
55 public string UserName { get; set; } | |
56 | |
57 [Required] | |
58 [DataType(DataType.EmailAddress)] | |
59 [Display(Name = "Email address")] | |
60 public string Email { get; set; } | |
61 | |
62 [Required] | |
63 [ValidatePasswordLength] | |
64 [DataType(DataType.Password)] | |
65 [Display(Name = "Password")] | |
66 public string Password { get; set; } | |
67 | |
68 [DataType(DataType.Password)] | |
69 [Display(Name = "Confirm password")] | |
70 [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] | |
71 public string ConfirmPassword { get; set; } | |
72 } | |
73 #endregion | |
74 | |
93 | 75 #region Validation |
10 | 76 public static class AccountValidation |
77 { | |
78 public static string ErrorCodeToString(MembershipCreateStatus createStatus) | |
79 { | |
80 // See http://go.microsoft.com/fwlink/?LinkID=177550 for | |
81 // a full list of status codes. | |
82 switch (createStatus) | |
83 { | |
84 case MembershipCreateStatus.DuplicateUserName: | |
85 return "Username already exists. Please enter a different user name."; | |
86 | |
87 case MembershipCreateStatus.DuplicateEmail: | |
88 return "A username for that e-mail address already exists. Please enter a different e-mail address."; | |
89 | |
90 case MembershipCreateStatus.InvalidPassword: | |
91 return "The password provided is invalid. Please enter a valid password value."; | |
92 | |
93 case MembershipCreateStatus.InvalidEmail: | |
94 return "The e-mail address provided is invalid. Please check the value and try again."; | |
95 | |
96 case MembershipCreateStatus.InvalidAnswer: | |
97 return "The password retrieval answer provided is invalid. Please check the value and try again."; | |
98 | |
99 case MembershipCreateStatus.InvalidQuestion: | |
100 return "The password retrieval question provided is invalid. Please check the value and try again."; | |
101 | |
102 case MembershipCreateStatus.InvalidUserName: | |
103 return "The user name provided is invalid. Please check the value and try again."; | |
104 | |
105 case MembershipCreateStatus.ProviderError: | |
106 return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator."; | |
107 | |
108 case MembershipCreateStatus.UserRejected: | |
109 return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator."; | |
110 | |
111 default: | |
112 return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator."; | |
113 } | |
114 } | |
115 } | |
116 | |
117 [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] | |
118 public sealed class ValidatePasswordLengthAttribute : ValidationAttribute, IClientValidatable | |
119 { | |
120 private const string _defaultErrorMessage = "'{0}' must be at least {1} characters long."; | |
121 private readonly int _minCharacters = Membership.Provider.MinRequiredPasswordLength; | |
122 | |
123 public ValidatePasswordLengthAttribute() | |
124 : base(_defaultErrorMessage) | |
125 { | |
126 } | |
127 | |
128 public override string FormatErrorMessage(string name) | |
129 { | |
130 return String.Format(CultureInfo.CurrentCulture, ErrorMessageString, | |
131 name, _minCharacters); | |
132 } | |
133 | |
134 public override bool IsValid(object value) | |
135 { | |
136 string valueAsString = value as string; | |
137 return (valueAsString != null && valueAsString.Length >= _minCharacters); | |
138 } | |
139 | |
140 public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) | |
141 { | |
142 return new[]{ | |
143 new ModelClientValidationStringLengthRule(FormatErrorMessage(metadata.GetDisplayName()), _minCharacters, int.MaxValue) | |
144 }; | |
145 } | |
146 } | |
147 #endregion | |
148 } |