Commit 1045b02d02d9ecdbb93ca9075af3e7a58db42e56

Authored by Nikita Kulshreshtha
1 parent a949d27f

introduced logs and some conditions.

400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs
@@ -8,8 +8,10 @@ namespace AIAHTML5.API.Constants @@ -8,8 +8,10 @@ namespace AIAHTML5.API.Constants
8 public class AIAConstants 8 public class AIAConstants
9 { 9 {
10 public const string ERROR_IN_FECTHING_DETAILS = "Error in fecthing details."; 10 public const string ERROR_IN_FECTHING_DETAILS = "Error in fecthing details.";
11 -  
12 public const string USER_NOT_FOUND = "User not found."; 11 public const string USER_NOT_FOUND = "User not found.";
  12 + public const string MAIL_NOT_SENT = "Mail not sent.";
  13 +
  14 +
13 15
14 } 16 }
15 } 17 }
16 \ No newline at end of file 18 \ No newline at end of file
400-SOURCECODE/AIAHTML5.API/Controllers/ForgotUserController.cs
@@ -33,27 +33,40 @@ namespace AIAHTML5.API.Controllers @@ -33,27 +33,40 @@ namespace AIAHTML5.API.Controllers
33 //} 33 //}
34 public HttpResponseMessage Post([FromBody]JObject userInfo) 34 public HttpResponseMessage Post([FromBody]JObject userInfo)
35 { 35 {
36 - ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));  
37 - logger.Debug("inside POST"); 36 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  37 + logger.Debug("inside POST in ForgotUserController for emailId = " + userInfo["emailId"]);
38 38
39 dynamic userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo); 39 dynamic userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo);
40 if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS) 40 if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS)
41 - { 41 + {
  42 + logger.Debug("inside if in ForgotUserController userData.loginId= " + userData.loginId);
42 bool isMailSent = false; 43 bool isMailSent = false;
43 - string userDetails = Newtonsoft.Json.JsonConvert.SerializeObject(userData);  
44 - if (Convert.ToBoolean(userInfo["isPassword"]))  
45 - isMailSent = AIAHTML5.API.Models.ResetUser.SendEmail(userData, true);  
46 - else  
47 - isMailSent = AIAHTML5.API.Models.ResetUser.SendEmail(userData, false);  
48 - 44 + string userDetails = Newtonsoft.Json.JsonConvert.SerializeObject(userData);
  45 +
  46 + logger.Debug("1. inside if in ForgotUserController userDetails= " + userDetails);
  47 +
  48 + if (Convert.ToBoolean(userInfo["isPassword"]))
  49 + {
  50 + logger.Debug("2. isPassword= " + Convert.ToBoolean(userInfo["isPassword"]));
  51 +
  52 + isMailSent = AIAHTML5.API.Models.ResetUser.SendEmail(userData, true);
  53 + }
  54 + else
  55 + {
  56 + logger.Debug("3. isPassword= " + Convert.ToBoolean(userInfo["isPassword"]));
  57 +
  58 + isMailSent = AIAHTML5.API.Models.ResetUser.SendEmail(userData, false);
  59 + }
  60 + logger.Debug("isMailSent= " + isMailSent);
49 if (isMailSent) 61 if (isMailSent)
50 return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userDetails) }; 62 return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userDetails) };
51 else 63 else
52 - return new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(userData) }; 64 + return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.MAIL_NOT_SENT)};
53 } 65 }
54 else 66 else
55 - {  
56 - return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userData) }; //new StringContent(userData) 67 + {
  68 + logger.Debug("inside else in ForgotUserController userData= " + userData);
  69 + return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userData)}; //new StringContent(userData)
