Example #1
0
        public AllAppsAccessHistory SaveUserLog(UserTokenDeviceDetails data)
        {
            _db.UserTokenDeviceDetails.Add(data);
            _db.SaveChanges();

            return(new AllAppsAccessHistory());
        }
Example #2
0
        public ActionResult ValidateToken([FromBody] UserDetails data)
        {
            try
            {
                using (var db = new ApplicationDbContext())
                {
                    if (data == null)
                    {
                        return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status400BadRequest));
                    }
                    else
                    {
                        AppHistoryService history = new AppHistoryService(_db);
                        var tokenInfo             = history.MatchedById(data.TokenId, data.AppName);
                        var isValid = history.ValidateUser(data);

                        if (isValid != null)
                        {
                            var userTokenDeviceDetails = new UserTokenDeviceDetails
                            {
                                UserTokenDetailsId = tokenInfo.Id,
                                DeviceId           = data.DeviceId,
                            };

                            var validUser = history.SaveUserLog(userTokenDeviceDetails);
                        }
                        else
                        {
                            TokenValidationStatus failureStatus = new TokenValidationStatus();
                            failureStatus.success = false;
                            failureStatus.message = "No such token found";
                            return(Ok(failureStatus));
                        }
                        TokenValidationStatus successStatus = new TokenValidationStatus();
                        successStatus.success = true;
                        successStatus.message = "Token validated successfully";
                        return(Ok(successStatus));
                    }
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status204NoContent));
            }
        }