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