void AccountContactManage_VerifyPhone_Save(object sender, EventArgs e) { AuthoriseRequestSid(); UserPhoneNumber phoneNumber = new UserPhoneNumber(core, core.Functions.FormLong("id", 0)); if (phoneNumber.UserId == LoggedInMember.Id) { if (!phoneNumber.Validated) { if (phoneNumber.ActivateKey == core.Http.Form["verify-code"]) { UpdateQuery query = new UpdateQuery(typeof(UserPhoneNumber)); query.AddField("phone_validated", true); query.AddField("phone_validated_time_ut", UnixTime.UnixTimeStamp()); query.AddCondition("phone_id", phoneNumber.Id); db.Query(query); SetRedirectUri(BuildUri()); core.Display.ShowMessage("Phone number verified", "Your phone number has been verified"); } } } }
void AccountContactManage_VerifyPhone(object sender, ModuleModeEventArgs e) { AuthoriseRequestSid(); SetTemplate("account_phone_verify"); UserPhoneNumber phoneNumber = new UserPhoneNumber(core, core.Functions.RequestLong("id", 0)); if (phoneNumber.UserId == LoggedInMember.Id) { if (!phoneNumber.Validated) { string activateKey = User.GeneratePhoneActivationToken(); UpdateQuery query = new UpdateQuery(typeof(UserPhoneNumber)); query.AddField("phone_activate_code", activateKey); query.AddCondition("phone_id", phoneNumber.Id); core.Db.Query(query); core.Sms.SendSms(phoneNumber.PhoneNumber, string.Format("Your {0} security code is {1}.", core.Settings.SiteTitle, activateKey)); TextBox verifyTextBox = new TextBox("verify-code"); verifyTextBox.Type = InputType.Telephone; template.Parse("S_ID", phoneNumber.Id.ToString()); template.Parse("PHONE_NUMBER", phoneNumber.PhoneNumber); template.Parse("S_VERIFY_CODE", verifyTextBox); } else { SetRedirectUri(BuildUri()); core.Display.ShowMessage("Already verified", "You have already verified your phone number."); } } else { SetRedirectUri(BuildUri()); core.Display.ShowMessage("Error", "An error has occured."); } }
void AccountContactManage_DeletePhone(object sender, EventArgs e) { AuthoriseRequestSid(); long phoneId = core.Functions.RequestLong("id", 0); try { UserPhoneNumber number = new UserPhoneNumber(core, phoneId); if (number.IsTwoFactor) { SetRedirectUri(BuildUri()); core.Display.ShowMessage("Cannot delete phone number", "The phone number cannot be deleted because it is currently being used for two-factor authentication."); return; } if (number.Delete() > 0) { SetRedirectUri(BuildUri()); core.Display.ShowMessage("Phone Number Deleted", "The phone number has been deleted from the database."); return; } else { SetRedirectUri(BuildUri()); core.Display.ShowMessage("Error", "Could not delete the phone number."); return; } } catch (InvalidUserPhoneNumberException) { SetRedirectUri(BuildUri()); core.Display.ShowMessage("Error", "Could not delete the phone number."); return; } }
void AccountContactManage_AddPhone_save(object sender, EventArgs e) { AuthoriseRequestSid(); switch (core.Http.Form["mode"]) { case "add-phone": string phoneNumber = core.Http.Form["phone-number"]; PhoneNumberTypes phoneType = (PhoneNumberTypes)core.Functions.FormByte("phone-type", 0); try { UserPhoneNumber.Create(core, phoneNumber, phoneType); SetRedirectUri(BuildUri()); core.Display.ShowMessage("Phone Number Saved", "Your phone number has been saved in the database."); } catch (InvalidUserEmailException) { } return; case "edit-phone": long phoneId = core.Functions.FormLong("id", 0); UserPhoneNumber number = null; try { number = new UserPhoneNumber(core, phoneId); } catch (InvalidUserPhoneNumberException) { return; } number.PhoneNumber = core.Http.Form["phone-number"]; number.PhoneType = (PhoneNumberTypes)core.Functions.FormByte("phone-type", (byte)PhoneNumberTypes.Home); number.Update(); SetRedirectUri(BuildUri()); core.Display.ShowMessage("Phone Number Saved", "Your phone number has been saved in the database."); return; default: DisplayError("Error - no mode selected"); return; } }
void AccountContactManage_AddPhone(object sender, ModuleModeEventArgs e) { SetTemplate("account_phone_edit"); /**/ TextBox phoneNumberTextBox = new TextBox("phone-number"); /* */ SelectBox phoneTypeSelectBox = new SelectBox("phone-type"); phoneTypeSelectBox.Add(new SelectBoxItem(((byte)PhoneNumberTypes.Home).ToString(), "Home")); phoneTypeSelectBox.Add(new SelectBoxItem(((byte)PhoneNumberTypes.Mobile).ToString(), "Mobile")); phoneTypeSelectBox.Add(new SelectBoxItem(((byte)PhoneNumberTypes.Business).ToString(), "Business")); phoneTypeSelectBox.Add(new SelectBoxItem(((byte)PhoneNumberTypes.BusinessMobile).ToString(), "BusinessMobile")); phoneTypeSelectBox.Add(new SelectBoxItem(((byte)PhoneNumberTypes.VoIP).ToString(), "VoIP")); phoneTypeSelectBox.Add(new SelectBoxItem(((byte)PhoneNumberTypes.Fax).ToString(), "Fax")); phoneTypeSelectBox.Add(new SelectBoxItem(((byte)PhoneNumberTypes.Other).ToString(), "Other")); switch (e.Mode) { case "add-phone": break; case "edit-phone": long phoneNumberId = core.Functions.FormLong("id", core.Functions.RequestLong("id", 0)); UserPhoneNumber phoneNumber = null; if (phoneNumberId > 0) { try { phoneNumber = new UserPhoneNumber(core, phoneNumberId); //phoneNumberTextBox.IsDisabled = true; phoneNumberTextBox.Value = phoneNumber.PhoneNumber; if (phoneTypeSelectBox.ContainsKey(((byte)phoneNumber.PhoneType).ToString())) { phoneTypeSelectBox.SelectedKey = ((byte)phoneNumber.PhoneType).ToString(); } template.Parse("S_ID", phoneNumber.Id.ToString()); } catch (InvalidUserPhoneNumberException) { } } template.Parse("EDIT", "TRUE"); break; } template.Parse("S_PHONE_NUMBER", phoneNumberTextBox); template.Parse("S_PHONE_TYPE", phoneTypeSelectBox); }
public static UserPhoneNumber Create(Core core, string phoneNumber, PhoneNumberTypes phoneType) { if (core == null) { throw new NullCoreException(); } InsertQuery iquery = new InsertQuery(UserPhoneNumber.GetTable(typeof(UserPhoneNumber))); iquery.AddField("phone_user_id", core.Session.LoggedInMember.Id); iquery.AddField("phone_number", phoneNumber); iquery.AddField("phone_type", (byte)phoneType); iquery.AddField("phone_time_ut", UnixTime.UnixTimeStamp()); iquery.AddField("phone_simple_permissions", true); iquery.AddField("phone_validated", false); long phoneId = core.Db.Query(iquery); UserPhoneNumber newPhoneNumber = new UserPhoneNumber(core, phoneId); Access.CreateGrantForPrimitive(core, newPhoneNumber, User.GetCreatorKey(core), "VIEW"); Access.CreateGrantForPrimitive(core, newPhoneNumber, Friend.GetFriendsGroupKey(core), "VIEW"); return newPhoneNumber; }