57 70
58 } 71 }
59 } 72 }
400-SOURCECODE/AIAHTML5.API/Models/ResetUser.cs
@@ -12,14 +12,17 @@ using AIAHTML5.API.Utility; @@ -12,14 +12,17 @@ using AIAHTML5.API.Utility;
12 using System.Text; 12 using System.Text;
13 using System.IO; 13 using System.IO;
14 using System.Net.Mime; 14 using System.Net.Mime;
15 -using System.Configuration; 15 +using System.Configuration;
16 16
17 namespace AIAHTML5.API.Models 17 namespace AIAHTML5.API.Models
18 { 18 {
19 public class ResetUser 19 public class ResetUser
20 { 20 {
21 public static bool SendEmail(dynamic UserDetails, bool isPassword) 21 public static bool SendEmail(dynamic UserDetails, bool isPassword)
22 - { 22 + {
  23 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  24 + logger.Debug("inside SendEmail in for isPassword =" + isPassword);
  25 +
23 try 26 try
24 { 27 {
25 List<LinkedResource> lstLinkedResource = new List<LinkedResource>(); 28 List<LinkedResource> lstLinkedResource = new List<LinkedResource>();
@@ -63,15 +66,16 @@ namespace AIAHTML5.API.Models @@ -63,15 +66,16 @@ namespace AIAHTML5.API.Models
63 resetPasswordLink = site_url + "?em:" + HttpUtility.UrlEncode(userMail); 66 resetPasswordLink = site_url + "?em:" + HttpUtility.UrlEncode(userMail);
64 } 67 }
65 else 68 else
66 - templatePath = "~/Templates/forgot-UserId.html";  
67 - 69 + templatePath = "~/Templates/forgot-UserId.html";
  70 +
  71 + logger.Debug("inside SendEmail for templatePath= " + templatePath + ", userId= " + userId + ", userMail= " + userMail + ",fullName= " + fullName + ",resetPasswordLink= " + resetPasswordLink);
68 string mailBody = ResetUser.GetMailBodyTextFromTemplate(templatePath, userId, userMail, fullName, resetPasswordLink); 72 string mailBody = ResetUser.GetMailBodyTextFromTemplate(templatePath, userId, userMail, fullName, resetPasswordLink);
69 73
70 lstToAddress.Add(userMail); 74 lstToAddress.Add(userMail);
71 75
72 - emailText = mailBody;  
73 -  
74 - 76 + emailText = mailBody;
  77 +
  78 + logger.Debug("emailText= " + emailText);
75 // for embedding images in email 79 // for embedding images in email
76 if (emailText.Contains("<img")) 80 if (emailText.Contains("<img"))
77 { 81 {
@@ -92,9 +96,9 @@ namespace AIAHTML5.API.Models @@ -92,9 +96,9 @@ namespace AIAHTML5.API.Models
92 if(!isPassword) 96 if(!isPassword)
93 mailSubject = "UserID recovery mail for: "; 97 mailSubject = "UserID recovery mail for: ";
94 else 98 else
95 - mailSubject = "Password recovery mail for: ";  
96 -  
97 - emailUtility.sHostName = "10.100.12.13"; 99 + mailSubject = "Password recovery mail for: ";
  100 +
  101 + emailUtility.sHostName = Convert.ToString(ConfigurationManager.AppSettings["HostAddress"]);
98 emailUtility.sFromAddress = Convert.ToString(ConfigurationManager.AppSettings["SenderEmailAddress"]); 102 emailUtility.sFromAddress = Convert.ToString(ConfigurationManager.AppSettings["SenderEmailAddress"]);
99 emailUtility.bIsBodyHtml = true; 103 emailUtility.bIsBodyHtml = true;
100 emailUtility.bEnableSsl = false; 104 emailUtility.bEnableSsl = false;
@@ -115,7 +119,10 @@ namespace AIAHTML5.API.Models @@ -115,7 +119,10 @@ namespace AIAHTML5.API.Models
115 } 119 }
116 120
117 protected static string GetMailBodyTextFromTemplate(string templatePath, string userId, string userMail, string fullName, string resetPasswordUrl) 121 protected static string GetMailBodyTextFromTemplate(string templatePath, string userId, string userMail, string fullName, string resetPasswordUrl)
118 - { 122 + {
  123 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  124 + logger.Debug("inside GetMailBodyTextFromTemplate for templatePath= " + templatePath + ", userId= " + userId + ", userMail= " + userMail + ",fullName= " + fullName + ",resetPasswordLink= " + resetPasswordUrl);
  125 +
119 string fileToRead = string.Empty; 126 string fileToRead = string.Empty;
120 string emailBody = string.Empty; 127 string emailBody = string.Empty;
121 try 128 try
@@ -138,7 +145,8 @@ namespace AIAHTML5.API.Models @@ -138,7 +145,8 @@ namespace AIAHTML5.API.Models
138 } 145 }
139 catch (Exception e) 146 catch (Exception e)
140 { 147 {
141 - emailBody = "Exception: " + e.Message; 148 + emailBody = "Exception: " + e.Message;
  149 + logger.Fatal("exception in GetMailBodyTextFromTemplate. msg= " + e.Message + ", stacktrace= " + e.StackTrace);
142 } 150 }
143 return emailBody; 151 return emailBody;
144 } 152 }
400-SOURCECODE/AIAHTML5.API/Models/Users.cs
@@ -55,6 +55,7 @@ namespace AIAHTML5.API.Models @@ -55,6 +55,7 @@ namespace AIAHTML5.API.Models
55 internal static dynamic GetUserByEmail(Newtonsoft.Json.Linq.JObject userInfo) 55 internal static dynamic GetUserByEmail(Newtonsoft.Json.Linq.JObject userInfo)
56 { 56 {
57 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); 57 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  58 + logger.Debug(" inside GetUserByEmail for emailId = " + userInfo["emailId"] );
58 var client = new MongoClient(); 59 var client = new MongoClient();
59 60
60 try 61 try
@@ -67,15 +68,21 @@ namespace AIAHTML5.API.Models @@ -67,15 +68,21 @@ namespace AIAHTML5.API.Models
67 FilterDefinition<dynamic> filterCondition = Builders<dynamic>.Filter.Eq("emailId", userInfo["emailId"].ToString().ToLower()); 68 FilterDefinition<dynamic> filterCondition = Builders<dynamic>.Filter.Eq("emailId", userInfo["emailId"].ToString().ToLower());
68 69
69 dynamic userDetails = collection.Find(Builders<dynamic>.Filter.And(filterCondition)).SingleOrDefault(); 70 dynamic userDetails = collection.Find(Builders<dynamic>.Filter.And(filterCondition)).SingleOrDefault();
70 -  
71 if (userDetails != null) 71 if (userDetails != null)
  72 + {
  73 + logger.Debug("userDetails= " + userDetails.loginId);
  74 +
72 return userDetails; 75 return userDetails;
  76 + }
73 else 77 else
  78 + {
  79 + logger.Debug("user not found");
74 return AIAConstants.USER_NOT_FOUND; 80 return AIAConstants.USER_NOT_FOUND;
  81 + }
75 } 82 }
76 catch (Exception e) 83 catch (Exception e)
77 { 84 {
78 - logger.Fatal("Exception= " + e.Message); 85 + logger.Fatal("Exception= " + e.Message+", stacktrace = "+e.StackTrace);
79 return AIAConstants.ERROR_IN_FECTHING_DETAILS; 86 return AIAConstants.ERROR_IN_FECTHING_DETAILS;
80 } 87 }
81 } 88 }
400-SOURCECODE/AIAHTML5.API/Utility/EmailUtility.cs
@@ -7,7 +7,8 @@ using System.Collections; @@ -7,7 +7,8 @@ using System.Collections;
7 using System.Xml; 7 using System.Xml;
8 using System.Text; 8 using System.Text;
9 using System.IO; 9 using System.IO;
10 -using System.Net.Mail; 10 +using System.Net.Mail;
  11 +using log4net;
11 12
12 namespace AIAHTML5.API.Utility 13 namespace AIAHTML5.API.Utility
13 { 14 {
@@ -41,7 +42,10 @@ namespace AIAHTML5.API.Utility @@ -41,7 +42,10 @@ namespace AIAHTML5.API.Utility
41 } 42 }
42 43
43 public void SendSmtpEmail() 44 public void SendSmtpEmail()
44 - { 45 + {
  46 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  47 + logger.Debug("inside SendSmtpEmail");
  48 +
45 try 49 try
46 { 50 {
47 MailMessage sMail = new MailMessage(); 51 MailMessage sMail = new MailMessage();
@@ -53,8 +57,8 @@ namespace AIAHTML5.API.Utility @@ -53,8 +57,8 @@ namespace AIAHTML5.API.Utility
53 { 57 {
54 foreach (var sItem in sToAddresses) 58 foreach (var sItem in sToAddresses)
55 { 59 {
56 - sMail.To.Add(sItem);  
57 - 60 + sMail.To.Add(sItem);
  61 + logger.Debug("sToAddresses= " + sItem);
58 } 62 }
59 } 63 }
60 64
@@ -62,7 +66,9 @@ namespace AIAHTML5.API.Utility @@ -62,7 +66,9 @@ namespace AIAHTML5.API.Utility
62 { 66 {
63 foreach (var sItem in sBccAddresses) 67 foreach (var sItem in sBccAddresses)
64 { 68 {
65 - sMail.Bcc.Add(sItem); 69 + sMail.Bcc.Add(sItem);
  70 + logger.Debug("sBccAddresses= " + sItem);
  71 +
66 } 72 }
67 } 73 }
68 74
@@ -70,21 +76,31 @@ namespace AIAHTML5.API.Utility @@ -70,21 +76,31 @@ namespace AIAHTML5.API.Utility
70 76
71 if (sAlternateView != null) 77 if (sAlternateView != null)
72 { 78 {
73 - sMail.AlternateViews.Add(sAlternateView); 79 + sMail.AlternateViews.Add(sAlternateView);
  80 + logger.Debug("sAlternateView= " + sAlternateView);
  81 +
74 } 82 }
75 else 83 else
76 { 84 {
77 - sMail.Body = sBodyText; 85 + sMail.Body = sBodyText;
  86 + logger.Debug("sMail.Body= " + sBodyText);
  87 +
78 } 88 }
79 89
80 - sMail.Subject = sSubject; 90 + sMail.Subject = sSubject;
  91 + logger.Debug("sMail.Subject= " + sSubject);
  92 +
81 if (sAttachments != null) 93 if (sAttachments != null)
82 { 94 {
83 foreach (var sItem in sAttachments) 95 foreach (var sItem in sAttachments)
84 { 96 {
85 - sMail.Attachments.Add(sItem); 97 + sMail.Attachments.Add(sItem);
  98 + logger.Debug("sAttachments= " + sAttachments);
  99 +
  100 +
86 } 101 }
87 - } 102 + }
  103 + logger.Debug("sUserName= " + sUserName + ", sPassword= " + sPassword);
88 104
89 SmtpServer.Port = iPort; 105 SmtpServer.Port = iPort;
90 SmtpServer.Credentials = new System.Net.NetworkCredential(sUserName, sPassword); 106 SmtpServer.Credentials = new System.Net.NetworkCredential(sUserName, sPassword);
@@ -105,12 +121,14 @@ namespace AIAHTML5.API.Utility @@ -105,12 +121,14 @@ namespace AIAHTML5.API.Utility
105 } 121 }
106 122
107 mm.IsBodyHtml = true; 123 mm.IsBodyHtml = true;
108 - SendMail(mm); 124 + SendMail(mm);
  125 + logger.Debug("after sending email");
109 } 126 }
110 127
111 } 128 }
112 catch (Exception ex) 129 catch (Exception ex)
113 - { 130 + {
  131 + logger.Fatal("exception in SendSmtpEmail.msg= " + ex.Message + ", stacktarce= " + ex.StackTrace);
114 throw ex; 132 throw ex;
115 } 133 }
116 } 134 }
400-SOURCECODE/AIAHTML5.API/Web.config
@@ -37,8 +37,8 @@ @@ -37,8 +37,8 @@
37 <add key="SMTPAddress" value="smtp.emailsrvr.com" /> 37 <add key="SMTPAddress" value="smtp.emailsrvr.com" />
38 <add key="SMTPPort" value="587" /> 38 <add key="SMTPPort" value="587" />
39 <add key="EnableSSL" value="false" /> 39 <add key="EnableSSL" value="false" />
40 - <add key="NotifyEmailAddress" value="support@interactiveanatomy.com" />  
41 <add key="Site_Url" value ="//52.2.38.120"/> 40 <add key="Site_Url" value ="//52.2.38.120"/>
  41 + <add key ="HostAddress" value="10.100.12.13" />
