/Docs/07-Implementacion/Source/trunk/EDUAR_actual/EDUAR/EDUAR_UI/Public/Account/ForgotPassword.aspx.cs

http://blpm.googlecode.com/ · C# · 246 lines · 181 code · 23 blank · 42 comment · 10 complexity · 627bece77e3c52d66ea41219b5f6650b MD5 · raw file

  1. using System;
  2. using System.Web;
  3. using System.Web.Security;
  4. using System.Web.UI;
  5. using EDUAR_BusinessLogic.Security;
  6. using EDUAR_Entities.Security;
  7. using EDUAR_UI.Shared;
  8. using EDUAR_Utility.Constantes;
  9. using EDUAR_Utility.Enumeraciones;
  10. using EDUAR_Utility.Utilidades;
  11. namespace EDUAR_UI
  12. {
  13. public partial class ForgotPassword : EDUARBasePage
  14. {
  15. #region --[Atributos]--
  16. private BLSeguridad objBLSeguridad;
  17. #endregion
  18. #region --[Propiedades]--
  19. /// <summary>
  20. /// Propiedad que contiene el objeto seguridad que devuelve la consulta a la Capa de Negocio.
  21. /// </summary>
  22. public DTSeguridad propSeguridad
  23. {
  24. get
  25. {
  26. if (ViewState["propSeguridad"] == null)
  27. return null;
  28. return (DTSeguridad)ViewState["propSeguridad"];
  29. }
  30. set { ViewState["propSeguridad"] = value; }
  31. }
  32. #endregion
  33. #region --[Eventos]--
  34. /// <summary>
  35. /// Método que se ejecuta al dibujar los controles de la página.
  36. /// Se utiliza para gestionar las excepciones del método Page_Load().
  37. /// </summary>
  38. /// <param name="e"></param>
  39. protected override void OnPreRender(EventArgs e)
  40. {
  41. base.OnPreRender(e);
  42. if (AvisoMostrar)
  43. {
  44. AvisoMostrar = false;
  45. try
  46. {
  47. Master.ManageExceptions(AvisoExcepcion);
  48. }
  49. catch (Exception ex) { Master.ManageExceptions(ex); }
  50. }
  51. }
  52. /// <summary>
  53. /// Handles the Load event of the Page control.
  54. /// </summary>
  55. /// <param name="sender">The source of the event.</param>
  56. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  57. protected void Page_Load(object sender, EventArgs e)
  58. {
  59. try
  60. {
  61. Master.BotonAvisoAceptar += (VentanaAceptar);
  62. if (!Page.IsPostBack)
  63. {
  64. Response.Cookies.Clear();
  65. HttpContext.Current.User = null;
  66. propSeguridad = new DTSeguridad();
  67. if (ObjSessionDataUI.ObjDTUsuario.EsUsuarioInicial == true)
  68. {
  69. ObjSessionDataUI.ObjDTUsuario.EsUsuarioInicial = false;
  70. CargarDatosUsuario();
  71. CargarPresentacionRecover();
  72. }
  73. else
  74. {
  75. udpEmail.Visible = true;
  76. udpRecover.Visible = false;
  77. }
  78. udpForgotPassword.Update();
  79. }
  80. }
  81. catch (Exception ex)
  82. {
  83. AvisoMostrar = true;
  84. AvisoExcepcion = ex;
  85. }
  86. }
  87. /// <summary>
  88. ///
  89. /// </summary>
  90. /// <param name="sender"></param>
  91. /// <param name="e"></param>
  92. void VentanaAceptar(object sender, EventArgs e)
  93. {
  94. try
  95. {
  96. Response.Redirect("~/Private/Account/Welcome.aspx", false);
  97. }
  98. catch (Exception ex)
  99. {
  100. Master.ManageExceptions(ex);
  101. }
  102. }
  103. /// <summary>
  104. /// Handles the Click event of the btnEnviarMail control.
  105. /// </summary>
  106. /// <param name="sender">The source of the event.</param>
  107. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  108. protected void btnEnviarMail_Click(object sender, EventArgs e)
  109. {
  110. try
  111. {
  112. if (EDUARUtilidades.EsEmailValido(txtEmail.Text.Trim()))
  113. {
  114. propSeguridad.Usuario.Email = txtEmail.Text.Trim();
  115. objBLSeguridad = new BLSeguridad(propSeguridad);
  116. objBLSeguridad.GetUsuarioByEmail();
  117. objBLSeguridad.RecuperarPassword(ObjSessionDataUI.urlDefault);
  118. txtEmail.Text = string.Empty;
  119. AccionPagina = enumAcciones.Buscar;
  120. Master.MostrarMensaje(enumTipoVentanaInformacion.Satisfactorio.ToString(), UIConstantesGenerales.MensajeCheckearCorreo, enumTipoVentanaInformacion.Satisfactorio);
  121. }
  122. }
  123. catch (Exception ex)
  124. {
  125. Master.ManageExceptions(ex);
  126. }
  127. }
  128. /// <summary>
  129. /// Handles the Click event of the btnRecoverPassword control.
  130. /// </summary>
  131. /// <param name="sender">The source of the event.</param>
  132. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  133. protected void btnRecoverPassword_Click(object sender, EventArgs e)
  134. {
  135. try
  136. {
  137. if (txtRespuesta.Text.Trim().Length > 0)
  138. {
  139. propSeguridad.Usuario.PaswordRespuesta = txtRespuesta.Text.Trim();
  140. propSeguridad.Usuario.Nombre = ObjSessionDataUI.ObjDTUsuario.Nombre;
  141. objBLSeguridad = new BLSeguridad(propSeguridad);
  142. objBLSeguridad.ValidarRespuesta();
  143. if (!string.IsNullOrEmpty(objBLSeguridad.Data.Usuario.PaswordRespuesta))
  144. {
  145. ObjSessionDataUI.ObjDTUsuario.PaswordRespuesta = txtRespuesta.Text.Trim();
  146. CargarPresentacionNuevaPassword();
  147. txtEmail.Text = string.Empty;
  148. }
  149. else
  150. {
  151. Master.MostrarMensaje(enumTipoVentanaInformacion.Advertencia.ToString(), UIConstantesGenerales.MensajeErrorPreguntaSeguridad, enumTipoVentanaInformacion.Advertencia);
  152. }
  153. }
  154. }
  155. catch (Exception ex)
  156. {
  157. Master.ManageExceptions(ex);
  158. }
  159. }
  160. /// <summary>
  161. /// Handles the Click event of the btnConfirmarPassword control.
  162. /// </summary>
  163. /// <param name="sender">The source of the event.</param>
  164. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  165. protected void btnConfirmarPassword_Click(object sender, EventArgs e)
  166. {
  167. try
  168. {
  169. if (Page.IsValid)
  170. {
  171. propSeguridad.Usuario.PaswordPregunta = ObjSessionDataUI.ObjDTUsuario.PaswordPregunta;
  172. propSeguridad.Usuario.PaswordRespuesta = ObjSessionDataUI.ObjDTUsuario.PaswordRespuesta;
  173. propSeguridad.Usuario.PasswordNuevo = txtPassword.Text.Trim();
  174. objBLSeguridad = new BLSeguridad(propSeguridad);
  175. objBLSeguridad.CambiarPassword();
  176. HttpContext.Current.SkipAuthorization = true;
  177. AccionPagina = enumAcciones.Salir;
  178. FormsAuthentication.SetAuthCookie(objBLSeguridad.Data.Usuario.Nombre, false);
  179. Master.MostrarMensaje(enumTipoVentanaInformacion.Satisfactorio.ToString(), UIConstantesGenerales.MensajeNuevoPassword, enumTipoVentanaInformacion.Satisfactorio);
  180. }
  181. }
  182. catch (Exception ex)
  183. {
  184. Master.ManageExceptions(ex);
  185. }
  186. }
  187. #endregion
  188. #region --[Métodos Privados]--
  189. /// <summary>
  190. /// Cargars the presentacion recover.
  191. /// </summary>
  192. private void CargarPresentacionRecover()
  193. {
  194. udpEmail.Visible = false;
  195. udpRecover.Visible = true;
  196. udpNewPassword.Visible = false;
  197. udpRecover.Update();
  198. }
  199. /// <summary>
  200. /// Cargars the presentacion nueva password.
  201. /// </summary>
  202. private void CargarPresentacionNuevaPassword()
  203. {
  204. udpEmail.Visible = false;
  205. udpRecover.Visible = false;
  206. udpNewPassword.Visible = true;
  207. udpForgotPassword.Update();
  208. }
  209. /// <summary>
  210. /// Cargars the datos usuario.
  211. /// </summary>
  212. private void CargarDatosUsuario()
  213. {
  214. propSeguridad.Usuario.Email = txtEmail.Text.Trim();
  215. propSeguridad.Usuario = ObjSessionDataUI.ObjDTUsuario;
  216. objBLSeguridad = new BLSeguridad(propSeguridad);
  217. objBLSeguridad.GetUsuario();
  218. ObjSessionDataUI.ObjDTUsuario.PaswordPregunta = objBLSeguridad.Data.Usuario.PaswordPregunta;
  219. lblPregunta.Text = ObjSessionDataUI.ObjDTUsuario.PaswordPregunta;
  220. }
  221. #endregion
  222. }
  223. }