Commit 3ce62572 authored by ale's avatar ale
Browse files

Add a page showing recent user login records

parent bd22a157
{{define "title"}}Account Activity{{end}}
{{define "content"}}
<h1>Account activity</h1>
<p>
This is a log of the most recent accesses to this account:
</p>
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Device</th>
</tr>
</thead>
<tbody>
{{range $idx, $log := .Logs}}
<tr>
<td>{{$log.Timestamp}}</td>
<td>
{{if $log.DeviceInfo}}
{{$log.DeviceInfo.Browser}} ({{$log.DeviceInfo.OS}})
{{else}}
<i>Unknown</i>
{{end}}
</td>
</tr>
{{end}}
</tbody>
</table>
<p>
<button class="btn btn-default" href="/account/overview">
Back
</button>
</p>
{{end}}
......@@ -48,4 +48,11 @@
</button>
</a>
</p>
<p>
<a href="/account/activity" class="btn btn-default">
Account activity
</a>
</p>
{{end}}
......@@ -28,6 +28,7 @@ func NewService(base *web.Service, actionMgr *idp.ActionManager) *Service {
// Account management.
m.Handle("/account/overview", s.withUser(s.handleOverview))
m.Handle("/account/activity", s.withUser(s.handleActivity))
m.Handle("/account/password_change", s.withUser(s.handlePasswordChange))
m.Handle("/account/u2f", s.withUser(s.handleU2FManagement))
m.Handle("/account/u2f/register_request", s.withUser(s.handleU2FRegisterRequest))
......@@ -128,6 +129,18 @@ func (s *Service) handleOverview(w http.ResponseWriter, r *http.Request, _ idp.T
return nil
}
func (s *Service) handleActivity(w http.ResponseWriter, r *http.Request, txn idp.Txn, user *idp.User) error {
logs, err := txn.GetUserLogEntries(user.Name, idp.UserLogTypeLogin, 20)
if err != nil {
return err
}
s.RenderTemplate(w, r, "account_activity.html", map[string]interface{}{
"User": user,
"Logs": logs,
})
return nil
}
type passwordChangeForm struct {
CurPassword string `schema:"cur_password"`
Password string `schema:"password"`
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment