Forráskód Böngészése

Add token expiration date autoupdate

- Add autoupdate of authentication token expiration date
- Add few more information to README
Alexey Edelev 4 éve
szülő
commit
d2cdd27e77
2 módosított fájl, 28 hozzáadás és 1 törlés
  1. 13 0
      README.md
  2. 15 1
      auth/authenticator.go

+ 13 - 0
README.md

@@ -11,6 +11,19 @@ Supported features:
 - ~IMAP interface~
 - SASL authentication
 
+# Prerequesties
+
+gostfix only works on Linux-like operating systems
+
+- go 1.13 or higher
+- mongo 3.6 or higher
+- protobuf 3.6.1 or higher
+- nginx 1.18.0 or higher with websockets support
+
+# Installation and setup
+
+> TODO: Will be described later
+
 # Nginx
 
 ```

+ 15 - 1
auth/authenticator.go

@@ -217,7 +217,21 @@ func (a *Authenticator) checkToken(user, token string) error {
 	}
 
 	if ok {
-		//TODO: Renew token
+		opts := options.Update().SetArrayFilters(options.ArrayFilters{
+			Registry: bson.DefaultRegistry,
+			Filters: bson.A{
+				bson.M{"element.token": "b3a612c1-a56c-4465-8071-4250ec5de79d"},
+			}})
+		a.tokensCollection.UpdateOne(context.Background(),
+			bson.M{
+				"user": user,
+			},
+			bson.M{
+				"$set": bson.M{
+					"token.$[element].expire": time.Now().Add(time.Hour * 24).Unix(),
+				},
+			},
+			opts)
 		return nil
 	}