protected void Btn_Save_Click(object sender, EventArgs e) { try { if (txt_Username.Text != "" && txt_Password.Text != "" && txt_ConfirmPassword.Text != "" && txt_Email.Text != "") { string username = txt_Username.Text; string password = txt_Password.Text; string confirm = txt_ConfirmPassword.Text; string usercard = txt_UserCard.Text; res = tau.Bring_Username(username); if (res.Count == 0) { password = Encrypt(txt_Password.Text); tau.Insert(txt_Username.Text, txt_Email.Text, password, "Active", 2, usercard); string script = @"alert('User New add correctly...'); window.location.href='Admin_Users.aspx';"; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", script, true); //talog.Insert("Registration of New User by Itself", (string)Session["Username"], System.DateTime.Now); } else { Response.Write("<script>alert('Username Already Registered... Try again with other username');</script>"); txt_Username.Focus(); } } else { Response.Write("<script>alert('Fill in the fields correctly');</script>"); txt_Username.Text = ""; txt_ConfirmPassword.Text = ""; txt_Password.Text = ""; txt_UserCard.Text = ""; } } catch (Exception error) { ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alerta", "alert('The following error has occurred: " + error.Message + " ');", true); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["Id_User"] == null) { Response.Redirect("Login.aspx"); } else { if (Convert.ToInt32(Session["User_Type"].ToString()) != 2) { Response.Redirect("DefaultAdmin.aspx"); } else { id_User = Convert.ToInt32(Session["Id_User"].ToString()); if (!IsPostBack) { if (Session["Id_User"] != null) { MercadoUDi_DataSetTableAdapters.UserTableAdapter tau = new MercadoUDi_DataSetTableAdapters.UserTableAdapter(); res = tau.GetDataBy_IdUser(id_User); txt_Username.Text = res[0].UserName; txt_Email.Text = res[0].UserEmail; txt_Password.Text = res[0].UserPassword; txt_ConfirmPassword.Text = res[0].UserPassword; if (res[0].UserCard.ToString() != " ") { txt_UserCard.Text = res[0].UserCard.ToString(); } else { txt_UserCard.Text = " "; } password = res[0].UserPassword; Session["User_PasswordRegisterConfig"] = res[0].UserPassword; } } } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["Id_User"] == null) { Response.Redirect("Login.aspx"); } else { if (Convert.ToInt32(Session["User_Type"].ToString()) != 1) { Response.Redirect("Default_Client.aspx"); } else { id_User = Convert.ToInt32(Session["Id_User_Update"].ToString()); if (!IsPostBack) { if (Session["Id_User_Update"] != null) { MercadoUDi_DataSetTableAdapters.UserTableAdapter tau = new MercadoUDi_DataSetTableAdapters.UserTableAdapter(); res = tau.GetDataBy_IdUser(id_User); txt_Username.Text = res[0].UserName; txt_Email.Text = res[0].UserEmail; txt_Password.Text = res[0].UserPassword; txt_ConfirmPassword.Text = res[0].UserPassword; if (res[0].UserCard.ToString() != " ") { txt_UserCard.Text = res[0].UserCard.ToString(); } else { txt_UserCard.Text = " "; } password = res[0].UserPassword; int id_User_Type = Convert.ToInt32(res[0].UserType.ToString()); resType = taut.GetDataBy_Id(id_User_Type); string userType = resType[0].IdUserType.ToString(); /* * DropDownList_Status.SelectedValue = res[0].UserStatus.ToString(); * DropDownList_UserType.SelectedValue = userType; * * DropDownList_UserType.DataValueField = resType[0].IdUserType.ToString();*/ DropDownList_Status.Text = res[0].UserStatus.ToString(); DropDownList_UserType.Text = resType[0].IdUserType.ToString(); Session["User_PasswordRegister"] = res[0].UserPassword; } } } } }
protected void Btn_RecoverPassword_Click(object sender, EventArgs e) { try { if (txt_Usermail.Text != "") { string UserEmail = txt_Usermail.Text; res = tau.Bring_UserEmail(UserEmail); if (res.Count != 0) { string UserName = res[0].UserName.ToString(); string newPassword = "******"; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; //587 //25 //465 smtp.EnableSsl = true; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "3102852214"); MailMessage emailMessage = new MailMessage(); emailMessage.From = new MailAddress("*****@*****.**"); emailMessage.To.Add(new MailAddress(txt_Usermail.Text)); emailMessage.Subject = "Reset Password of MercadoUDi"; emailMessage.Body = "Hello..." + "\n" + "As requested, your password for our member area has been reset. Your new session details are: " + "\n" + "\n" + "Username:"******"\n" + "New Password: "******"alert('In a moment you will receive a message with the new password...'); window.location.href='Login.aspx';"; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", script, true); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "alert('Email Sending');", true); } catch (Exception error) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "alert('email error" + error.Message + "');", true); } //talog.Insert("Recover the Password", UserName, System.DateTime.Now); } else { string script = @"alert('The email: " + UserEmail + " does not exist. Try Again...');"; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", script, true); txt_Usermail.Focus(); } } else { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "alert('Fill in the fields correctly ');", true); } } catch (Exception error) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "alert('The following error has occurred: " + error.Message + " ');", true); } }