public int GeneratePhoneVerificationCodeText(PhoneAddRequest model, string userId, string currentPhone) { Random rnd = new Random(); int code = rnd.Next(1000, 10000); InsertCode(code, userId); string toNumber = "+1" + model.Phone; //uncomment when ready for production var twilio = new TwilioRestClient(_AccountSid, _AuthToken); string messageBody = "Here is your verification code: " + code; var message = twilio.SendMessage(_TwilioNumber, toNumber , messageBody); string oldPhone = currentPhone; int logId = TextMessageLogInsert(userId, oldPhone , model.Phone, messageBody); return logId; }
public HttpResponseMessage UpdatePhone(PhoneAddRequest model) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } string userId = _userService.GetCurrentUserId(); string currentPhone = _userService.GetCurrentPhone(userId); _userService.UpdatePhone(model, userId); ItemResponse<int> response = new ItemResponse<int>(); response.Item = _userService.GeneratePhoneVerificationCodeText(model , userId, currentPhone); return Request.CreateResponse(response); }
public void UpdatePhone(PhoneAddRequest model, string userId) { if (model.Phone != null) { model.Phone = ParsePhone(model.Phone); } DataProvider.ExecuteNonQuery(GetConnection, "dbo.AspNetUsers_UpdatePhoneNumber" , inputParamMapper: delegate (SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@PhoneNumber", model.Phone); paramCollection.AddWithValue("@Id", userId); } , returnParameters: delegate (SqlParameterCollection param) { } ); }