diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
index bece065..fee558e 100644
--- a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
@@ -33,31 +33,35 @@ namespace AIAHTML5.API.Controllers
ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
logger.Debug("inside POST");
- dynamic authenticationRepsonse;
+ dynamic authenticationRepsonse;
- try
- {
+ try
+ {
- //01.get the user detail for autheticate user
+ //01.get the user detail to autheticate user
User userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
- if (userInfo.Id > 0)
- {
- // Check user is authenticated or not by login credential macth
- bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials, userInfo);
+ if (userInfo!= null)
+ {
+ // Check user is authenticated or not by login credential math
+ bool isUserAuthenticated = AIAHTML5.API.Models.Users.checkUserAuthenticity(credentials, userInfo);
+
+ DateTime blockTime;
+ bool isUserBlocked;
- // check if user is blocked
- DateTime blockTime;
- bool isUserBlocked = AIAHTML5.API.Models.Users.isUserBlocked(userInfo.Id, out blockTime);
+ if (isUserAuthenticated)
+ {
- if (isUserAuthenticated && !isUserBlocked)
- {
- //01. Get User details
- //userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
+ //01. assigning isCorrectPassword to true 'required for internal processing'
+ userInfo.IsCorrectPassword = true;
- //02. assigning isCorrectPassword to true 'required for internal processing'
- userInfo.IsCorrectPassword = true;
+ //02. check if user is blocked
+
+ isUserBlocked = AIAHTML5.API.Models.Users.checkUserBlockStatus(userInfo.Id, out blockTime);
+
+ if(!isUserBlocked)
+ {
//04.delete past wrong login attempts of user
int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
if (wrongAttemptDeteledCount < 0)
@@ -145,6 +149,7 @@ namespace AIAHTML5.API.Controllers
authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
}
+ }
else
{
//compare block time of user with current time if user is blocked
diff --git a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
index 94c7570..b3e38d0 100644
--- a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
@@ -118,8 +118,8 @@ namespace AIAHTML5.API.Models
DataTable dt = new DataTable();
da.Fill(dt);
-
- if (dt.Rows.Count > 0)
+
+ if (dt!= null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
@@ -145,10 +145,7 @@ namespace AIAHTML5.API.Models
objUser.IsActive = Convert.ToBoolean(dr["IsActive"]);
}
}
- else
- {
- objUser = new User();
- }
+
}
catch (SqlException ex)
{
@@ -850,10 +847,10 @@ namespace AIAHTML5.API.Models
return result;
}
- internal BlockedUser GetBlockedUserByUserId(int userId)
+ internal BlockedUser GetUserBlockedStatusByUserId(int userId)
{
- ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
- logger.Debug(" inside GetBlockedUserByUserId for UserId= " + userId);
+ ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
+ logger.Debug(" inside GetUserBlockedStatusByUserId for UserId= " + userId);
BlockedUser blockedUser = new BlockedUser();
DataTable dt = null;
@@ -868,9 +865,9 @@ namespace AIAHTML5.API.Models
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
dt = new DataTable();
- da.Fill(dt);
-
- if (dt.Rows.Count > 0)
+ da.Fill(dt);
+
+ if (dt!= null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
@@ -884,10 +881,7 @@ namespace AIAHTML5.API.Models
blockedUser.LoginTime = Convert.ToDateTime(dr["LoginTime"]);
}
}
- else
- {
- blockedUser = new BlockedUser ();
- }
+
}
catch (SqlException ex)
{
diff --git a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs
index 338d625..b044fcf 100644
--- a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs
@@ -196,7 +196,7 @@ namespace AIAHTML5.API.Models
return result;
}
- internal static bool IsUserAuthenticated(Newtonsoft.Json.Linq.JObject credentials, User user)
+ internal static bool checkUserAuthenticity(Newtonsoft.Json.Linq.JObject credentials, User user)
{
bool isAuthenticatedUser = DBModel.ValidateUserAuthenticity(credentials["username"].ToString(), credentials["password"].ToString(), user);
@@ -549,27 +549,26 @@ namespace AIAHTML5.API.Models
return modulesList;
}
- internal static bool isUserBlocked(int userId, out DateTime blockTime)
+ internal static bool checkUserBlockStatus(int userId, out DateTime blockTime)
{
ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
logger.Debug("inside isUserBlocked for UserId =" + userId);
- bool result = false;
+ bool isUserBlocked = false;
blockTime = new DateTime();
try
{
-
-
+
DBModel objModel = new DBModel();
- BlockedUser blockedUser = objModel.GetBlockedUserByUserId(userId);
+ BlockedUser blockedUser = objModel.GetUserBlockedStatusByUserId(userId);
- if (blockedUser.Id> 0)
+ if (blockedUser!= null)
{
blockTime = blockedUser.LoginTime;
- result = true;
+ isUserBlocked = true;
}
else
- result = false;
+ isUserBlocked = false;
}
catch (Exception e)
@@ -578,7 +577,7 @@ namespace AIAHTML5.API.Models
throw;
}
- return result;
+ return isUserBlocked;
}
}
}
\ No newline at end of file