public async Task <IHttpActionResult> SendSMS(twilioModel model) { var tosms = ""; if (model.countryCode != null) { tosms = "+" + model.countryCode + model.mobileNo; } else { tosms = "+" + model.mobileNo; } try { // Find your Account Sid and Token at twilio.com/console var accountSid = "AC59287b3995152a1dc20fa6a9238fbe6b"; var authToken = "34a067180051d73fb55ae8dbbea53441"; TwilioClient.Init(accountSid, authToken); var message = MessageResource.Create( body: model.messagebody, from: new PhoneNumber("+17014014499"), to: new PhoneNumber(tosms) ); Console.Write(message.Sid); //var json = new JavaScriptSerializer().Serialize(message); //return message.Sid; } catch (Exception ex) { } return(Ok()); }
public async Task <HttpResponseMessage> UserSignUp(SignUpModelRequset objSignUpModelRequset) { SignUpResponseModelResponse result = new SignUpResponseModelResponse(); if (ModelState.IsValid) { try { IsPasswordValid = (Regex.IsMatch(objSignUpModelRequset.Password, passwordRegex)); //if (IsPasswordValid == true) //{ string IsMailIdExist = _objFriendFitDBEntity.Database.SqlQuery <string>("Select Email from UserProfile where Email={0}", objSignUpModelRequset.Email).FirstOrDefault(); if (IsMailIdExist == null) { var model = _objIUserSettings.AddUser(objSignUpModelRequset); Random random = new Random(); Int64 otp = Convert.ToInt64(random.Next(1000, 9999)); /// to specify range for random number Int64 UserId = _objFriendFitDBEntity.Database.SqlQuery <Int64>("Select Id from UserProfile where Email={0}", objSignUpModelRequset.Email).FirstOrDefault(); int rowEffected = _objFriendFitDBEntity.Database.ExecuteSqlCommand("CreateNewToken @UserId=@UserId,@TokenCode=@TokenCode,@ExpiryDate=@ExpiryDate", new SqlParameter("UserId", UserId), new SqlParameter("TokenCode", Guid.NewGuid().ToString() + UserId.ToString() + Guid.NewGuid().ToString()), new SqlParameter("ExpiryDate", DateTime.Now.AddDays(7))); string Token = _objFriendFitDBEntity.Database.SqlQuery <string>("Select TokenCode from UserToken where UserId={0}", UserId).FirstOrDefault(); //mail sending after registration if (objSignUpModelRequset.Email != null) { var SendingMessage = new MailMessage(); SendingMessage.To.Add(new MailAddress(objSignUpModelRequset.Email)); // replace with valid value SendingMessage.From = new MailAddress("*****@*****.**"); // replace with valid value SendingMessage.Subject = "Verify your email (noti.fit)"; SendingMessage.Body = "Hi,<br/>Congratulations on signing up to noti.fit, the fitness tracker that keeps you honest!<br/><br/>Please visit <a href='" + RegistrationUrl + Token + "'>" + RegistrationUrl + Token + "</a> <br/> to verify your email address and activate your account, or copy the link into a browser if you can't open it from your email address.<br/><br/>Kind regards,<br/>The noti.fit team"; SendingMessage.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // replace with valid value Password = "******" // replace with valid value }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(SendingMessage); } //track sent Email time for expiry time : EmailTimeSaveModel objreq = new EmailTimeSaveModel(); objreq.UserId = UserId; objreq.ResetMail = false; objreq.VerifyMail = true; objreq.MailSentTime = DateTime.Now.TimeOfDay; EmailTrackerWrapper wrapper = new EmailTrackerWrapper(); wrapper.EmailTimeSave(objreq); result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.OK); result.Response.Message = "Please check your Email for further instructions"; } else { FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/Content/ErrorLog.txt"), FileMode.Append, FileAccess.Write); StreamWriter swr = new StreamWriter(fs); swr.Write("Enter ur Exception Here"); swr.Close(); result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.Unauthorized); result.Response.Message = "This Mail Id is not registered"; } //mail SMS after registration if (objSignUpModelRequset.MobileNumber != null) { twilioModel tm = new twilioModel(); tm.countryCode = objSignUpModelRequset.CountryId; tm.mobileNo = objSignUpModelRequset.MobileNumber; tm.messagebody = "Hi " + objSignUpModelRequset.FirstName + ", Welcome to noti.fit. Please confirm your mobile at <a href='" + RegistrationUrl + Token + "'>" + RegistrationUrl + Token + "</a> - If this wasn't you, ignore this SMS or decline at the link"; var SMSStatus = SMSCont.SendSMS(tm); //track sent Email time for expiry time : EmailTimeSaveModel objreq = new EmailTimeSaveModel(); objreq.UserId = UserId; objreq.ResetMail = false; objreq.VerifyMail = true; objreq.MailSentTime = DateTime.Now.TimeOfDay; EmailTrackerWrapper wrapper = new EmailTrackerWrapper(); wrapper.EmailTimeSave(objreq); result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.OK); result.Response.Message = "Please check your Mobile for further instructions"; } else { FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/Content/ErrorLog.txt"), FileMode.Append, FileAccess.Write); StreamWriter swr = new StreamWriter(fs); swr.Write("Enter ur Exception Here"); swr.Close(); result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.Unauthorized); result.Response.Message = "This Mobile No. is not registered"; } // if (model > 0) { result.Response.Token = Token; result.Response.UserId = UserId; result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.OK); result.Response.Message = "Check your email and confirm your account, you must be confirmed " + " " + "before you can log in."; } else { result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.NotAcceptable); result.Response.Message = "The Data which you are providing it is in the wrong format"; } } else { result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.Ambiguous); result.Response.Message = "MailID elready Exist"; } //} //else //{ // result.StatusCode = Convert.ToInt32(HttpStatusCode.NotAcceptable); // result.Message = "Password Must contain at least one number and one uppercase and lowercase letter, and atleast one special character and must be in between 6 to 20 characters"; //} } catch (Exception ex) { result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.BadRequest); _response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Some error occurred"); } _response = Request.CreateResponse(HttpStatusCode.OK, result); } else { ModelState.AddModelError("", "One or more errors occurred."); } return(_response); }
public HttpResponseMessage AddFriendInvitation(AddFriendInvitationRequestModel objFriendInvitation) { AddFriendIFitResponse result = new AddFriendIFitResponse(); try { var headers = Request.Headers; string token = headers.Authorization.Parameter.ToString(); Int64 UserId = _objFriendFitDBEntity.Database.SqlQuery <Int64>("select UserId from UserToken where TokenCode={0}", token).FirstOrDefault(); string checkuser = _objFriendFitDBEntity.Database.SqlQuery <string>("select Email from FriendsInvitation where Email={0}", objFriendInvitation.Email).FirstOrDefault(); string UserName = _objFriendFitDBEntity.Database.SqlQuery <string>("select FirstName from UserProfile where Id={0}", UserId).FirstOrDefault(); int value = _objIFriendInvitationRepository.AddFriendInvitation(objFriendInvitation); string RegistrationUrl = WebConfigurationManager.AppSettings["FrendFitSignUp"]; #region send mail for notification if (objFriendInvitation.Email != null) { if (objFriendInvitation.Email != "") { var SendingMessage = new MailMessage(); SendingMessage.To.Add(new MailAddress(objFriendInvitation.Email)); // replace with valid value SendingMessage.From = new MailAddress("*****@*****.**"); // replace with valid value SendingMessage.Subject = "Notification your email (noti.fit)"; //SendingMessage.Body = " <p><strong> Hi " + objFriendInvitation.Email + "</ strong > ,<br/>Congratulations for on signing up to noti.fit so please click on,<br/><br/><strong>Please visit</strong> <a href='" + RegistrationUrl +"'>" + RegistrationUrl+ "</a> <br/> to fill the details and click on sign up button<br/><br/>Kind regards,<br/>The noti.fit team"; SendingMessage.Body = "<p>Hi " + objFriendInvitation.FriendsName + "</p><p>Your friend " + objFriendInvitation.Email + " has invited you to track their workouts on noti.fit!noti.fit is a workout tracker that sends you notifications when your friend misses a workout.</ p >< p > Please sign up at " + RegistrationUrl + " to get started!</ p >< p > Cheers<strong>,</ strong >< br /> The noti.fit tea</ p > "; SendingMessage.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // replace with valid value Password = "******" // replace with valid value }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; smtp.Send(SendingMessage); } } } #endregion #region notification via sms if (objFriendInvitation.MobileNumber != null) { if (objFriendInvitation.MobileNumber != "") { twilioModel tm = new twilioModel(); tm.mobileNo = objFriendInvitation.MobileNumber; tm.messagebody = "Hi " + UserName + ", " + objFriendInvitation.FriendsName + " has nominated you to receive their workout reminders. Please accept/ decline at " + RegistrationUrl + " or ignore this text for no further communication."; var SMSStatus = SMSCont.SendSMS(tm); } } #endregion if (value > 0) { result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.OK); result.Response.Message = "Friend invitation Added successfully"; } else { result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.NotAcceptable); result.Response.Message = "Some parameters is incorrect"; } } catch (Exception ex) { result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.BadRequest); _response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Some error occurred"); } _response = Request.CreateResponse(HttpStatusCode.OK, result); return(_response); }