annotate Agendas/trunk/src/Agendas.Web/Models/AccountModels.cs @ 110:a456eb519e23

Lanzando twitts desde el sitio con la cuenta de AltNetHispanoDESA
author Nelo@Kenia.neluz.int
date Wed, 08 Jun 2011 07:33:14 -0300
parents 1eb5a0e531bf
children
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 {
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
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
54 [Display(Name = "User name")]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
55 public string UserName { get; set; }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
56
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
57 [Required]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
58 [DataType(DataType.EmailAddress)]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
59 [Display(Name = "Email address")]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
60 public string Email { get; set; }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
61
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
62 [Required]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
63 [ValidatePasswordLength]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
64 [DataType(DataType.Password)]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
65 [Display(Name = "Password")]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
66 public string Password { get; set; }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
67
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
68 [DataType(DataType.Password)]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
69 [Display(Name = "Confirm password")]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
70 [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
71 public string ConfirmPassword { get; set; }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
72 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
73 #endregion
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
74
93
65f0b3d70c18 Reordenando clases e interfaces
Nelo@Kenia.neluz.int
parents: 34
diff changeset
75 #region Validation
10
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
76 public static class AccountValidation
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
77 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
78 public static string ErrorCodeToString(MembershipCreateStatus createStatus)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
79 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
80 // See http://go.microsoft.com/fwlink/?LinkID=177550 for
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
81 // a full list of status codes.
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
82 switch (createStatus)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
83 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
84 case MembershipCreateStatus.DuplicateUserName:
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
85 return "Username already exists. Please enter a different user name.";
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
86
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
87 case MembershipCreateStatus.DuplicateEmail:
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
88 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
89
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
90 case MembershipCreateStatus.InvalidPassword:
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
91 return "The password provided is invalid. Please enter a valid password value.";
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
92
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
93 case MembershipCreateStatus.InvalidEmail:
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
94 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
95
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
96 case MembershipCreateStatus.InvalidAnswer:
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
97 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
98
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
99 case MembershipCreateStatus.InvalidQuestion:
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
100 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
101
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
102 case MembershipCreateStatus.InvalidUserName:
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
103 return "The user name provided is invalid. Please check the value and try again.";
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
104
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
105 case MembershipCreateStatus.ProviderError:
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
106 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
107
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
108 case MembershipCreateStatus.UserRejected:
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
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.";
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
110
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
111 default:
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
112 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
113 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
114 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
115 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
116
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
117 [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
118 public sealed class ValidatePasswordLengthAttribute : ValidationAttribute, IClientValidatable
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
119 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
120 private const string _defaultErrorMessage = "'{0}' must be at least {1} characters long.";
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
121 private readonly int _minCharacters = Membership.Provider.MinRequiredPasswordLength;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
122
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
123 public ValidatePasswordLengthAttribute()
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
124 : base(_defaultErrorMessage)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
125 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
126 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
127
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
128 public override string FormatErrorMessage(string name)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
129 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
130 return String.Format(CultureInfo.CurrentCulture, ErrorMessageString,
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
131 name, _minCharacters);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
132 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
133
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
134 public override bool IsValid(object value)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
135 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
136 string valueAsString = value as string;
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
137 return (valueAsString != null && valueAsString.Length >= _minCharacters);
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
138 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
139
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
140 public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
141 {
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
142 return new[]{
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
143 new ModelClientValidationStringLengthRule(FormatErrorMessage(metadata.GetDisplayName()), _minCharacters, int.MaxValue)
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
144 };
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
145 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
146 }
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
147 #endregion
c62b77fc33f4 website inicial
nelo@MTEySS.neluz.int
parents:
diff changeset
148 }