protected void btConfirmar_Click(object sender, EventArgs e)
        {
            string guid = Request.QueryString["guid"];

            if (PasswordDAO.GetNewPwdRequestDataByGUID(guid) == null)
            {
                lbMensagem.ForeColor       = System.Drawing.Color.Red;
                lbMensagem.Text            = "Guid inválido!<br />Contacte o administrador ou faça um novo pedido...";
                tbxConfirmPassword.Enabled = false;
                tbxPassword.Enabled        = false;
                btConfirmar.Enabled        = false;
                hlLogin.Text = "Voltar";
            }
            else
            {
                ResetPwdRequests resetPwd = PasswordDAO.GetNewPwdRequestDataByGUID(guid);
                User             user     = UserDAO.GetUserByEmail(resetPwd.email);
                int returncode            = PasswordDAO.ResetPassword(user.id_User, tbxPassword.Text);
                if (returncode == -1)
                {
                    lbMensagem.ForeColor       = System.Drawing.Color.Red;
                    lbMensagem.Text            = "Guid inválido!<br />Contacte o administrador ou faça um novo pedido...";
                    tbxConfirmPassword.Enabled = false;
                    tbxPassword.Enabled        = false;
                    btConfirmar.Enabled        = false;
                    hlLogin.Text = "Voltar";
                }
                else
                {
                    int return_code = PasswordDAO.DeletePwdRequestByEmail(resetPwd.email);
                    if (return_code == -1)
                    {
                        lbMensagem.ForeColor       = System.Drawing.Color.Red;
                        lbMensagem.Text            = "Guid inválido!<br />Contacte o administrador ou faça um novo pedido...";
                        tbxConfirmPassword.Enabled = false;
                        tbxPassword.Enabled        = false;
                        btConfirmar.Enabled        = false;
                        hlLogin.Text = "Voltar";
                    }
                    else
                    {
                        lbMensagem.ForeColor       = System.Drawing.Color.Green;
                        lbMensagem.Text            = "Reposição efetuada com sucesso!";
                        tbxConfirmPassword.Enabled = false;
                        tbxPassword.Enabled        = false;
                        btConfirmar.Enabled        = false;
                        hlLogin.Text = "Voltar";
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public static ResetPwdRequests GetNewPwdRequestDataByGUID(string guid)
 {
     using (SqlConnection connection = new SqlConnection())
     {
         connection.ConnectionString = ConfigurationManager.ConnectionStrings["GameLibraryDBCS"].ConnectionString;
         using (SqlCommand command = new SqlCommand())
         {
             command.Connection  = connection;
             command.CommandText = "sp_GetPwdRequestDataByGUID";
             command.Parameters.AddWithValue("@guid", guid);
             command.CommandType = CommandType.StoredProcedure;
             connection.Open();
             using (SqlDataReader dataReader = command.ExecuteReader())
             {
                 if (dataReader.Read())
                 {
                     if (Convert.ToInt32(dataReader["ReturnCode"]) == -1)
                     {
                         return(null);
                     }
                     if (dataReader.NextResult())
                     {
                         dataReader.Read();
                         ResetPwdRequests pwdRequests = new ResetPwdRequests()
                         {
                             id_resetPwdRequest = Convert.ToInt32(dataReader["id_resetPwdRequest"]),
                             email = dataReader["email"].ToString(),
                             guid  = dataReader["guid"].ToString(),
                             date_recovery_request = Convert.ToDateTime(dataReader["date_recovery_request"].ToString())
                         };
                         return(pwdRequests);
                     }
                 }
                 return(null);
             }
         }
     }
 }