Mercurial > altnet-hispano
annotate Agendas/trunk/src/Agendas.Web/Models/AccountModels.cs @ 93:65f0b3d70c18
Reordenando clases e interfaces
author | Nelo@Kenia.neluz.int |
---|---|
date | Sat, 04 Jun 2011 00:07:20 -0300 |
parents | 475be11edf56 |
children | 1eb5a0e531bf |
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 { | |
50 [Required] | |
51 [Display(Name = "User name")] | |
52 public string UserName { get; set; } | |
53 | |
54 [Required] | |
55 [DataType(DataType.EmailAddress)] | |
56 [Display(Name = "Email address")] | |
57 public string Email { get; set; } | |
58 | |
59 [Required] | |
60 [ValidatePasswordLength] | |
61 [DataType(DataType.Password)] | |
62 [Display(Name = "Password")] | |
63 public string Password { get; set; } | |
64 | |
65 [DataType(DataType.Password)] | |
66 [Display(Name = "Confirm password")] | |
67 [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] | |
68 public string ConfirmPassword { get; set; } | |
69 } | |
70 #endregion | |
71 | |
93 | 72 #region Validation |
10 | 73 public static class AccountValidation |
74 { | |
75 public static string ErrorCodeToString(MembershipCreateStatus createStatus) | |
76 { | |
77 // See http://go.microsoft.com/fwlink/?LinkID=177550 for | |
78 // a full list of status codes. | |
79 switch (createStatus) | |
80 { | |
81 case MembershipCreateStatus.DuplicateUserName: | |
82 return "Username already exists. Please enter a different user name."; | |
83 | |
84 case MembershipCreateStatus.DuplicateEmail: | |
85 return "A username for that e-mail address already exists. Please enter a different e-mail address."; | |
86 | |
87 case MembershipCreateStatus.InvalidPassword: | |
88 return "The password provided is invalid. Please enter a valid password value."; | |
89 | |
90 case MembershipCreateStatus.InvalidEmail: | |
91 return "The e-mail address provided is invalid. Please check the value and try again."; | |
92 | |
93 case MembershipCreateStatus.InvalidAnswer: | |
94 return "The password retrieval answer provided is invalid. Please check the value and try again."; | |
95 | |
96 case MembershipCreateStatus.InvalidQuestion: | |
97 return "The password retrieval question provided is invalid. Please check the value and try again."; | |
98 | |
99 case MembershipCreateStatus.InvalidUserName: | |
100 return "The user name provided is invalid. Please check the value and try again."; | |
101 | |
102 case MembershipCreateStatus.ProviderError: | |
103 return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator."; | |
104 | |
105 case MembershipCreateStatus.UserRejected: | |
106 return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator."; | |
107 | |
108 default: | |
109 return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator."; | |
110 } | |
111 } | |
112 } | |
113 | |
114 [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] | |
115 public sealed class ValidatePasswordLengthAttribute : ValidationAttribute, IClientValidatable | |
116 { | |
117 private const string _defaultErrorMessage = "'{0}' must be at least {1} characters long."; | |
118 private readonly int _minCharacters = Membership.Provider.MinRequiredPasswordLength; | |
119 | |
120 public ValidatePasswordLengthAttribute() | |
121 : base(_defaultErrorMessage) | |
122 { | |
123 } | |
124 | |
125 public override string FormatErrorMessage(string name) | |
126 { | |
127 return String.Format(CultureInfo.CurrentCulture, ErrorMessageString, | |
128 name, _minCharacters); | |
129 } | |
130 | |
131 public override bool IsValid(object value) | |
132 { | |
133 string valueAsString = value as string; | |
134 return (valueAsString != null && valueAsString.Length >= _minCharacters); | |
135 } | |
136 | |
137 public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) | |
138 { | |
139 return new[]{ | |
140 new ModelClientValidationStringLengthRule(FormatErrorMessage(metadata.GetDisplayName()), _minCharacters, int.MaxValue) | |
141 }; | |
142 } | |
143 } | |
144 #endregion | |
145 } |