moloch-- / RootTheBox

A Game of Hackers (CTF Scoreboard & Game Manager)
http://root-the-box.com/
Apache License 2.0
908 stars 292 forks source link

Need help to fetch list of last login users. #600

Closed PunitTailor55 closed 9 months ago

PunitTailor55 commented 9 months ago

I am trying to develop total login users using the last login date. In database, last_login column has datetime function used. So, I have converted date using datetime function date = now.strftime('%Y/%m/%d') but it still return 0. I am trying to fetch current date login users. I have successfully created verified users and registered users.

PunitTailor55 commented 9 months ago

Fetch the last 48 hours login user details add following code.

add function in User.py

```
    def all_login_user(cls):
    now = datetime.now()
    print(now)
    date = datetime.utcnow() - timedelta(hours=48)
    #date = now - timedelta(days=3)
    userlogin = dbsession.query(cls).filter(User.last_login >=date).all()
    return [user for user in userlogin if user.is_admin() is False] ```

Add following code in UserHandlers.py class HomeHandler(BaseHandler) function where render the admin/home.html file.

userlogin = len(User.all_login_user()),

Rander in admin/index.html

<div style="margin-bottom: 5px;"><i class="fa fa-fw fa-user"></i>{{ _("Total Login Users") }}: {{userlogin}}