eNewsletter Subscription
Error executing template "Designs/PLC/UserManagement/CreateProfile/email_subscribe.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_0a790a34b78b491e9d2d490b29445838.Execute() in E:\www\uat.petloverscentre.co.th\Solution\Files\Templates\Designs\PLC\UserManagement\CreateProfile\email_subscribe.cshtml:line 115
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()
1 @using DWAPAC.PLC.Services
2 @using System.Web
3
4
5 @{
6 string siteUrl = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;
7 string redirectLink = "/" + GetGlobalValue("Global:Area.LongLang") + "/newlettersignup/burp-1";
8 if(siteUrl.Contains("approvalKey"))
9 {
10 System.Web.HttpContext.Current.Response.Redirect(redirectLink);
11 }
12 }
13
14 @{
15 if( !string.IsNullOrWhiteSpace(System.Web.HttpContext.Current.Request["UserManagement_Form_Email"]))
16 {
17 var validateEmail = System.Web.HttpContext.Current.Request["UserManagement_Form_Email"];
18 var user = Dynamicweb.Security.UserManagement.User.GetUserByEmailAddress(validateEmail);
19 if(user != null)
20 {
21 if( !user.Active)
22 {
23 user.EmailAllowed = true;
24 user.Save();
25 <text>
26 <script>
27 location.href='/Default.aspx?Id=@GetPageIdByNavigationTag("EmailReactivated")&Email=@validateEmail'
28 </script>
29 </text>
30 }
31 }
32 }
33 }
34
35 @if(GetLoop("FormValidationErrors").Count > 0)
36 {
37 Dynamicweb.Security.UserManagement.User dwUser = new Dynamicweb.Security.UserManagement.User();
38 dwUser = Dynamicweb.Security.UserManagement.User.GetUserByEmailAddress(System.Web.HttpContext.Current.Request["UserManagement_Form_Email"]);
39 <div id="errormessages">
40 <ul>
41 @foreach(var FormValidationError in GetLoop("FormValidationErrors"))
42 {
43 @*if(dwUser.EmailAllowed){
44 <p style="color:red;margin-left: -17px;">@Translate("Email is already subscribed to PLC's e-Newsletter.")</p>
45 }else{*@
46 <text>
47 <script>
48 location.href='/Default.aspx?Id=@GetPageIdByNavigationTag("NewsletterSubscribe")'
49 </script>
50 </text>
51 @*}*@
52 }
53 </ul>
54 </div>
55
56
57 if(dwUser != null && dwUser.Active == true)
58 {
59 string errorMessage = "";
60 string toMailAddress = dwUser.Email;
61 string successMessage = "";
62 string status = "";
63 string subject = "You already subscribed to PLC's e-Newsletter.";
64 string logoTable = "<table class='logos' cellpadding='0' cellspacing='0' style='box-sizing: border-box; font-size: 15px; width: 100%; margin: 0;'><tr style='box-sizing: border-box; font-size: 15px; margin: 0;'><td width='35%' style='box-sizing: border-box; font-size: 15px; margin: 0;' align='left' valign='top'><img src='https://uat.petloverscentre.co.th/Files/Images/plc/images/logo.gif' style='box-sizing: border-box; font-size: 15px; max-width: 100%; margin: 0;' /></td><td width='30%' style='box-sizing: border-box; font-size: 15px; margin: 0;' valign='top'> </td><td width='35%' style='box-sizing: border-box; font-size: 15px; margin: 0;' align='right' valign='top'><img src='https://uat.petloverscentre.co.th/Files/Images/plc/images/ico/tpslogo.gif' style='box-sizing: border-box; font-size: 15px; max-width: 100%; margin: 0;' /></td></tr></table>";
65
66 var body = System.Web.HttpContext.Current.Request["body"];
67 body += "<style>.one {width: 15%;height: 40px;background:#210a05;float: left;}.two {margin-left: 15%;height: 40px;background:#ad2c13;color:white;}</style>";
68 body += logoTable;
69 body += "<br/>";
70 body += "<br/>";
71 body += "Dear " + dwUser.Name + ",";
72 body += "<br/><br/>";
73 body += dwUser.Email + " is already subscribed to PLC's e-Newsletter.";
74 body += "<br/><br/>";
75 body += "Yours sincerely,<br />Pet Lovers Centre Team<br /><br/><small><i>This is a computer generated email. Please do not reply.</i></small>";
76 body += "<section class=\"container\">";
77 body += "<div class=\"one\" style=\"width:15%;height:40px;background:#210a05;float:left;\"></div>";
78 body += "<div class=\"two\" style=\"margin-left:15%;height:40px;background:#ad2c13;color:white;\"><p style=\"float:right;font-size:16px;margin-top:11px;margin-right:15px;\">Asia's <i>preferred</i> Pet store!</p></div>";
79 body += "</section>";
80 try
81 {
82 dwUser.EmailAllowed = true;
83 dwUser.Save();
84
85 //System.Web.Helpers.WebMail.SmtpServer = "smtp.1and1.com";
86 //System.Web.Helpers.WebMail.SmtpPort = 587;
87 //System.Web.Helpers.WebMail.EnableSsl = true;
88 //System.Web.Helpers.WebMail.UserName = "hl.thaw@edwincs.com";
89 //System.Web.Helpers.WebMail.Password ="p@ssw0rd";
90
91 System.Web.Helpers.WebMail.SmtpServer = Dynamicweb.Configuration.SystemConfiguration.Instance.GetValue("/Globalsettings/System/MailServer/Server");
92 System.Web.Helpers.WebMail.SmtpPort = Convert.ToInt32(Dynamicweb.Configuration.SystemConfiguration.Instance.GetValue("/Globalsettings/System/MailServer/Port"));
93 System.Web.Helpers.WebMail.EnableSsl = Convert.ToBoolean(Dynamicweb.Configuration.SystemConfiguration.Instance.GetValue("/Globalsettings/System/MailServer/UseSll"));
94 System.Web.Helpers.WebMail.UserName = Dynamicweb.Configuration.SystemConfiguration.Instance.GetValue("/Globalsettings/System/MailServer/Username");
95 System.Web.Helpers.WebMail.Password = Dynamicweb.Configuration.SystemConfiguration.Instance.GetValue("/Globalsettings/System/MailServer/Password");
96
97 System.Web.Helpers.WebMail.From = "donotreply@petloverscentre.co.th";
98 System.Web.Helpers.WebMail.Send(to: toMailAddress, subject: subject, body: body );
99 successMessage = "An email has been sent to your email.";
100 }
101 catch (Exception ex )
102 {
103 errorMessage = ex.Message;
104 }
105 }
106 }
107
108 @{
109 Random rnd = new Random();
110 string dummyUserName = rnd.Next(1, 51).ToString() + rnd.Next(100).ToString() + rnd.Next(50, 101).ToString();
111 }
112
113 <div class="dottedBoxGrey form" style="padding-top:1em;">
114 <p><strong>@Translate("Subscribe to our eNewsletter and be one of the first to receive the latest news on our products and special promotions!")</strong></p>
115 @GetString("UserManagement:User.FormStart")
116 <div class="formContact">
117 <input type="hidden" name="UserManagement_Form_UserName" id="UserManagement_Form_UserName" value="@dummyUserName">
118 <input type="hidden" name="UserManagement_Form_NewPassword" id="UserManagement_Form_NewPassword" value="@dummyUserName A!a1">
119 <input type="hidden" name="UserManagement_Form_NewPasswordConfirm" id="UserManagement_Form_NewPasswordConfirm" value="@dummyUserName A!a1">
120 <input type="hidden" name="CustomField.AccessUser_AccessUser_DOB" id="CustomField.AccessUser_AccessUser_DOB" value="01/01/1900">
121 <input type="hidden" name="CustomField.AccessUser_AccessUser_ExpryDate" id="CustomField.AccessUser_AccessUser_ExpryDate" value="01/01/1900">
122 <p><label>Name:</label><input name="UserManagement_Form_Name" type="text" id="UserManagement_Form_Name"></p>
123 <p><label>Email:</label><input name="UserManagement_Form_Email" type="text" id="UserManagement_Form_Email" value='@System.Web.HttpContext.Current.Request["UserManagement_Form_Email"].Replace(" ", "")'></p>
124 <p>
125 <input name="UserManagement_Form_EmailAllowed" type="checkbox" id="UserManagement_Form_EmailAllowed" value="True" checked="checked" />
126 <lable>@Translate("I agree to receive information, news, offers and the promotions from Pet Lovers Centre (PLC), its subsidiaries, affiliates or any other party acting on behalf of PLC.")</label>
127 </p>
128 <p>@GetString("UserManagement:User.EmailAllowed.Hidden.Input")</p>
129 <hr class="dotted"/>
130 <p class="clearfix"></p>
131 <input type="submit" id="submitter" value="Subscribe">
132 </div>
133 @GetString("UserManagement:User.FormEnd")
134 </div>
135 <script>
136 $(document).ready(function(){
137 $("#UserManagement_Form_Email").focusout(function() {
138 $('#UserManagement_Form_Email').val($('#UserManagement_Form_Email').val().replace(/\s+/g, ''));
139 });
140 })
141 $('form[name="UserManagementEditForm"]').submit(function(){
142
143
144 if(!$("#UserManagement_Form_EmailAllowed").is(':checked'))
145 {
146 errorMessage= ' @Translate("You have to read and agree the Terms and Conditions and Privacy Policy.")';
147 ShowMessage(errorMessage);
148 return false;
149 }
150 if($("#UserManagement_Form_Name").val()=="")
151 {
152 errorMessage = '@Translate("User Name Cannot Be Empty")';
153 ShowMessage(errorMessage);
154 return false;
155 }
156 if($("#UserManagement_Form_Email").val()=="" || !isEmailAddress($("#UserManagement_Form_Email").val()) )
157 {
158 if($("#UserManagement_Form_Email").val()=="")
159 {errorMessage = "User Email Cannot Be Empty";}
160 if(!isEmailAddress($("#UserManagement_Form_Email").val()))
161 {errorMessage = '@Translate("User Email is not valid")';}
162 ShowMessage(errorMessage);
163 return false;
164 }
165
166 return true;
167
168 });
169 function ShowMessage(messgarPara) {
170 var NewDialog;
171 NewDialog = $('<div class="popup" title="Message" style="text-align: center;padding-top: 2em;">' + messgarPara + '</div>');
172 NewDialog.dialog({
173 resizable: false,
174 modal: true,
175 open: function(event, ui) {
176 $(".ui-dialog-titlebar-close").hide();
177 },
178 show: 'clip',
179 buttons: {
180 "Ok": function() {
181 $(this).dialog("close");
182 }
183 }
184 });
185 }
186
187 function isEmailAddress(str) {
188
189 var re = /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;
190 return re.test(str);
191
192 }
193 </script>
194 <style>
195 .ui-dialog-titlebar, .ui-dialog-buttonset button{
196 background:#662010 !important;
197 padding: 7px;
198 text-align: center;
199 color: #FFF !important;
200 }
201 .popup.ui-dialog-content.ui-widget-content{
202 padding:2em!important;
203 }
204 .ui-dialog-titlebar-close{
205 background:#f6f6f6;
206 border: 1px solid #c5c5c5;
207 }
208
209 .ui-icon-closethick{
210 margin-bottom: 5px;
211 }
212
213 .ui-dialog-buttonset button:hover{
214 background:#AD2C13;
215 color: #FFF;
216 }
217 .ui-dialog {
218 top: 700px !important;
219 }
220 </style>
221