42 </appSettings> 42 </appSettings>
43 <system.web> 43 <system.web>
44 <compilation debug="true" targetFramework="4.5" /> 44 <compilation debug="true" targetFramework="4.5" />
400-SOURCECODE/AIAHTML5.API/bin/AIAHTML5.API.dll
No preview for this file type
400-SOURCECODE/AIAHTML5.API/bin/AIAHTML5.API.dll.config
@@ -39,6 +39,7 @@ @@ -39,6 +39,7 @@
39 <add key="EnableSSL" value="false" /> 39 <add key="EnableSSL" value="false" />
40 <add key="NotifyEmailAddress" value="support@interactiveanatomy.com" /> 40 <add key="NotifyEmailAddress" value="support@interactiveanatomy.com" />
41 <add key="Site_Url" value ="//52.2.38.120"/> 41 <add key="Site_Url" value ="//52.2.38.120"/>
  42 + <add key ="HostAddress" value="10.100.12.13" />
42 </appSettings> 43 </appSettings>
43 <system.web> 44 <system.web>
44 <compilation debug="true" targetFramework="4.5" /> 45 <compilation debug="true" targetFramework="4.5" />
@@ -48,7 +49,7 @@ @@ -48,7 +49,7 @@
48 <applicationSettings> 49 <applicationSettings>
49 <AIAHTML5.API.Properties.Settings> 50 <AIAHTML5.API.Properties.Settings>
50 <setting name="AIAConnectionString" serializeAs="String"> 51 <setting name="AIAConnectionString" serializeAs="String">
51 - <value>192.168.90.157:27017</value> 52 + <value>localhost:27017</value>
52 </setting> 53 </setting>
53 <setting name="database" serializeAs="String"> 54 <setting name="database" serializeAs="String">
54 <value>AIA</value> 55 <value>AIA</value>
400-SOURCECODE/AIAHTML5.API/bin/AIAHTML5.API.pdb
No preview for this file type
400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js
@@ -179,7 +179,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic @@ -179,7 +179,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
179 $rootScope.SendMailToUser = function (userInfo, isMailForPassword) { 179 $rootScope.SendMailToUser = function (userInfo, isMailForPassword) {
180 if ((userInfo.emailId != null) && (userInfo.emailId != '')) { 180 if ((userInfo.emailId != null) && (userInfo.emailId != '')) {
181 if (validateEmail(userInfo.emailId)) { 181 if (validateEmail(userInfo.emailId)) {
182 - if (isMailForPassword == 'true') 182 + if (isMailForPassword == true)
183 userInfo.isPassword = true; 183 userInfo.isPassword = true;
184 else 184 else
185 userInfo.isPassword = false; 185 userInfo.isPassword = false;
@@ -187,10 +187,13 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic @@ -187,10 +187,13 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
187 AuthenticationService.SendMailToUser(userInfo) 187 AuthenticationService.SendMailToUser(userInfo)
188 .then(function (result) { 188 .then(function (result) {
189 if (result == LoginConstants.USER_NOT_FOUND) { 189 if (result == LoginConstants.USER_NOT_FOUND) {
190 - alert("Error occured."); 190 + alert(LoginConstants.USER_NOT_FOUND);
191 } 191 }
192 else if (result == LoginConstants.ERROR_IN_FECTHING_DETAILS) { 192 else if (result == LoginConstants.ERROR_IN_FECTHING_DETAILS) {
193 - alert("Error occured."); 193 + alert("An error occured.");
  194 + }
  195 + else if (result == LoginConstants.MAIL_NOT_SENT) {
  196 + alert("Due to some issue, email not sent.");
194 } 197 }
195 else { 198 else {
196 if (result.loginId != undefined || result.loginId != "" || result.loginId != null) { 199 if (result.loginId != undefined || result.loginId != "" || result.loginId != null) {
400-SOURCECODE/AIAHTML5.Web/app/main/AIA.js
@@ -283,6 +283,7 @@ AIA.constant(&#39;ImageTypes&#39;, [&#39;Illustration&#39;, &#39;Cadaver Photograph&#39;, &#39;Radiograph&#39;]) @@ -283,6 +283,7 @@ AIA.constant(&#39;ImageTypes&#39;, [&#39;Illustration&#39;, &#39;Cadaver Photograph&#39;, &#39;Radiograph&#39;])
283 AIA.constant("LoginConstants", { 283 AIA.constant("LoginConstants", {
284 "USER_NOT_FOUND": "User not found.", 284 "USER_NOT_FOUND": "User not found.",
285 "ERROR_IN_FECTHING_DETAILS": "Error in fecthing details.", 285 "ERROR_IN_FECTHING_DETAILS": "Error in fecthing details.",
  286 + "MAIL_NOT_SENT" : "Mail not sent.",
286 287
287 }) 288 })
288 289
400-SOURCECODE/AIAHTML5.Web/index.html
@@ -243,7 +243,7 @@ @@ -243,7 +243,7 @@
243 </form> 243 </form>
244 </div> 244 </div>
245 <div class="modal-footer"> 245 <div class="modal-footer">
246 - <button type="button" class="btn btn-primary btn-block" ng-click="SendMailToUser(userInfo, 'false')">Send Mail</button> 246 + <button type="button" class="btn btn-primary btn-block" ng-click="SendMailToUser(userInfo, false)">Send Mail</button>
247 </div> 247 </div>
248 <!--<div style="color: maroon; font-weight: bold; " ng-if="message">{{message}}</div>--> 248 <!--<div style="color: maroon; font-weight: bold; " ng-if="message">{{message}}</div>-->
249 </div> 249 </div>
@@ -268,7 +268,7 @@ @@ -268,7 +268,7 @@
268 </form> 268 </form>
269 </div> 269 </div>
270 <div class="modal-footer"> 270 <div class="modal-footer">
271 - <button type="button" class="btn btn-primary btn-block" ng-click="SendMailToUser(userInfo, 'true')">Send Mail</button> 271 + <button type="button" class="btn btn-primary btn-block" ng-click="SendMailToUser(userInfo, true)">Send Mail</button>
272 </div> 272 </div>
273 <!--<div style="color: maroon; font-weight: bold; " ng-if="message">{{message}}</div>--> 273 <!--<div style="color: maroon; font-weight: bold; " ng-if="message">{{message}}</div>-->
274 </div> 274 </div>