protected void Page_Load(object sender, EventArgs e) { Page.Form.Attributes["data-form"] = "message"; note.Visible = MyUtils.IsMale; ID_USER = (int)MyUtils.GetUserField("ID_USER"); //will redirect to login page if not logged in ID_USER_CHATWITH = Convert.ToInt32(Request.QueryString["id"]); DB_Helper db = new DB_Helper(); int id_offer = db.ExecuteScalarInt("exec CAN_MESSAGE_WITH " + ID_USER + "," + ID_USER_CHATWITH, 0); if (id_offer == 0) { id_offer = db.ExecuteScalarInt("select id_offer from offers where id_offer_state=404 and (id_user_from=" + ID_USER_CHATWITH + " and id_user_to=" + MyUtils.ID_USER + ") or (id_user_from=" + MyUtils.ID_USER + " and id_user_to=" + ID_USER_CHATWITH + ")", 0); if (id_offer > 0) { Response.Redirect("/Account/Messages#" + id_offer, true); return; } Response.Clear(); Response.Write("You don't have permission to send messages to this user."); Response.End(); } R = db.GetRow("exec GET_USER_PROFILE " + ID_USER + "," + ID_USER_CHATWITH); if (R == null) { Response.Clear(); Response.Write("This user doesn't exist."); Response.End(); } Offer = db.GetRow("select amount from offers where (id_user_to=" + ID_USER + " and id_user_from=" + ID_USER_CHATWITH + ") or (id_user_to=" + ID_USER_CHATWITH + " and id_user_from=" + ID_USER + ")"); //do some magic here with ID_USER and ID_USER_CHATWITH //....................................................... //Example on how to insert message to DB //SaveMessage2DB(10002, 10003, "testing.... ", "1,2,3,4"); //Example on how to get messages for user pair //DataTable T = GetMessagesForUser(10002, 10003); }
protected void Page_Load(object sender, EventArgs e) { DB_Helper db = new DB_Helper(); int v = db.ExecuteScalarInt("select email_verified from users where id_user="******"/Account/"); return; } if (!IsPostBack) txtEmail.Text = MyUtils.GetUserField("email").ToString(); }
protected void Page_Load(object sender, EventArgs e) { DB_Helper db = new DB_Helper(); int v = db.ExecuteScalarInt("select email_verified from users where id_user="******"/Account/"); return; } if (!IsPostBack) { txtEmail.Text = MyUtils.GetUserField("email").ToString(); } }
protected void btnSendCode_Click(object sender, EventArgs e) { if (regexEmailValid.IsValid && RequiredFieldValidator1.IsValid) { DB_Helper db = new DB_Helper(); string em = txtEmail.Text; if (em.StartsWith("ACTIVATE")) { db.Execute(string.Format("update Users set email_verified=1 where id_user = {0}", MyUtils.ID_USER)); MyUtils.RefreshUserRow(); } else { int id_user = db.ExecuteScalarInt("select id_user from users where email=" + MyUtils.safe(em), 0); if (id_user > 0 && id_user != MyUtils.ID_USER) { Session["message"] = "ERROR: This email is already used by a different user."; return; } db.Execute("update users set email=" + MyUtils.safe(em) + " where id_user="******"EMAIL_ACTIVATE", MyUtils.ID_USER); Session["message"] = "OK: Activation email was sent. Please check your inbox."; } } else { Session["message"] = "ERROR: Invalid email."; } bool needtoverify = Convert.ToUInt32(MyUtils.GetUserField("email_verified")) == 0; if (!needtoverify) { Response.Redirect("/Account/"); Session["message"] = "Account is active."; } }
protected void btnSendCode_Click(object sender, EventArgs e) { if (regexEmailValid.IsValid && RequiredFieldValidator1.IsValid) { DB_Helper db = new DB_Helper(); string em =txtEmail.Text; if (em.StartsWith("ACTIVATE")) { db.Execute(string.Format("update Users set email_verified=1 where id_user = {0}", MyUtils.ID_USER)); MyUtils.RefreshUserRow(); } else { int id_user = db.ExecuteScalarInt("select id_user from users where email=" + MyUtils.safe(em), 0); if (id_user > 0 && id_user != MyUtils.ID_USER) { Session["message"] = "ERROR: This email is already used by a different user."; return; } db.Execute("update users set email=" + MyUtils.safe(em) + " where id_user="******"EMAIL_ACTIVATE", MyUtils.ID_USER); Session["message"] = "OK: Activation email was sent. Please check your inbox."; } } else Session["message"] = "ERROR: Invalid email."; bool needtoverify = Convert.ToUInt32(MyUtils.GetUserField("email_verified")) == 0; if (!needtoverify) { Response.Redirect("/Account/"); Session["message"] = "Account is active."; } }
protected void btnsend_Click(object sender, EventArgs e) { DB_Helper DB = new DB_Helper(); if (txtEmail.Text.Length > 0) { int userId = DB.ExecuteScalarInt("select id_user from users where email='" + txtEmail.Text.Replace("'", "''") + "'", 0); // db.getActiveUserIdByEmail(txtEmail.Text); if (userId != 0) { EmailWrapper mw = new EmailWrapper(); mw.SendTemplate("EMAIL_LOSTPASSWORD", userId); Session["SUCCESS"] = "Password has been sent to provided e-mail"; Response.Redirect("/Forgot"); } else { MyUtils.DisplayCustomMessageInValidationSummary("Provided e-mail is not registered as a valid user e-mail.", ValidationSummary1); } } //else //{ // MyUtils.DisplayCustomMessageInValidationSummary("E-mail is required.", ValidationSummary1); //} }
private void BUT_SENDMESSAGE_ServerClick(object sender, EventArgs e) { int id_offer = db.ExecuteScalarInt("select top 1 id_offer from offers where (id_user_to=" + id_user_profile + " and id_user_from=" + MyUtils.ID_USER + ") or (id_user_from=" + id_user_profile + " and id_user_to=" + MyUtils.ID_USER + ")"); Utils.GoToSendMessage(id_offer); }
public static Message SendMessage(string message, string toUser, string giftIds) { DB_Helper db = new DB_Helper(); var fromUser = MyUtils.ID_USER; message = MyUtils.StripHTML(message); giftIds = MyUtils.StripHTML(giftIds); int id_user_to = Convert.ToInt32(toUser); int id_offer = db.ExecuteScalarInt("exec CAN_MESSAGE_WITH " + Convert.ToInt32(fromUser) + "," + id_user_to, 0); if (id_offer == 0) { Message mm = new Message(); mm.Text = "You don't have permission to send messages to this user."; return(mm); } if (message.Trim() == "") { return(null); } if (!string.IsNullOrEmpty(giftIds)) { Gifts g = new Gifts(giftIds); string err = g.AddGifts2User(MyUtils.ID_USER, id_user_to); if (err != "") { Message mmm = new Message(); mmm.Text = err; return(mmm); } } var table = SaveMessage2DBAndSelect(fromUser, id_user_to, message, giftIds, id_offer); //make sure we don't send too many notification emails int unread_messages_in_10_mins = db.ExecuteScalarInt("select count(*) from Messages where id_user_from=" + fromUser + " and id_user_to=" + id_user_to + " and is_new = 1 and [time] > DATEADD(minute, -10, GETDATE())"); if (unread_messages_in_10_mins < 2) { RWorker.AddToEmailQueue("EMAIL_NEWMESSAGE", id_user_to, MyUtils.ID_USER); } DB_Helper.InvalidateCache("TOPCOUNTS_" + MyUtils.ID_USER); DB_Helper.InvalidateCache("TOPCOUNTS_" + id_user_to); var query = from p in table.AsEnumerable() select new Message { Id = p.Field <int>("id_message"), Text = p.Field <string>("text"), From = new User { Name = "You", Id = p.Field <int>("id_user_from") }, To = new User { Name = "Female123", //TODO Id = p.Field <int>("id_user_from") }, DateTime = p.Field <DateTime>("time"), IsFromMe = true }; Message m = query.First(); if (!string.IsNullOrEmpty(giftIds)) { m.Credits = Convert.ToInt32(MyUtils.GetUserField("credits")); } return(m); }
protected void btnUpdate_Click(object sender, EventArgs e) { bool revalidate = false; try { string newemail = txtEmail.Text.Trim(); int cnt = db.ExecuteScalarInt("select count(*) from users where email=" + MyUtils.safe(newemail) + " and id_user<>" + MyUtils.ID_USER); if (cnt > 0) { Session["message"] = "ERROR: this email is used by other user. You need to provide a new email."; return; } DataSet ds = db.CommandBuilder_LoadDataSet(string.Format("select * from users where id_user={0}", MyUtils.ID_USER)); DataRow userRow = ds.Tables[0].Rows[0]; if (txtPassword.Text.Trim() != string.Empty) { userRow["password"] = txtPassword.Text.Trim(); } revalidate = userRow["email"].ToString().ToUpper() != newemail.ToUpper(); userRow["email"] = newemail; if (revalidate) { userRow["email_verified"] = 0; } //cbx userRow["email_new_matches"] = cbxEmailNewMatches.Checked; userRow["email_when_new_message"] = cbxEmailWhenNewMessage.Checked; userRow["email_when_favorited"] = cbxEmailWhenFavorited.Checked; userRow["email_when_new_offer"] = cbxemail_when_new_offer.Checked; userRow["email_newsletter"] = cbxEmailNewsletter.Checked; userRow["hide_from_search_results"] = cbxHideFromSearchResults.Checked; // userRow["hide_on_viewed_favorited_list"] = cbxHideOnViewedFavoritedList.Checked; // userRow["hide_last_logintime"] = cbxHideLastLogintime.Checked; db.CommandBuilder_SaveDataset(); } finally { db.CommandBuilder_Disconnect(); } MyUtils.RefreshUserRow(); if (revalidate) { RWorker.AddToEmailQueue("EMAIL_ACTIVATE", MyUtils.ID_USER); } Session["message"] = "Settings have been saved"; Response.Redirect("~/Account/"); }
protected void btnSignUp_Click(object sender, EventArgs e) { int id_user; try { txtName.Text = txtName.Text.Trim(); txtPassword.Text = txtPassword.Text.Trim(); txtEmail.Text = txtEmail.Text.Trim(); if (db.ExecuteScalarInt(string.Format("select count(*) from users where username = {0}", MyUtils.safe(txtName.Text))) > 0) { MyUtils.DisplayCustomMessageInValidationSummary("User with this Username already exists.", ValidationSummary1); return; } if (db.ExecuteScalarInt(string.Format("select count(*) from users where email = {0}", MyUtils.safe(txtEmail.Text))) > 0) { MyUtils.DisplayCustomMessageInValidationSummary("User with this Email Address already exists.", ValidationSummary1); return; } string xx = Profanity.TestAndMessage(txtName.Text); if (xx != null) { MyUtils.DisplayCustomMessageInValidationSummary("User name " + xx, ValidationSummary1); return; } DataSet d = db.CommandBuilder_LoadDataSet("select * from users where id_user=-1"); //get the columns schema DataRow n = d.Tables[0].NewRow(); n["username"] = MyUtils.StripHTML(txtName.Text); n["password"] = txtPassword.Text; n["email"] = txtEmail.Text; n["sex"] = MyUtils.StripHTML(ddlGender.SelectedValue); string error = ""; DateTime dt = birthday.GetBirthday(out error); if (error != "") { MyUtils.DisplayCustomMessageInValidationSummary(error, ValidationSummary1); return; } n["birthdate"] = dt; n["country"] = 28; // United States d.Tables[0].Rows.Add(n); id_user = db.CommandBuilder_SaveDataset(); //gets back @@identity EmailWrapper mw = new EmailWrapper(); mw.SendTemplate("EMAIL_ACTIVATE", id_user); string membership = ""; MyUtils.authenticate(txtName.Text, txtPassword.Text, out membership); FormsAuthentication.SetAuthCookie(txtName.Text, false); Response.Redirect("~/Account/Registration"); } finally { db.CommandBuilder_Disconnect(); } }
private int GetIdOffer(int id) { return(db.ExecuteScalarInt("select id_offer from offers where (id_user_from=" + id + " and id_user_to=" + MyUtils.ID_USER + ") or (id_user_from=" + MyUtils.ID_USER + " and id_user_to=" + id + ")")); }