@@ -86,6 +86,7 @@ type UserService interface {
8686 GetRoleFiltersByUserRoleGroups (userRoleGroups []userBean.UserRoleGroup ) ([]userBean.RoleFilter , error )
8787 SaveLoginAudit (emailId , clientIp string , id int32 )
8888 CheckIfTokenIsValid (email string , version string ) error
89+ CheckUserStatusAndUpdateLoginAudit (token string ) (bool , int32 , string , error )
8990}
9091
9192type UserServiceImpl struct {
@@ -1826,3 +1827,34 @@ func (impl *UserServiceImpl) GetUserBasicDataByEmailId(emailId string) (*userBea
18261827 }
18271828 return response , nil
18281829}
1830+
1831+ func (impl * UserServiceImpl ) CheckUserStatusAndUpdateLoginAudit (token string ) (bool , int32 , string , error ) {
1832+ emailId , version , err := impl .GetEmailAndVersionFromToken (token )
1833+ if err != nil {
1834+ impl .logger .Error ("unable to fetch user by token" )
1835+ err = & util.ApiError {HttpStatusCode : 401 , UserMessage : "Invalid User" , InternalMessage : "unable to fetch user by token" }
1836+ return false , 0 , "" , err
1837+ }
1838+ userId , isInactive , err := impl .getUserWithTimeoutWindowConfiguration (emailId )
1839+ if err != nil {
1840+ err = & util.ApiError {HttpStatusCode : 401 , UserMessage : "Invalid User" , InternalMessage : err .Error ()}
1841+ impl .logger .Errorw ("unable to fetch user by email, %s" , token )
1842+ return isInactive , userId , "" , err
1843+ }
1844+ //if user is inactive, no need to store audit log
1845+ if ! isInactive {
1846+ impl .SaveLoginAudit (emailId , "localhost" , userId )
1847+ }
1848+ // checking length of version, to ensure backward compatibility as earlier we did not
1849+ // have version for api-tokens
1850+ // therefore, for tokens without version we will skip the below part
1851+ if strings .HasPrefix (emailId , userBean .API_TOKEN_USER_EMAIL_PREFIX ) && len (version ) > 0 {
1852+ err := impl .CheckIfTokenIsValid (emailId , version )
1853+ if err != nil {
1854+ impl .logger .Errorw ("token is not valid" , "error" , err , "token" , token )
1855+ return isInactive , userId , "" , err
1856+ }
1857+ }
1858+
1859+ return isInactive , userId , emailId , nil
1860+ }
0 commit comments