Commit c9934c73 authored by David Venhoek's avatar David Venhoek Committed by Sietse Ringers
Browse files

Added activity tracking.

parent dff7da6e
......@@ -26,6 +26,8 @@ type KeyshareDB interface {
// Reserve returns (allow, tries, wait, error)
ReservePincheck(user KeyshareUser) (bool, int, int64, error)
ClearPincheck(user KeyshareUser) error
SetSeen(user KeyshareUser) error
}
type KeyshareUser interface {
......@@ -110,6 +112,10 @@ func (db *keyshareMemoryDB) ClearPincheck(user KeyshareUser) error {
return nil
}
func (db *keyshareMemoryDB) SetSeen(user KeyshareUser) error {
return nil
}
type keysharePostgresDatabase struct {
db *sql.DB
}
......@@ -270,3 +276,22 @@ func (db *keysharePostgresDatabase) ClearPincheck(user KeyshareUser) error {
}
return nil
}
func (db *keysharePostgresDatabase) SetSeen(user KeyshareUser) error {
userdata, ok := user.(*keysharePostgresUser)
if !ok {
return ErrInvalidData
}
res, err := db.db.Exec("UPDATE irma.users SET lastSeen = $1 WHERE id = $2", time.Now().Unix(), userdata.id)
if err != nil {
return err
}
c, err := res.RowsAffected()
if err != nil {
return err
}
if c == 0 {
return ErrUserNotFound
}
return nil
}
......@@ -3,8 +3,9 @@ CREATE TABLE IF NOT EXISTS irma.users
id serial PRIMARY KEY,
username varchar(128),
coredata bytea,
lastSeen bigint,
pinCounter int,
pinBlockDate bigint
);
CREATE UNIQUE INDEX username_index ON irma.users (username);
GRANT ALL PRIVILEGES ON TABLE irma.users TO irma;
\ No newline at end of file
GRANT ALL PRIVILEGES ON TABLE irma.users TO irma;
......@@ -204,6 +204,13 @@ func (s *Server) handleResponse(w http.ResponseWriter, r *http.Request) {
return
}
// Indicate activity on user account
err = s.db.SetSeen(user)
if err != nil {
s.conf.Logger.WithField("error", err).Error("Could not mark user as seen recently")
// Do not send to user
}
// Get data from session
s.sessionLock.Lock()
sessionData, ok := s.sessions[username]
......@@ -297,6 +304,14 @@ func (s *Server) handleVerifyPin(w http.ResponseWriter, r *http.Request) {
s.conf.Logger.WithField("error", err).Error("Could not reset users pin check logic")
// Do not send to user
}
// Indicate activity on user account
err = s.db.SetSeen(user)
if err != nil {
s.conf.Logger.WithField("error", err).Error("Could not indicate user activity")
// Do not send to user
}
server.WriteJson(w, keysharePinStatus{Status: "success", Message: jwtt})
}
}
......
Supports Markdown
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