Commit 38c7edb9074f79aa1f20f2c314935a9fb0ae662c

Authored by Nikita Kulshreshtha
1 parent aa922a08

updated code. removed comments and added logs and null check in backend code

400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj
@@ -155,7 +155,7 @@ @@ -155,7 +155,7 @@
155 <AutoAssignPort>True</AutoAssignPort> 155 <AutoAssignPort>True</AutoAssignPort>
156 <DevelopmentServerPort>63874</DevelopmentServerPort> 156 <DevelopmentServerPort>63874</DevelopmentServerPort>
157 <DevelopmentServerVPath>/</DevelopmentServerVPath> 157 <DevelopmentServerVPath>/</DevelopmentServerVPath>
158 - <IISUrl>http://localhost:95/AIA/API</IISUrl> 158 + <IISUrl>http://localhost:85/AIA/API</IISUrl>
159 <NTLMAuthentication>False</NTLMAuthentication> 159 <NTLMAuthentication>False</NTLMAuthentication>
160 <UseCustomServer>False</UseCustomServer> 160 <UseCustomServer>False</UseCustomServer>
161 <CustomServerUrl>http://182.19.10.91/AIAHTML5</CustomServerUrl> 161 <CustomServerUrl>http://182.19.10.91/AIAHTML5</CustomServerUrl>
400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
@@ -28,19 +28,11 @@ namespace AIAHTML5.API.Controllers @@ -28,19 +28,11 @@ namespace AIAHTML5.API.Controllers
28 public HttpResponseMessage Post([FromBody]JObject credentials) 28 public HttpResponseMessage Post([FromBody]JObject credentials)
29 29
30 { 30 {
31 - // log4net.Config.XmlConfigurator.Configure();  
32 -  
33 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); 31 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
34 logger.Debug("inside POST"); 32 logger.Debug("inside POST");
  33 +
35 dynamic userDetails = AIAHTML5.API.Models.Users.AuthenticateUser(credentials); 34 dynamic userDetails = AIAHTML5.API.Models.Users.AuthenticateUser(credentials);
36 -  
37 -  
38 - //JsonSerializerSettings settings = new JsonSerializerSettings()  
39 - //{  
40 - // ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,  
41 - // DateFormatHandling = DateFormatHandling.IsoDateFormat,  
42 - //};  
43 - 35 +
44 return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(userDetails)) }; 36 return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(userDetails)) };
45 37
46 } 38 }
400-SOURCECODE/AIAHTML5.API/Models/Users.cs
@@ -25,34 +25,29 @@ namespace AIAHTML5.API.Models @@ -25,34 +25,29 @@ namespace AIAHTML5.API.Models
25 25
26 var collection = db.GetCollection<dynamic>("Users"); 26 var collection = db.GetCollection<dynamic>("Users");
27 27
28 - // var builder = Builders<BsonDocument>.Filter;  
29 - BsonDocument filter = new BsonDocument();  
30 - filter.Add("loginId", credentials["username"].ToString());  
31 - filter.Add("password", credentials["password"].ToString());  
32 -  
33 -  
34 FilterDefinition<dynamic>[] filterCondition = { Builders<dynamic>.Filter.Eq("loginId", credentials["username"].ToString()), 28 FilterDefinition<dynamic>[] filterCondition = { Builders<dynamic>.Filter.Eq("loginId", credentials["username"].ToString()),
35 Builders<dynamic>.Filter.Eq("password", credentials["password"].ToString())}; 29 Builders<dynamic>.Filter.Eq("password", credentials["password"].ToString())};
36 30
37 dynamic userDetails = collection.Find(Builders<dynamic>.Filter.And(filterCondition)).SingleOrDefault(); 31 dynamic userDetails = collection.Find(Builders<dynamic>.Filter.And(filterCondition)).SingleOrDefault();
38 32
39 - //logger.Debug("userDetails= " + userDetails.ElementCount);  
40 - //if (userDetails.ElementCount > 0)  
41 - //{ 33 +
  34 + if (userDetails!= null)
  35 + {
  36 + logger.Debug("userDetails.loginId= " + userDetails.loginId);
42 return userDetails; 37 return userDetails;
43 - //}  
44 - //else  
45 - //{  
46 - // return AIAConstants.USER_NOT_FOUND;  
47 - //} 38 + }
  39 + else
  40 + {
  41 + return AIAConstants.USER_NOT_FOUND;
  42 + }
48 } 43 }
49 catch(Exception e) 44 catch(Exception e)
50 { 45 {
51 - //NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); 46 +
52 logger.Fatal("Exception in AuthenticateUser for loginId =" + credentials["username"].ToString() + " and password= " + credentials["password"].ToString() + "Exception= " + e.Message); 47 logger.Fatal("Exception in AuthenticateUser for loginId =" + credentials["username"].ToString() + " and password= " + credentials["password"].ToString() + "Exception= " + e.Message);
53 48
54 - string error = AIAConstants.ERROR_IN_FECTHING_DETAILS;  
55 - return error; 49 + string errorMessage = AIAConstants.ERROR_IN_FECTHING_DETAILS;
  50 + return errorMessage;
56 } 51 }
57 52
58 } 53 }