Commit 2808e788ecb4a3b9d2830dea3ed7d56d3bd18e58

Authored by Nikita Kulshreshtha
1 parent 8423ce8c

made some changes in forgotPassword

400-SOURCECODE/AIAHTML5.API/Controllers/ForgotUserController.cs
... ... @@ -11,6 +11,7 @@ using Newtonsoft.Json.Linq;
11 11 using AIAHTML5.API.Models;
12 12 using AIAHTML5.API.Utility;
13 13 using System.Collections;
  14 +using System.Data.SqlClient;
14 15  
15 16 namespace AIAHTML5.API.Controllers
16 17 {
... ... @@ -27,50 +28,7 @@ namespace AIAHTML5.API.Controllers
27 28 {
28 29 return "value";
29 30 }
30   -
31   - // POST api/<controller>
32   - //public void Post([FromBody]string value)
33   - //{
34   - //}
35   - //public HttpResponseMessage Post([FromBody]JObject userInfo)
36   - //{
37   - // ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
38   - // logger.Debug("inside POST in ForgotUserController for emailId = " + userInfo["emailId"]);
39   -
40   - // dynamic userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo);
41   - // if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS)
42   - // {
43   - // //logger.Debug("inside if in ForgotUserController userData.loginId= " + userData.LoginId);
44   - // bool isMailSent = false;
45   - // string userDetails = Newtonsoft.Json.JsonConvert.SerializeObject(userData);
46   -
47   - // logger.Debug("1. inside if in ForgotUserController userDetails= " + userDetails);
48   -
49   - // if (Convert.ToBoolean(userInfo["havePassword"]))
50   - // {
51   - // logger.Debug("2. havePassword= " + Convert.ToBoolean(userInfo["havePassword"]));
52   -
53   - // isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"]));
54   - // }
55   - // else
56   - // {
57   - // logger.Debug("3. havePassword= " + Convert.ToBoolean(userInfo["havePassword"]));
58   -
59   - // isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"]));
60   - // }
61   - // logger.Debug("isMailSent= " + isMailSent);
62   - // if (isMailSent)
63   - // return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userDetails) };
64   - // else
65   - // return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.MAIL_NOT_SENT)};
66   - // }
67   - // else
68   - // {
69   - // logger.Debug("inside else in ForgotUserController userData= " + userData);
70   - // return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userData)};
71   - // }
72   - //}
73   -
  31 +
74 32 public HttpResponseMessage Post([FromBody]JObject userInfo)
75 33 {
76 34 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
... ... @@ -78,32 +36,33 @@ namespace AIAHTML5.API.Controllers
78 36 try
79 37 {
80 38 dynamic userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo);
81   - if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(userData) != AIAConstants.EXCEPTION_IN_AIAHTML5)
  39 +
  40 + if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND)
82 41 {
83 42 //logger.Debug("inside if in ForgotUserController userData.loginId= " + userData.LoginId);
84 43 bool isMailSent = false;
85 44  
86 45 logger.Debug("1. inside if in ForgotUserController userDetails= " + userData.ToString());
87 46  
88   - if (Convert.ToBoolean(userInfo["havePassword"]))
  47 + if (Convert.ToBoolean(userInfo["isMailForForgotPassword"]))
89 48 {
90 49 if (Convert.ToBoolean(userInfo["unblockUser"]))
91 50 {
92 51 logger.Debug("2. unblockUser= " + Convert.ToBoolean(userInfo["unblockUser"]));
93   - isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"]), Convert.ToBoolean(userInfo["unblockUser"]));
  52 + isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["isMailForForgotPassword"]), Convert.ToBoolean(userInfo["unblockUser"]));
94 53 }
95 54 else
96 55 {
97   - logger.Debug("2. havePassword= " + Convert.ToBoolean(userInfo["havePassword"]));
98   - isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"]));
  56 + logger.Debug("2. isMailForForgotPassword= " + Convert.ToBoolean(userInfo["isMailForForgotPassword"]));
  57 + isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["isMailForForgotPassword"]));
99 58 }
100 59  
101 60 }
102 61 else
103 62 {
104   - logger.Debug("3. havePassword= " + Convert.ToBoolean(userInfo["havePassword"]));
  63 + logger.Debug("3. isMailForForgotPassword= " + Convert.ToBoolean(userInfo["isMailForForgotPassword"]));
105 64  
106   - isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"]));
  65 + isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["isMailForForgotPassword"]));
