/// <summary> /// Method to validate token against expiry and existence in database. /// </summary> /// <param name="tokenId"></param> /// <returns></returns> public bool ValidateToken(string tokenId, string emailAddress, string userTpe) { QueryFilter filter = new QueryFilter(); filter.AddCondition("EmailAddress", QueryOperator.Equal, emailAddress); //company is a parameter filter.AddCondition("UserType", QueryOperator.Equal, userTpe); //company is a parameter QueryOperationConfig config = new QueryOperationConfig() { Filter = filter, Select = SelectValues.SpecificAttributes, AttributesToGet = new List <string> { "AuthData" }, ConsistentRead = true }; var userData = _dynamoDataService.QueryItem <CustomerAPI>(emailAddress, userTpe, config).FirstOrDefault(); // _dynamoDataService.GetItem<CustomerAPI>() // var token = userData.Get(t => t.AuthToken == tokenId && t.ExpiresOn > DateTime.Now); if (userData != null && userData.AuthData != null //&& string.IsNullOrEmpty(userData.AuthData.ExpiresOn) && userData.AuthData.AuthToken.Equals(tokenId) && Convert.ToDateTime(userData.AuthData.ExpiresOn) > DateTime.Now) { if (!(DateTime.Now > Convert.ToDateTime(userData.AuthData.ExpiresOn))) { //if (token != null && !(DateTime.Now > token.ExpiresOn)) //{ // token.ExpiresOn = token.ExpiresOn.AddSeconds( // Convert.ToDouble(ConfigurationManager.AppSettings["AuthTokenExpiry"])); // _unitOfWork.TokenRepository.Update(token); // _unitOfWork.Save(); // return true; //} } return(true); } return(false); }
/// <summary> /// Public method to authenticate user by user name and password. /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <returns></returns> public CustomerAPI Authenticate(string userName, string password) { CustomerAPI obj = new CustomerAPI(); obj.EmailAddress = userName; obj.Password = password; #region Trial Blocked Code //var user = _unitOfWork.UserRepository.Get(u => u.user_name == userName && u.password == EncryptText("wgt_hmis", password)); //var request = new QueryRequest //{ // TableName = "Reply", // KeyConditionExpression = "userName = :v_userName and emailAddress > :v_emailAddress", // ExpressionAttributeValues = new Dictionary<string, AttributeValue> { // {":v_userName", new AttributeValue { S = "surhere" }}, // {":v_emailAddress", new AttributeValue { S = "*****@*****.**" }} // }, // ProjectionExpression = "Subject, ReplyDateTime, PostedBy", // ConsistentRead = true //}; //IDictionary<string, DynamoDBEntry> keys = new Dictionary<string, DynamoDBEntry>(); //keys["EmailAddress"] = "*****@*****.**"; //keys["UserType"] = "Customer"; //var userData = _dynamoDataService.GetItem<CustomerAPI>(keys); //var user = _dynamoDataService.GetItem<DVD>("The Godfather"); #endregion QueryFilter filter = new QueryFilter(); filter.AddCondition("EmailAddress", QueryOperator.Equal, userName); //company is a parameter filter.AddCondition("UserType", QueryOperator.Equal, "Customer"); //company is a parameter QueryOperationConfig config = new QueryOperationConfig() { Filter = filter, Select = SelectValues.SpecificAttributes, AttributesToGet = new List<string> { "AuthData", "Password", "FirstName", "LastName", "EmailAddress" }, ConsistentRead = true }; var userData = _dynamoDataService.QueryItem<CustomerAPI>(userName, password, config).FirstOrDefault(); //var user = _dynamoDataService.GetEnumerable<CustomerAPI>(obj).FirstOrDefault(); if (userData != null && userData.AuthData != null) { // validate if password is matched if (userData.Password != null && !string.IsNullOrEmpty(userData.Password)) { //if(userData.AuthData.Password.Equals(password)) if (userData.Password.Equals(password)) { userData.UserName = userData.EmailAddress; userData.FirstName = userData.FirstName; return userData; } } return null; } return null; }