From 2808e788ecb4a3b9d2830dea3ed7d56d3bd18e58 Mon Sep 17 00:00:00 2001 From: nikita Date: Wed, 27 Sep 2017 18:33:01 +0530 Subject: [PATCH] made some changes in forgotPassword --- 400-SOURCECODE/AIAHTML5.API/Controllers/ForgotUserController.cs | 75 +++++++++++++++++++++++---------------------------------------------------- 400-SOURCECODE/AIAHTML5.API/Controllers/ResetPasswordController.cs | 54 +++++++++++++++++++++++++++++++++++------------------- 400-SOURCECODE/AIAHTML5.API/Models/Users.cs | 2 +- 3 files changed, 59 insertions(+), 72 deletions(-) diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/ForgotUserController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/ForgotUserController.cs index fc08e54..aa8037e 100644 --- a/400-SOURCECODE/AIAHTML5.API/Controllers/ForgotUserController.cs +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/ForgotUserController.cs @@ -11,6 +11,7 @@ using Newtonsoft.Json.Linq; using AIAHTML5.API.Models; using AIAHTML5.API.Utility; using System.Collections; +using System.Data.SqlClient; namespace AIAHTML5.API.Controllers { @@ -27,50 +28,7 @@ namespace AIAHTML5.API.Controllers { return "value"; } - - // POST api/ - //public void Post([FromBody]string value) - //{ - //} - //public HttpResponseMessage Post([FromBody]JObject userInfo) - //{ - // ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); - // logger.Debug("inside POST in ForgotUserController for emailId = " + userInfo["emailId"]); - - // dynamic userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo); - // if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS) - // { - // //logger.Debug("inside if in ForgotUserController userData.loginId= " + userData.LoginId); - // bool isMailSent = false; - // string userDetails = Newtonsoft.Json.JsonConvert.SerializeObject(userData); - - // logger.Debug("1. inside if in ForgotUserController userDetails= " + userDetails); - - // if (Convert.ToBoolean(userInfo["havePassword"])) - // { - // logger.Debug("2. havePassword= " + Convert.ToBoolean(userInfo["havePassword"])); - - // isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"])); - // } - // else - // { - // logger.Debug("3. havePassword= " + Convert.ToBoolean(userInfo["havePassword"])); - - // isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"])); - // } - // logger.Debug("isMailSent= " + isMailSent); - // if (isMailSent) - // return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userDetails) }; - // else - // return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.MAIL_NOT_SENT)}; - // } - // else - // { - // logger.Debug("inside else in ForgotUserController userData= " + userData); - // return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userData)}; - // } - //} - + public HttpResponseMessage Post([FromBody]JObject userInfo) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); @@ -78,32 +36,33 @@ namespace AIAHTML5.API.Controllers try { dynamic userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo); - if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(userData) != AIAConstants.EXCEPTION_IN_AIAHTML5) + + if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND) { //logger.Debug("inside if in ForgotUserController userData.loginId= " + userData.LoginId); bool isMailSent = false; logger.Debug("1. inside if in ForgotUserController userDetails= " + userData.ToString()); - if (Convert.ToBoolean(userInfo["havePassword"])) + if (Convert.ToBoolean(userInfo["isMailForForgotPassword"])) { if (Convert.ToBoolean(userInfo["unblockUser"])) { logger.Debug("2. unblockUser= " + Convert.ToBoolean(userInfo["unblockUser"])); - isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"]), Convert.ToBoolean(userInfo["unblockUser"])); + isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["isMailForForgotPassword"]), Convert.ToBoolean(userInfo["unblockUser"])); } else { - logger.Debug("2. havePassword= " + Convert.ToBoolean(userInfo["havePassword"])); - isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"])); + logger.Debug("2. isMailForForgotPassword= " + Convert.ToBoolean(userInfo["isMailForForgotPassword"])); + isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["isMailForForgotPassword"])); } } else { - logger.Debug("3. havePassword= " + Convert.ToBoolean(userInfo["havePassword"])); + logger.Debug("3. isMailForForgotPassword= " + Convert.ToBoolean(userInfo["isMailForForgotPassword"])); - isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"])); + isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["isMailForForgotPassword"])); } logger.Debug("isMailSent= " + isMailSent); if (isMailSent) @@ -117,9 +76,21 @@ namespace AIAHTML5.API.Controllers return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userData.ToString()) }; } } + catch (SqlException e) + { + + logger.Fatal("SqlException occured for emailId =" + userInfo["emailId"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + + ArrayList supportMailList = UserUtility.GetSupportMailList(); + string mailSubject = AIAConstants.SQL_CONNECTION_ERROR; + string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace; + UserUtility.SendEmail(userInfo, supportMailList, "", mailSubject, mailBody); + + return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.SQL_CONNECTION_ERROR) }; + } catch (Exception e) { - logger.Fatal("Exception occured for loginId =" + userInfo["username"].ToString() + " and password= " + userInfo["password"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + logger.Fatal("Exception occured for emailId =" + userInfo["emailId"].ToString()+ "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); ArrayList supportMailList = UserUtility.GetSupportMailList(); string mailSubject = AIAConstants.EXCEPTION_IN_AIAHTML5_MAIL_SUBJECT; diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/ResetPasswordController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/ResetPasswordController.cs index 4ad2e63..1c02145 100644 --- a/400-SOURCECODE/AIAHTML5.API/Controllers/ResetPasswordController.cs +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/ResetPasswordController.cs @@ -9,7 +9,8 @@ using log4net; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using AIAHTML5.API.Models; -using AIAHTML5.API.Utility; +using AIAHTML5.API.Utility; +using System.Collections; namespace AIAHTML5.API.Controllers { @@ -34,24 +35,39 @@ namespace AIAHTML5.API.Controllers public HttpResponseMessage Post([FromBody]JObject userInfo) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); - logger.Debug("inside POST"); - dynamic userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo); - HttpResponseMessage response = null; - if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(userData) != AIAConstants.SQL_CONNECTION_ERROR) - { - int result = 0; - if (!String.IsNullOrEmpty(userInfo["newPassword"].ToString())) - { - result = AIAHTML5.API.Models.Users.UpdatePassword(userInfo, userData.LoginId, userData.EmailId); - if (result > 0) - response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.PASSWORD_UPDATE_SUCCESS) }; - else - response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.PASSWORD_UPDATE_FAILED) }; - } - } - else - { - response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userData.ToString()) }; + logger.Debug("inside POST"); + HttpResponseMessage response = null; + try + { + dynamic userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo); + + if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(userData) != AIAConstants.EXCEPTION_IN_AIAHTML5) + { + int result = 0; + if (!String.IsNullOrEmpty(userInfo["newPassword"].ToString())) + { + result = AIAHTML5.API.Models.Users.UpdatePassword(userInfo, userData.LoginId, userData.EmailId); + if (result > 0) + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.PASSWORD_UPDATE_SUCCESS) }; + else + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.PASSWORD_UPDATE_FAILED) }; + } + } + else + { + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userData.ToString()) }; + } + } + catch (Exception e) + { + logger.Fatal("Exception occured for loginId =" + userInfo["username"].ToString() + " and password= " + userInfo["password"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + + ArrayList supportMailList = UserUtility.GetSupportMailList(); + string mailSubject = AIAConstants.EXCEPTION_IN_AIAHTML5_MAIL_SUBJECT; + string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace; + UserUtility.SendEmail(userInfo, supportMailList, "", mailSubject, mailBody); + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.EXCEPTION_IN_AIAHTML5) }; + } return response; diff --git a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs index 7dcefaa..f15da52 100644 --- a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs +++ b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs @@ -50,7 +50,7 @@ namespace AIAHTML5.API.Models //dynamic userDetails; - if (objUser.Id > 0) + if (objUser!= null) { logger.Debug("userDetails.loginId= " + objUser.LoginId); //return userDetails = JsonConvert.SerializeObject(objUser); -- libgit2 0.21.4