107 66 }
108 67 logger.Debug("isMailSent= " + isMailSent);
109 68 if (isMailSent)
... ... @@ -117,9 +76,21 @@ namespace AIAHTML5.API.Controllers
117 76 return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userData.ToString()) };
118 77 }
119 78 }
  79 + catch (SqlException e)
  80 + {
  81 +
  82 + logger.Fatal("SqlException occured for emailId =" + userInfo["emailId"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
  83 +
  84 + ArrayList supportMailList = UserUtility.GetSupportMailList();
  85 + string mailSubject = AIAConstants.SQL_CONNECTION_ERROR;
  86 + string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
  87 + UserUtility.SendEmail(userInfo, supportMailList, "", mailSubject, mailBody);
  88 +
  89 + return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.SQL_CONNECTION_ERROR) };
  90 + }
120 91 catch (Exception e)
121 92 {
122   - logger.Fatal("Exception occured for loginId =" + userInfo["username"].ToString() + " and password= " + userInfo["password"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
  93 + logger.Fatal("Exception occured for emailId =" + userInfo["emailId"].ToString()+ "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
123 94  
124 95 ArrayList supportMailList = UserUtility.GetSupportMailList();
125 96 string mailSubject = AIAConstants.EXCEPTION_IN_AIAHTML5_MAIL_SUBJECT;
... ...
400-SOURCECODE/AIAHTML5.API/Controllers/ResetPasswordController.cs
... ... @@ -9,7 +9,8 @@ using log4net;
9 9 using Newtonsoft.Json;
10 10 using Newtonsoft.Json.Linq;
11 11 using AIAHTML5.API.Models;
12   -using AIAHTML5.API.Utility;
  12 +using AIAHTML5.API.Utility;
  13 +using System.Collections;
13 14  
14 15 namespace AIAHTML5.API.Controllers
15 16 {
... ... @@ -34,24 +35,39 @@ namespace AIAHTML5.API.Controllers
34 35 public HttpResponseMessage Post([FromBody]JObject userInfo)
35 36 {
36 37 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
37   - logger.Debug("inside POST");
38   - dynamic userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo);
39   - HttpResponseMessage response = null;
40   - if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(userData) != AIAConstants.SQL_CONNECTION_ERROR)
41   - {
42   - int result = 0;
43   - if (!String.IsNullOrEmpty(userInfo["newPassword"].ToString()))
44   - {
45   - result = AIAHTML5.API.Models.Users.UpdatePassword(userInfo, userData.LoginId, userData.EmailId);
46   - if (result > 0)
47   - response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.PASSWORD_UPDATE_SUCCESS) };
48   - else
49   - response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.PASSWORD_UPDATE_FAILED) };
50   - }
51   - }
52   - else
53   - {
54   - response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userData.ToString()) };
  38 + logger.Debug("inside POST");
  39 + HttpResponseMessage response = null;
  40 + try
  41 + {
  42 + dynamic userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo);
  43 +
  44 + if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(userData) != AIAConstants.EXCEPTION_IN_AIAHTML5)
  45 + {
  46 + int result = 0;
  47 + if (!String.IsNullOrEmpty(userInfo["newPassword"].ToString()))
  48 + {
  49 + result = AIAHTML5.API.Models.Users.UpdatePassword(userInfo, userData.LoginId, userData.EmailId);
  50 + if (result > 0)
  51 + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.PASSWORD_UPDATE_SUCCESS) };
  52 + else
  53 + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.PASSWORD_UPDATE_FAILED) };
  54 + }
  55 + }
  56 + else
  57 + {
  58 + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userData.ToString()) };
  59 + }
  60 + }
  61 + catch (Exception e)
  62 + {
  63 + logger.Fatal("Exception occured for loginId =" + userInfo["username"].ToString() + " and password= " + userInfo["password"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
  64 +
  65 + ArrayList supportMailList = UserUtility.GetSupportMailList();
  66 + string mailSubject = AIAConstants.EXCEPTION_IN_AIAHTML5_MAIL_SUBJECT;
  67 + string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
  68 + UserUtility.SendEmail(userInfo, supportMailList, "", mailSubject, mailBody);
  69 + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.EXCEPTION_IN_AIAHTML5) };
  70 +
55 71 }
56 72  
57 73 return response;
... ...
400-SOURCECODE/AIAHTML5.API/Models/Users.cs
... ... @@ -50,7 +50,7 @@ namespace AIAHTML5.API.Models
50 50  
51 51 //dynamic userDetails;
52 52  
53   - if (objUser.Id > 0)
  53 + if (objUser!= null)
54 54 {
55 55 logger.Debug("userDetails.loginId= " + objUser.LoginId);
56 56 //return userDetails = JsonConvert.SerializeObject(objUser);
... ...