mirror of https://github.com/gophish/gophish
Added functionality to display last user login (#1967)
Added functionality to display last login time for each user in the User Management page.pull/2060/head
parent
c1d3c7cd75
commit
b53cff0c98
|
@ -382,6 +382,11 @@ func (as *AdminServer) Login(w http.ResponseWriter, r *http.Request) {
|
||||||
as.handleInvalidLogin(w, r)
|
as.handleInvalidLogin(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
u.LastLogin = time.Now().UTC()
|
||||||
|
err = models.PutUser(&u)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
// If we've logged in, save the session and redirect to the dashboard
|
// If we've logged in, save the session and redirect to the dashboard
|
||||||
session.Values["id"] = u.Id
|
session.Values["id"] = u.Id
|
||||||
session.Save(r, w)
|
session.Save(r, w)
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
-- +goose Up
|
||||||
|
-- SQL in section 'Up' is executed when this migration is applied
|
||||||
|
ALTER TABLE `users` ADD COLUMN last_login datetime;
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
-- SQL section 'Down' is executed when this migration is rolled back
|
|
@ -0,0 +1,6 @@
|
||||||
|
-- +goose Up
|
||||||
|
-- SQL in section 'Up' is executed when this migration is applied
|
||||||
|
ALTER TABLE users ADD COLUMN last_login datetime;
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
-- SQL section 'Down' is executed when this migration is rolled back
|
|
@ -2,6 +2,7 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/gophish/gophish/logger"
|
log "github.com/gophish/gophish/logger"
|
||||||
)
|
)
|
||||||
|
@ -13,13 +14,14 @@ var ErrModifyingOnlyAdmin = errors.New("Cannot remove the only administrator")
|
||||||
|
|
||||||
// User represents the user model for gophish.
|
// User represents the user model for gophish.
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Username string `json:"username" sql:"not null;unique"`
|
Username string `json:"username" sql:"not null;unique"`
|
||||||
Hash string `json:"-"`
|
Hash string `json:"-"`
|
||||||
ApiKey string `json:"api_key" sql:"not null;unique"`
|
ApiKey string `json:"api_key" sql:"not null;unique"`
|
||||||
Role Role `json:"role" gorm:"association_autoupdate:false;association_autocreate:false"`
|
Role Role `json:"role" gorm:"association_autoupdate:false;association_autocreate:false"`
|
||||||
RoleID int64 `json:"-"`
|
RoleID int64 `json:"-"`
|
||||||
PasswordChangeRequired bool `json:"password_change_required"`
|
PasswordChangeRequired bool `json:"password_change_required"`
|
||||||
|
LastLogin time.Time `json:"last_login"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUser returns the user that the given id corresponds to. If no user is found, an
|
// GetUser returns the user that the given id corresponds to. If no user is found, an
|
||||||
|
|
|
@ -185,9 +185,14 @@ const load = () => {
|
||||||
userTable.clear();
|
userTable.clear();
|
||||||
userRows = []
|
userRows = []
|
||||||
$.each(users, (i, user) => {
|
$.each(users, (i, user) => {
|
||||||
|
lastlogin = "Never"
|
||||||
|
if (user.last_login != "0001-01-01T00:00:00Z") {
|
||||||
|
lastlogin = moment(user.last_login).format('MMMM Do YYYY, h:mm:ss a')
|
||||||
|
}
|
||||||
userRows.push([
|
userRows.push([
|
||||||
escapeHtml(user.username),
|
escapeHtml(user.username),
|
||||||
escapeHtml(user.role.name),
|
escapeHtml(user.role.name),
|
||||||
|
lastlogin,
|
||||||
"<div class='pull-right'>\
|
"<div class='pull-right'>\
|
||||||
<button class='btn btn-warning impersonate_button' data-user-id='" + user.id + "'>\
|
<button class='btn btn-warning impersonate_button' data-user-id='" + user.id + "'>\
|
||||||
<i class='fa fa-retweet'></i>\
|
<i class='fa fa-retweet'></i>\
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>Username</th>
|
<th>Username</th>
|
||||||
<th>Role</th>
|
<th>Role</th>
|
||||||
|
<th>Last Login</th>
|
||||||
<th class="col-md-2 no-sort"></th>
|
<th class="col-md-2 no-sort"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
Loading…
Reference in New Issue