public JsonResult Generate() { string Message = string.Empty, Code = string.Empty, Error = string.Empty; try { StudentRepository _objRepository = new StudentRepository(); DataSet _dsInstituteListForGeneration = _objRepository.Opr_GenerateStudentDtl("SelectActivationLinkNotSent"); if (_dsInstituteListForGeneration != null) { if (_dsInstituteListForGeneration.Tables[0].Rows.Count > 0) { foreach (DataRow _dr in _dsInstituteListForGeneration.Tables[0].Rows) { DateTime _datetime = DateTime.Now; #region Generate Link If Needed _objRepository = new StudentRepository(); string studentid = _dr["studentid"].ToString(); string Email = _dr["Email"].ToString(); string StudentName = _dr["StudentName"].ToString(); string Country_Name = _dr["Country_Name"].ToString(); string AccessURL = ""; if (_dr["ActivationLink"].ToString() == "") { AccessURL = "https://www.studyinindia.gov.in/admission/login?eid=" + Encrypt_Decrypt.EncryptData(Email, ""); } else { AccessURL = _dr["ActivationLink"].ToString(); } DataSet _ds = _objRepository.Opr_GenerateStudentDtl("Update", studentid, AccessURL); #endregion #region Call PivotRoots Code string strUrl = "https://pivotroots.com/clients/studyinindia/webhooks/user_events"; WebRequest request = HttpWebRequest.Create(strUrl); request.Headers.Add("Request-Id", DateTime.Now.ToString("yyyyMMddhhmmss")); request.Method = "POST"; request.ContentType = "application/json"; request.Headers.Add("Client-Id", "b7a51eff57749dc0e733b74342c8b512"); request.Headers.Add("Client-Access-Token", "dfdd5aa8ea4a1e2fb5999dc213476c2a9b68efa7"); mWebhookRequestRegistration _objJsonRequest = new mWebhookRequestRegistration() { timestamp = DateTime.Now.ToString("yyyyMMddhhmmss"), user_id = studentid, @event = "new_registration", userName = StudentName, emailID = Email, activationLink = AccessURL, Country = Country_Name }; string data = JsonConvert.SerializeObject(_objJsonRequest); byte[] dataStream = Encoding.UTF8.GetBytes(data); request.ContentLength = dataStream.Length; Stream r = request.GetRequestStream(); r.Write(dataStream, 0, dataStream.Length); r.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream s = (Stream)response.GetResponseStream(); StreamReader readStream = new StreamReader(s); string dataString = readStream.ReadToEnd(); mWebhook _response = JsonConvert.DeserializeObject <mWebhook>(dataString); if (_response.reason == "SUCCESS") { DataSet dsMailSend = _objRepository.Opr_GenerateStudentDtl("ActivationLinkSent", studentid, AccessURL, "1", "Mail Sent", ""); } response.Close(); s.Close(); readStream.Close(); #endregion DateTime _NextDatetime = _datetime.AddSeconds(5); g : { } if (DateTime.Now <= _NextDatetime) { goto g; } } Message = "Activation links sent!"; Code = "success"; } } else { Message = "Error from server side. Kindly refresh the page and try again."; Code = "servererror"; } } catch (NullReferenceException ex) { Message = "Your session has been expired. Kindly login again."; Code = "sessionexpired"; Error = ex.Message; } catch (Exception ex) { Message = "Error from server side. Kindly refresh the page and try again."; Code = "servererror"; Error = ex.Message; } return(Json(new { m = Message, c = Code, e = Error }, JsonRequestBehavior.AllowGet )); }
//[RecaptchaFilter], bool CaptchaValid public JsonResult RegistationUser(Student_Register _obj) { bool flagCaptcha = false; bool flagValidID = true; bool flagDOB = true; string[] DMonths = null; mWebhook _response = null; if (this.Session["CaptchaImageText"].ToString() == _obj.Captchastr) // if (CaptchaValid) { flagCaptcha = true; DMonths = new[] { "04", "06", "09", "11" }; if (_obj.Month == "02") { if (Convert.ToInt32(_obj.Year) % 4 == 0) { if (Convert.ToInt32(_obj.Date) > 29) { flagDOB = false; } } else { if (Convert.ToInt32(_obj.Date) > 28) { flagDOB = false; } } } else if (DMonths.Contains(_obj.Month)) { if (Convert.ToInt32(_obj.Date) > 30) { flagDOB = false; } } if (flagDOB) { _obj.DateOfBirth = _obj.Date + "-" + _obj.Month + "-" + _obj.Year; StudentRepository _objRepository = new StudentRepository(); // _obj.CREATE_BY = Session["FA_USER_ID"].ToString(); string localIP = "?"; localIP = Request.ServerVariables["REMOTE_ADDR"].ToString(); _obj.Created_Ip = localIP; string password = Membership.GeneratePassword(8, 1); _obj.Random = password; Random rn = new Random(); #pragma warning disable SCS0005 // Weak random generator int month = rn.Next(1, 6); #pragma warning restore SCS0005 // Weak random generator StringBuilder hashPassword = new StringBuilder(); string new_password = _obj.ActualPassword; switch (month) { case 1: hashPassword.Append(Helper.ComputeHash(new_password, "MD5", null)); break; case 2: hashPassword.Append(Helper.ComputeHash(new_password, "SHA1", null)); break; case 3: hashPassword.Append(Helper.ComputeHash(new_password, "SHA256", null)); break; case 4: hashPassword.Append(Helper.ComputeHash(new_password, "SHA384", null)); break; case 5: hashPassword.Append(Helper.ComputeHash(new_password, "SHA512", null)); break; } _obj.ActualPassword = hashPassword.ToString(); _obj.Created_Ip = Request.ServerVariables["REMOTE_ADDR"].ToString(); DataSet ds = _objRepository.InsertStudentRegistration(_obj); SendEmail _objseedemail = new SendEmail(); if (ds.Tables[0].Rows.Count > 0) { _obj.studentid = ds.Tables[0].Rows[0]["UserName"].ToString(); if (ds.Tables[0].Rows[0]["Exist"].ToString() == "0") { flagValidID = true; string strform = ""; if (_obj.Email.ToString() != "") { #region Mail Sending Code #region Code to send mails simultaneously in a loop (By Amit: 14-06-2019 11:45 AM) //if (System.Web.HttpContext.Current.Application["UserCountForMail"] == null) //{ // System.Web.HttpContext.Current.Application["UserCountForMail"] = 1; //} //else //{ //} //int UserCountForMail = Convert.ToInt32(System.Web.HttpContext.Current.Application["UserCountForMail"]); //if (UserCountForMail < 4) //{ // UserCountForMail++; //} //else //{ // UserCountForMail = 1; //} //System.Web.HttpContext.Current.Application["UserCountForMail"] = UserCountForMail; //if (System.Web.HttpContext.Current.Application["UserCountForMail"] == null) //{ // System.Web.HttpContext.Current.Application["UserCountForMail"] = 1; //} //if (UserCountForMail == 1) //{ // strform = System.Configuration.ConfigurationManager.AppSettings["Emailusername1"]; //} //else if (UserCountForMail == 2) //{ // strform = System.Configuration.ConfigurationManager.AppSettings["Emailusername2"]; //} //else if (UserCountForMail == 3) //{ // strform = System.Configuration.ConfigurationManager.AppSettings["Emailusername3"]; //} //else if (UserCountForMail == 4) //{ // strform = System.Configuration.ConfigurationManager.AppSettings["Emailusername4"]; //} #endregion string ActivationLink = FullyQualifiedApplicationPath(ControllerContext.RequestContext.HttpContext.Request) + "admission/login?eid=" + Encrypt_Decrypt.EncryptData(_obj.Email, ""); //string Subject = "Student Login"; //StringBuilder MailBody = new StringBuilder(); //MailBody.Append("<br/>Dear " + _obj.FirstName + " " + _obj.LastName + ",<br/>"); //MailBody.Append("<br/>Greetings from 'Study In India' Team!"); //MailBody.Append("<br/>Thank you for registering at 'Study In India' Portal. Your application will be considered for the Academic Year of 2020-21."); //MailBody.Append("<br/>To activate your account <b><a target='_blank' href='" + ActivationLink + "'>click here </a> </b>"); //// MailBody.Append("<br/>Username: "******"UserName"].ToString() + "(You can also use your email id for logging in)"); //// MailBody.Append("<br/>Password: "******"<br/>Please note: This is an auto generated email.<br/>"); //MailBody.Append("<br/><br/><br/>Regards,<br/>"); //MailBody.Append("'Study In India' Team<br/>"); //MailBody.Append("<br/><strong>NOTE:</strong> This is an auto generated mail. Please do not respond to this mail.<br/>"); //string bcc = ""; //string cc = ""; //_objseedemail.SendEmailInBackgroundThread(strform, _obj.Email, bcc, cc, Subject, MailBody.ToString(), "", true); string MailMessage = ""; string MailSent = "1"; try { //_objseedemail.SendEmailForRegistration(strform, _obj.Email, bcc, cc, Subject, MailBody.ToString(), "", true); MailMessage = "Mail Sent"; MailSent = "1"; } catch (Exception ex) { MailMessage = ex.Message.ToString(); } #endregion #region Call PivotRoots Code int gotoIndex = 0; goback : { } string strUrl = "https://pivotroots.com/clients/studyinindia/webhooks/user_events"; WebRequest request = HttpWebRequest.Create(strUrl); request.Headers.Add("Request-Id", DateTime.Now.ToString("yyyyMMddhhmmss")); request.Method = "POST"; request.ContentType = "application/json"; request.Headers.Add("Client-Id", "b7a51eff57749dc0e733b74342c8b512"); request.Headers.Add("Client-Access-Token", "dfdd5aa8ea4a1e2fb5999dc213476c2a9b68efa7"); mWebhookRequestRegistration _objJsonRequest = new mWebhookRequestRegistration() { timestamp = DateTime.Now.ToString("yyyyMMddhhmmss"), user_id = _obj.studentid, @event = "new_registration", userName = _obj.FirstName + " " + _obj.LastName, emailID = _obj.Email, activationLink = ActivationLink, Country = ds.Tables[0].Rows[0]["CountryName"].ToString(), country_code = ds.Tables[0].Rows[0]["country_code"].ToString(), mobile = _obj.Mobile, whatsapp_consent = _obj.whatsapp_consent }; string data = JsonConvert.SerializeObject(_objJsonRequest); byte[] dataStream = Encoding.UTF8.GetBytes(data); request.ContentLength = dataStream.Length; Stream r = request.GetRequestStream(); r.Write(dataStream, 0, dataStream.Length); r.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream s = (Stream)response.GetResponseStream(); StreamReader readStream = new StreamReader(s); string dataString = readStream.ReadToEnd(); _response = JsonConvert.DeserializeObject <mWebhook>(dataString); if (_response.reason == "SUCCESS") { DataSet dsMailSend = _objRepository.Opr_GenerateStudentDtl("ActivationLinkSent", _obj.studentid, ActivationLink, MailSent, MailMessage, strform); response.Close(); s.Close(); readStream.Close(); } else { response.Close(); s.Close(); readStream.Close(); if ((gotoIndex++) < 3) { goto goback; } } #endregion } } else { flagValidID = false; } } } } return(Json(new { flagCaptcha = flagCaptcha, flagValidID = flagValidID, flagDOB = flagDOB }, JsonRequestBehavior.AllowGet )); }
public JsonResult RegistationUser(Student_Register _obj, bool CaptchaValid) { bool flagCaptcha = false; bool flagValidID = true; try { //if (this.Session["CaptchaImageText"].ToString() == _obj.Captchastr) if (CaptchaValid) { flagCaptcha = true; StudentRepository _objRepository = new StudentRepository(); // _obj.CREATE_BY = Session["FA_USER_ID"].ToString(); string localIP = "?"; localIP = Request.ServerVariables["REMOTE_ADDR"].ToString(); _obj.Created_Ip = localIP; string password = Membership.GeneratePassword(8, 1); _obj.Random = password; Random rn = new Random(); int month = rn.Next(1, 6); StringBuilder hashPassword = new StringBuilder(); string new_password = _obj.ActualPassword; switch (month) { case 1: hashPassword.Append(Helper.ComputeHash(new_password, "MD5", null)); break; case 2: hashPassword.Append(Helper.ComputeHash(new_password, "SHA1", null)); break; case 3: hashPassword.Append(Helper.ComputeHash(new_password, "SHA256", null)); break; case 4: hashPassword.Append(Helper.ComputeHash(new_password, "SHA384", null)); break; case 5: hashPassword.Append(Helper.ComputeHash(new_password, "SHA512", null)); break; } _obj.ActualPassword = hashPassword.ToString(); DataSet ds = _objRepository.InsertStudentRegistration(_obj); SendEmail _objseedemail = new SendEmail(); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Exist"].ToString() == "0") { flagValidID = true; if (_obj.Email.ToString() != "") { string strform = System.Configuration.ConfigurationManager.AppSettings["Emailusername"]; string Subject = "Student Login"; StringBuilder MailBody = new StringBuilder(); MailBody.Append("<br/>Dear Student, " + _obj.FirstName + " " + _obj.LastName + ",<br/>"); MailBody.Append("<br/>Thank you for registering at Study in India."); MailBody.Append("<br/>To activate your account <b><a target='_blank' href='" + FullyQualifiedApplicationPath(ControllerContext.RequestContext.HttpContext.Request) + "admission/login?eid=" + Encrypt_Decrypt.EncryptData(_obj.Email, "") + "'>click on the following link </a> </b>"); // MailBody.Append("<br/>Username: "******"UserName"].ToString() + "(You can also use your email id for logging in)"); // MailBody.Append("<br/>Password: "******"<br/>Please note: This is an auto generated email.<br/>"); MailBody.Append("<br/><br/><br/>Regards,<br/>"); MailBody.Append("Study in India Team<br/>"); string bcc = ""; string cc = ""; _objseedemail.SendEmailInBackgroundThread(strform, _obj.Email, bcc, cc, Subject, MailBody.ToString(), "", true); } } else { flagValidID = false; } } } } catch (Exception ex) { throw ex; } return(Json(new { flagCaptcha = flagCaptcha, flagValidID = flagValidID }, JsonRequestBehavior.AllowGet )); }