public ActionResult SendFindPasswordSMS(FormCollection form) { string cell = CookieHelper.GetCookie <String>("FindPasswordCustomerCellPhone"); if (!string.IsNullOrEmpty(cell)) { SMSInfo item = new SMSInfo(); //item.CustomerSysNo = int.Parse(CookieHelper.GetCookie<String>("FindPasswordCustomerSysNo")); item.CreateUserSysNo = int.Parse(CookieHelper.GetCookie <String>("FindPasswordCustomerSysNo")); item.CellNumber = cell; item.Status = SMSStatus.NoSend; item.Type = SMSType.FindPassword; item.Priority = 100; item.RetryCount = 0; string code = VerifyImage.CreateRandomNumber(); CookieHelper.SaveCookie <string>("FindPasswordSMSCode", code); item.SMSContent = string.Format(AppSettingManager.GetSetting("SMSTemplate", "AlertConfirmPhoneCode"), DateTime.Now.ToString("MM月dd日 HH:mm"), code); if (CommonFacade.InsertNewSMS(item)) { return(Json("s", JsonRequestBehavior.AllowGet)); } } return(Json("服务器忙,稍后重试", JsonRequestBehavior.AllowGet)); }
public ActionResult AjaxSendValidateCellphoneByCode(FormCollection form) { string cell = Request["CellPhoneNumber"].ToString(); if (!string.IsNullOrEmpty(cell)) { //判断手机号码是否被验证过 if (CustomerFacade.PhoneIsValidate(cell)) { return(Json("此手机号码已经被验证过,不能进行重复验证", JsonRequestBehavior.AllowGet)); } CellPhoneConfirm item = new CellPhoneConfirm(); item.CustomerSysNo = CurrUser.UserSysNo; item.CellPhone = cell; string code = VerifyImage.CreateRandomNumber(); item.ConfirmKey = code; int CellPhoneSysNo = CustomerFacade.CreateCellPhoneConfirm(item).SysNo; if (CellPhoneSysNo > 0) { return(Json("s", JsonRequestBehavior.AllowGet)); } if (CellPhoneSysNo == -99999) { return(Json("同一个IP地址24小时内只能请求验证码10次,同一个手机号码请求验证码5次。", JsonRequestBehavior.AllowGet)); } return(Json("服务器忙,稍后重试", JsonRequestBehavior.AllowGet)); } return(Json("服务器忙,稍后重试", JsonRequestBehavior.AllowGet)); }
protected void Page_Load(object sender, EventArgs e) { // 规定验证码长度 if (this.CodeLen < 4 || this.CodeLen > 16) { throw new Exception("验证码长度必须在4到16之间"); } // 获取图片宽度 if (this.ImgWidth < 16 || ImgWidth > 480) { throw new Exception("图片宽度必须在16到480之间"); } // 获取图片高度 if (ImgHeight < 16 || ImgHeight > 320) { throw new Exception("图片高度必须在16到320之间"); } string validateCode = CreateValidateCode(this.Context); VerifyImage verifyimg = new VerifyImage(validateCode, imgWidth, imgHeight); Bitmap image = verifyimg.Image; Response.ContentType = "image/pjpeg"; //MemoryStream ms = new MemoryStream(); image.Save(Response.OutputStream, ImageFormat.Jpeg); }
public ActionResult VerifyImage() { string code = (new VerifyImage()).GenerateCheckCode(); Session["ValidateCode"] = code; byte[] bytes = new VerifyImage().CreateCheckCodeImage(code); return(File(bytes, "image/jpeg")); }
protected void Page_Load(object sender, EventArgs e) { VerifyImage v = new VerifyImage(); string code = v.CreateVerifyCode(); v.CreateImageOnPage(code, this.Context); Response.Cookies.Add(new HttpCookie("CheckCode", code.ToUpper())); }
public ActionResult AjaxSendValidateCellphoneByCode(FormCollection form) { //return Json("s", JsonRequestBehavior.AllowGet); string validatedCode = Request["ValidateCode"].ToString(); if (CookieHelper.GetCookie <String>("VerifyCode").ToLower() != validatedCode.ToLower()) { return(Json(new JsonResult() { ContentType = "验证码不正确", Data = "" }, JsonRequestBehavior.AllowGet)); } string cell = Request["CellPhoneNumber"].ToString(); if (!string.IsNullOrEmpty(cell)) { //判断手机号码是否被验证过 //if (CustomerFacade.PhoneIsValidate(cell)) //{ // return Json(new JsonResult(){ContentType="此手机号码已经被验证过,不能进行重复验证"} , JsonRequestBehavior.AllowGet); //} CellPhoneConfirm item = new CellPhoneConfirm(); item.CustomerSysNo = 0; item.CellPhone = cell; string code = VerifyImage.CreateRandomNumber(); item.ConfirmKey = code; int CellPhoneSysNo = CustomerFacade.CreateCellPhoneConfirm(item).SysNo; if (CellPhoneSysNo > 0) { return(Json(new JsonResult() { ContentType = "s", Data = CellPhoneSysNo }, JsonRequestBehavior.AllowGet)); } if (CellPhoneSysNo == -99999) { return(Json(new JsonResult() { ContentType = "同一个IP地址24小时内只能请求验证码10次,同一个手机号码请求验证码5次。" }, JsonRequestBehavior.AllowGet)); } return(Json(new JsonResult() { ContentType = "服务器忙,稍后重试" }, JsonRequestBehavior.AllowGet)); } return(Json(new JsonResult() { ContentType = "服务器忙,稍后重试" }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 初始化页面 /// </summary> /// <param name="e"></param> protected override void OnInit(EventArgs e) { base.OnInit(e); string verifyCode = Game.Utils.TextUtility.CreateAuthStr(4, true); Game.Utils.SessionState.Set(Fetch.UC_VERIFY_CODE_KEY, verifyCode); Utils.Utility.WriteCookie(Fetch.UC_VERIFY_CODE_KEY, Utils.CWHEncryptNet.XorEncrypt(verifyCode)); VerifyImageInfo verifyimg = new VerifyImage().GenerateImage(verifyCode, 42, 20, Color.FromArgb(227, 227, 227)); Bitmap image = verifyimg.Image; Response.ContentType = verifyimg.ContentType; image.Save(Response.OutputStream, verifyimg.ImageFormat); }
public FileContentResult ImageValidator() { Response.Cache.SetCacheability(HttpCacheability.NoCache); VerifyImage v = new VerifyImage(); string code = v.CreateVerifyCode(); CookieHelper.SaveCookie <String>("VerifyCode", code); using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { Bitmap image = v.CreateImageCode(code); image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); code = CryptoManager.Encrypt(code.ToUpper()); byte[] b = ms.GetBuffer(); return(File(b, @"image/jpg")); } }
public void CreateImageOnPage(string code, HttpContext context) { System.IO.MemoryStream ms = new System.IO.MemoryStream(); VerifyImage vi = new VerifyImage(); Bitmap image = vi.GenerateImage(code);// this.CreateImageCode(code); image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); context.Response.ClearContent(); context.Response.ContentType = "image/Jpeg"; context.Response.BinaryWrite(ms.GetBuffer()); ms.Close(); ms = null; image.Dispose(); image = null; }
/// <summary> /// 初始化 /// </summary> /// <param name="e"></param> protected override void OnInit(EventArgs e) { // base.OnInit(e); string authStr = StringUtil.CreateAuthStr(5, true); Utils.WriteCookie("verifycode", authStr); VerifyImage verifyimg = new VerifyImage(authStr, 90, 50); Bitmap image = verifyimg.Image; System.Web.HttpContext.Current.Response.ContentType = "image/pjpeg"; //MemoryStream ms = new MemoryStream(); image.Save(this.Response.OutputStream, ImageFormat.Jpeg); //System.Web.HttpContext.Current.Response.OutputStream.Write(ms.ToArray(), 0, (int)ms.Length); }
public ActionResult SendLoginValidSMS(FormCollection form) { //step one :get customer cellphone from db string customerID = form["CustomerID"]; if (string.IsNullOrEmpty(customerID)) { return(Json("账户名未提供,发送验证码失败。", JsonRequestBehavior.AllowGet)); } var customer = CustomerFacade.GetCustomerByID(customerID); string customerCellphone = customer.CellPhone; //step two :send sms if (string.IsNullOrEmpty(customerCellphone) || customer.IsPhoneValided == 0) { return(Json("账户未绑定手机或是未完成验证绑定,获取验证码失败。", JsonRequestBehavior.AllowGet)); } else { SMSInfo item = new SMSInfo(); item.CreateUserSysNo = customer.SysNo; item.CellNumber = customer.CellPhone; item.Status = SMSStatus.NoSend; item.Type = SMSType.VerifyPhone; item.Priority = 100; item.RetryCount = 0; string code = VerifyImage.CreateRandomNumber(); CookieHelper.SaveCookie <string>("VerifyCode", code); item.SMSContent = string.Format(AppSettingManager.GetSetting("SMSTemplate", "CreateConfirmPhoneCode"), DateTime.Now.ToString("MM月dd日 HH:mm"), code); if (CommonFacade.InsertNewSMS(item)) { return(Json("s", JsonRequestBehavior.AllowGet)); } } return(Json("服务器忙,稍后重试", JsonRequestBehavior.AllowGet)); }
public string Get(string username) { try { _logger.LogInformation($"Getting property details for {username} for image url {HttpContext.Request.Query["image"]}"); var imgSearchReq = new SearchImageRequest { org_image_url = HttpContext.Request.Query["image"] }; var response = new Response(); response.milestones.Add("Getting property details"); try { _logger.LogInformation("ORCHESTRATOR SERVICE: get all images from DB"); using (var sqlConn = new SqlConnection(DB_CONN)) { sqlConn.Open(); var query = "SELECT Path from [dbo].[Image]"; using (SqlCommand cmd = new SqlCommand(query, sqlConn)) { using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { imgSearchReq.comp_image_urls.Add(reader.GetString(0)); } } } } _logger.LogInformation($"ORCHESTRATOR SERVICE: retrieved {imgSearchReq.comp_image_urls.Count} images from DB"); response.milestones.Add("Retrieved images from DB"); } catch (Exception ex) { response.milestones.Add($"Error getting details from DB: {ex.Message}"); return($"Error getting all images from DB: {ex.Message}"); } VerifyImage verifyImg; try { _logger.LogInformation($"ORCHESTRATOR SERVICE: verify if the image is a house"); response.milestones.Add("Verifying image"); using (var httpClient = new HttpClient()) { _logger.LogInformation($"ORCHESTRATOR SERVICE: calling {ML_API}/? image_url={imgSearchReq.org_image_url}"); using (var res = httpClient.GetAsync(ML_API + "/?image_url=" + imgSearchReq.org_image_url)) { var apiResponse = res.Result.Content.ReadAsStringAsync().Result; _logger.LogInformation($"ORCHESTRATOR SERVICE: received response from {ML_API}/? image_url={imgSearchReq.org_image_url} ---- {res.Result.StatusCode}"); if (res.Result.IsSuccessStatusCode) { _logger.LogInformation($"ORCHESTRATOR SERVICE: Deserializing response {apiResponse}"); verifyImg = JsonConvert.DeserializeObject <VerifyImage>(apiResponse); _logger.LogInformation($"ORCHESTRATOR SERVICE: Deserialized response {string.Join(';', verifyImg.tags.ToArray())}"); response.milestones.Add("It is a house"); } else { _logger.LogInformation($"ORCHESTRATOR SERVICE: Image is not a house"); verifyImg = new VerifyImage { is_house = false }; _logger.LogInformation($"ORCHESTRATOR SERVICE: Image is {string.Join(';', verifyImg.tags.ToArray())}"); response.milestones.Add("It is not a house"); } } response.isHouse = verifyImg.is_house; } _logger.LogInformation("ORCHESTRATOR SERVICE: get user details from DB"); response.milestones.Add("Getting User details from DB"); using (var sqlConn = new SqlConnection(DB_CONN)) { sqlConn.Open(); var query = $"SELECT * from [dbo].[UserProfile] where username='******'"; using (SqlCommand cmd = new SqlCommand(query, sqlConn)) { using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { response.user = new Core.UserProfile { userId = reader.GetInt32(0).ToString(), username = reader.GetString(1), firstName = reader.GetString(3), lastName = reader.GetString(4), middleName = reader.GetString(5), creditScore = reader.GetInt32(6), aum = reader.GetInt32(7), relationshipAge = reader.GetInt32(8), phone = reader.GetString(9), emailAddress = reader.GetString(10), accountNumber = reader.GetString(11) }; } } } } _logger.LogInformation($"ORCHESTRATOR SERVICE: retrieved {JsonConvert.SerializeObject(response.user)} from DB"); response.milestones.Add("Got User details from DB"); } catch (Exception ex) { return($"Error verifying image: {ex.Message}"); } if (!verifyImg.is_house) { _logger.LogInformation($"ORCHESTRATOR SERVICE: returning early since the image is not a house"); return(JsonConvert.SerializeObject(response)); } SearchImageResponse imgSearchResponse; try { _logger.LogInformation($"ORCHESTRATOR SERVICE: send query image and all DB images to ML model"); response.milestones.Add("calling vision service"); using (var httpClient = new HttpClient()) { var httpContent = new StringContent(JsonConvert.SerializeObject(imgSearchReq), Encoding.UTF8, "application/json"); { _logger.LogInformation($"ORCHESTRATOR SERVICE: calling {ML_API} using {httpContent}"); using (var res = httpClient.PostAsync(ML_API, httpContent)) { var apiResponse = res.Result.Content.ReadAsStringAsync().Result; _logger.LogInformation($"ORCHESTRATOR SERVICE: received response from {ML_API} for image matching ---- {res.Result.StatusCode}"); if (res.Result.IsSuccessStatusCode) { _logger.LogInformation($"ORCHESTRATOR SERVICE: Deserializing response {apiResponse}"); imgSearchResponse = JsonConvert.DeserializeObject <SearchImageResponse>(apiResponse); response.propertyFound = true; _logger.LogInformation($"ORCHESTRATOR SERVICE: Deserialized response {imgSearchResponse.comp_image_url} and {imgSearchResponse.message}"); response.milestones.Add("Property was found"); } else { response.propertyFound = false; imgSearchResponse = new SearchImageResponse { comp_image_url = "https://azsnappersblob.blob.core.windows.net/images/HouseNotFound.PNG", message = "Property not found" }; _logger.LogInformation($"ORCHESTRATOR SERVICE: Image not matched... returning property not found image"); response.milestones.Add("Property was not found"); // var p = new Random().Next(0, 65); //_logger.LogInformation($"ORCHESTRATOR SERVICE: Image not matched... picking a random image {p}"); //if (p == 0) //{ // imgSearchResponse = new SearchImageResponse { comp_image_url = "https://azsnappersblob.blob.core.windows.net/images/HouseNotFound.PNG", message = "Property not found" }; //} //else //{ // imgSearchResponse = new SearchImageResponse { comp_image_url = imgSearchReq.comp_image_urls[p - 1], message = "Randomly chosen house image" }; //} //_logger.LogInformation($"ORCHESTRATOR SERVICE: Image not matched... picked a random image {JsonConvert.SerializeObject(imgSearchResponse)}"); } } } } } catch (Exception ex) { return($"Error matching image from vision service: {ex.Message}"); } var mtgReq = new MortgageQuoteRequest(); try { _logger.LogInformation($"ORCHESTRATOR SERVICE: get property from return image url"); response.milestones.Add("Getting property details from DB"); using (var sqlConn = new SqlConnection(DB_CONN)) { sqlConn.Open(); var query = $"select P.*, I.Path from [dbo].[image] I, [dbo].[Property] P where I.PropertyId = P.PropertyId and I.Path = '{imgSearchResponse.comp_image_url}'"; using (SqlCommand cmd = new SqlCommand(query, sqlConn)) { using (var reader = cmd.ExecuteReader()) { var added = false; while (reader.Read()) { if (!added) { added = true; response.propertyList.Add(new Property { imageUrl = reader.GetString(16), address = $"{reader.GetString(1)}, {reader.GetString(3)}, {reader.GetString(4)} {reader.GetString(5)}", area = reader.GetDouble(14).ToString(), numberOfBedrooms = reader.GetInt32(7), numberOfBathrooms = reader.GetInt32(8), cost = reader.GetDouble(13).ToString(), status = reader.GetString(12), tax = reader.GetDouble(15).ToString(), zip = reader.GetString(5), propertyId = reader.GetInt32(0).ToString() }); } response.propertyList[0].moreImages.Add(reader.GetString(16)); } } } } _logger.LogInformation($"ORCHESTRATOR SERVICE: retrieved property details from DB --- {JsonConvert.SerializeObject(response.propertyList)}"); response.milestones.Add("Got property details from DB"); mtgReq.AccountDetails = new AccountDetails { AccountNumber = response.user.accountNumber, AUM = decimal.Parse(response.user.aum.ToString()), Tenure = response.user.relationshipAge.ToString(), UserId = response.user.userId }; var age = new Random().Next(5, 50); mtgReq.PropertyDetails = new PropertyDetails { Zipcode = response.propertyList[0].zip, Area = response.propertyList[0].area.ToString(), Cost = decimal.Parse(response.propertyList[0].cost), AgeInYears = age, contrustedIn = DateTime.Now.AddYears(-1 * age), NumberOfBedrooms = response.propertyList[0].numberOfBedrooms, PropertyId = response.propertyList[0].propertyId }; _logger.LogInformation($"ORCHESTRATOR SERVICE: send user and property details to mortgage service --- {JsonConvert.SerializeObject(mtgReq)}"); } catch (Exception ex) { return($"Error getting selected property from DB: {ex.Message}"); } response.milestones.Add("Getting quote from Mortgage service"); try { MortgageQuoteResponse mtgResponse; using (var httpClient = new HttpClient()) { var httpContent = new StringContent(JsonConvert.SerializeObject(mtgReq), Encoding.UTF8, "application/json"); { _logger.LogInformation($"ORCHESTRATOR SERVICE: calling {MTG_API} using {httpContent}"); using (var res = httpClient.PostAsync(MTG_API, httpContent)) { var apiResponse = res.Result.Content.ReadAsStringAsync().Result; _logger.LogInformation($"ORCHESTRATOR SERVICE: received response from {MTG_API} for mortgage saearch ---- {res.Result.StatusCode}"); if (res.Result.IsSuccessStatusCode) { _logger.LogInformation($"ORCHESTRATOR SERVICE: Deserializing response {apiResponse}"); mtgResponse = JsonConvert.DeserializeObject <MortgageQuoteResponse>(apiResponse); response.quoteFound = true; _logger.LogInformation($"ORCHESTRATOR SERVICE: Deserialized response {JsonConvert.SerializeObject(mtgResponse)}"); response.milestones.Add("Got quote from Mortgage service"); } else { mtgResponse = new MortgageQuoteResponse { AccountNumber = mtgReq.AccountDetails.AccountNumber, UserId = response.user.userId, IsPreApproved = false, PropertyId = mtgReq.PropertyDetails.PropertyId, DownPayment = 0, MonthlyEMI = 0, RateofInterest = "0" }; response.quoteFound = false; _logger.LogInformation($"ORCHESTRATOR SERVICE: Image not matched... setting default dummy response {JsonConvert.SerializeObject(mtgResponse)}"); response.milestones.Add("Dummy quote generated"); } response.propertyList[0].quoteDetails.downPayment = mtgResponse.DownPayment; response.propertyList[0].quoteDetails.isPreApproved = mtgResponse.IsPreApproved; response.propertyList[0].quoteDetails.monthlyPayment = mtgResponse.MonthlyEMI; response.propertyList[0].quoteDetails.rateOfInterest = mtgResponse.RateofInterest; } } } } catch (Exception ex) { return($"Error getting mortgage quote: {ex.Message}"); } _logger.LogInformation($"ORCHESTRATOR SERVICE: send user, property and mortgage details back to UI {JsonConvert.SerializeObject(response)}"); response.milestones.Add("Sending full response back"); return(JsonConvert.SerializeObject(response)); } catch (Exception exc) { return(exc.Message); } }