1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

chore: set samesite attributes and configurable max age for cookies (resolve #75)

fix: sort entities by total time descending (resolve #74)
This commit is contained in:
Ferdinand Mütsch 2020-11-21 22:30:56 +01:00
parent f4328c452f
commit 4a78f66778
12 changed files with 308 additions and 250 deletions

View File

@ -75,6 +75,7 @@ You can specify configuration options either via a config file (default: `config
| `server.base_path` | `WAKAPI_BASE_PATH` | `/` | Web base path (change when running behind a proxy under a sub-path) |
| `security.password_salt` | `WAKAPI_PASSWORD_SALT` | - | Pepper to use for password hashing |
| `security.insecure_cookies` | `WAKAPI_INSECURE_COOKIES` | `false` | Whether or not to allow cookies over HTTP |
| `security.cookie_max_age` | `WAKAPI_COOKIE_MAX_AGE ` | `172800` | Lifetime of authentication cookies in seconds or `0` to use [Session](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Define_the_lifetime_of_a_cookie) cookies |
| `db.host` | `WAKAPI_DB_HOST` | - | Database host |
| `db.port` | `WAKAPI_DB_PORT` | - | Database port |
| `db.user` | `WAKAPI_DB_USER` | - | Database user |

View File

@ -23,3 +23,4 @@ db:
security:
password_salt: # CHANGE !
insecure_cookies: false
cookie_max_age: 172800

View File

@ -14,6 +14,7 @@ import (
"gorm.io/gorm"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
)
@ -41,6 +42,7 @@ type securityConfig struct {
// this is actually a pepper (https://en.wikipedia.org/wiki/Pepper_(cryptography))
PasswordSalt string `yaml:"password_salt" default:"" env:"WAKAPI_PASSWORD_SALT"`
InsecureCookies bool `yaml:"insecure_cookies" default:"false" env:"WAKAPI_INSECURE_COOKIES"`
CookieMaxAgeSec int `yaml:"cookie_max_age" default:"172800" env:"WAKAPI_COOKIE_MAX_AGE"`
SecureCookie *securecookie.SecureCookie `yaml:"-"`
}
@ -69,6 +71,26 @@ type Config struct {
Server serverConfig
}
func (c *Config) CreateCookie(name, value, path string) *http.Cookie {
return c.createCookie(name, value, path, c.Security.CookieMaxAgeSec)
}
func (c *Config) GetClearCookie(name, path string) *http.Cookie {
return c.createCookie(name, "", path, -1)
}
func (c *Config) createCookie(name, value, path string, maxAge int) *http.Cookie {
return &http.Cookie{
Name: name,
Value: value,
Path: path,
MaxAge: maxAge,
Secure: !c.Security.InsecureCookies,
HttpOnly: true,
SameSite: http.SameSiteStrictMode,
}
}
func (c *Config) IsDev() bool {
return IsDev(c.Env)
}

View File

@ -45,6 +45,61 @@ github.com/muety/wakapi/models/heartbeat.go:51.23,52.19 1 1
github.com/muety/wakapi/models/heartbeat.go:53.17,54.26 1 1
github.com/muety/wakapi/models/heartbeat.go:55.22,56.18 1 1
github.com/muety/wakapi/models/heartbeat.go:59.15,61.3 1 1
github.com/muety/wakapi/models/models.go:3.14,5.2 0 1
github.com/muety/wakapi/models/summary.go:29.27,33.2 1 0
github.com/muety/wakapi/models/summary.go:83.29,85.2 1 1
github.com/muety/wakapi/models/summary.go:87.37,94.2 6 0
github.com/muety/wakapi/models/summary.go:96.35,98.2 1 1
github.com/muety/wakapi/models/summary.go:100.57,108.2 1 1
github.com/muety/wakapi/models/summary.go:121.33,126.26 4 1
github.com/muety/wakapi/models/summary.go:133.2,133.37 1 1
github.com/muety/wakapi/models/summary.go:137.2,140.33 2 1
github.com/muety/wakapi/models/summary.go:126.26,127.30 1 1
github.com/muety/wakapi/models/summary.go:127.30,129.4 1 1
github.com/muety/wakapi/models/summary.go:133.37,135.3 1 0
github.com/muety/wakapi/models/summary.go:140.33,146.3 1 1
github.com/muety/wakapi/models/summary.go:149.45,154.30 3 1
github.com/muety/wakapi/models/summary.go:163.2,163.30 1 1
github.com/muety/wakapi/models/summary.go:154.30,155.47 1 1
github.com/muety/wakapi/models/summary.go:155.47,156.32 1 1
github.com/muety/wakapi/models/summary.go:159.4,159.9 1 1
github.com/muety/wakapi/models/summary.go:156.32,158.5 1 1
github.com/muety/wakapi/models/summary.go:166.73,168.55 2 1
github.com/muety/wakapi/models/summary.go:173.2,173.16 1 1
github.com/muety/wakapi/models/summary.go:168.55,169.31 1 1
github.com/muety/wakapi/models/summary.go:169.31,171.4 1 1
github.com/muety/wakapi/models/summary.go:176.88,178.55 2 1
github.com/muety/wakapi/models/summary.go:186.2,186.16 1 1
github.com/muety/wakapi/models/summary.go:178.55,179.31 1 1
github.com/muety/wakapi/models/summary.go:179.31,180.23 1 1
github.com/muety/wakapi/models/summary.go:183.4,183.46 1 1
github.com/muety/wakapi/models/summary.go:180.23,181.13 1 1
github.com/muety/wakapi/models/summary.go:189.79,190.33 1 1
github.com/muety/wakapi/models/summary.go:193.2,193.16 1 1
github.com/muety/wakapi/models/summary.go:190.33,192.3 1 1
github.com/muety/wakapi/models/summary.go:196.71,197.63 1 1
github.com/muety/wakapi/models/summary.go:237.2,243.10 6 1
github.com/muety/wakapi/models/summary.go:197.63,200.45 2 1
github.com/muety/wakapi/models/summary.go:209.3,209.31 1 1
github.com/muety/wakapi/models/summary.go:216.3,216.31 1 1
github.com/muety/wakapi/models/summary.go:233.3,233.16 1 1
github.com/muety/wakapi/models/summary.go:200.45,201.32 1 1
github.com/muety/wakapi/models/summary.go:206.4,206.14 1 1
github.com/muety/wakapi/models/summary.go:201.32,202.24 1 1
github.com/muety/wakapi/models/summary.go:202.24,204.6 1 1
github.com/muety/wakapi/models/summary.go:209.31,211.60 1 1
github.com/muety/wakapi/models/summary.go:211.60,213.5 1 1
github.com/muety/wakapi/models/summary.go:216.31,218.60 1 1
github.com/muety/wakapi/models/summary.go:218.60,219.55 1 1
github.com/muety/wakapi/models/summary.go:219.55,221.6 1 1
github.com/muety/wakapi/models/summary.go:221.11,229.6 1 1
github.com/muety/wakapi/models/summary.go:246.33,248.2 1 0
github.com/muety/wakapi/models/summary.go:250.43,252.2 1 0
github.com/muety/wakapi/models/summary.go:254.38,256.2 1 0
github.com/muety/wakapi/models/user.go:34.43,37.2 1 0
github.com/muety/wakapi/models/user.go:39.33,43.2 1 0
github.com/muety/wakapi/models/user.go:45.45,47.2 1 0
github.com/muety/wakapi/models/user.go:49.45,51.2 1 0
github.com/muety/wakapi/models/heartbeats.go:7.31,9.2 1 0
github.com/muety/wakapi/models/heartbeats.go:11.41,13.2 1 0
github.com/muety/wakapi/models/heartbeats.go:15.36,17.2 1 0
@ -72,57 +127,6 @@ github.com/muety/wakapi/models/shared.go:74.51,77.2 2 0
github.com/muety/wakapi/models/shared.go:79.37,82.2 2 0
github.com/muety/wakapi/models/shared.go:84.35,86.2 1 0
github.com/muety/wakapi/models/shared.go:88.34,90.2 1 0
github.com/muety/wakapi/models/user.go:34.43,37.2 1 0
github.com/muety/wakapi/models/user.go:39.33,43.2 1 0
github.com/muety/wakapi/models/user.go:45.45,47.2 1 0
github.com/muety/wakapi/models/user.go:49.45,51.2 1 0
github.com/muety/wakapi/models/models.go:3.14,5.2 0 1
github.com/muety/wakapi/models/summary.go:28.27,32.2 1 0
github.com/muety/wakapi/models/summary.go:80.29,82.2 1 1
github.com/muety/wakapi/models/summary.go:84.35,86.2 1 1
github.com/muety/wakapi/models/summary.go:88.59,96.2 1 1
github.com/muety/wakapi/models/summary.go:109.33,114.26 4 1
github.com/muety/wakapi/models/summary.go:121.2,121.37 1 1
github.com/muety/wakapi/models/summary.go:125.2,128.33 2 1
github.com/muety/wakapi/models/summary.go:114.26,115.30 1 1
github.com/muety/wakapi/models/summary.go:115.30,117.4 1 1
github.com/muety/wakapi/models/summary.go:121.37,123.3 1 0
github.com/muety/wakapi/models/summary.go:128.33,134.3 1 1
github.com/muety/wakapi/models/summary.go:137.45,142.30 3 1
github.com/muety/wakapi/models/summary.go:151.2,151.30 1 1
github.com/muety/wakapi/models/summary.go:142.30,143.47 1 1
github.com/muety/wakapi/models/summary.go:143.47,144.32 1 1
github.com/muety/wakapi/models/summary.go:147.4,147.9 1 1
github.com/muety/wakapi/models/summary.go:144.32,146.5 1 1
github.com/muety/wakapi/models/summary.go:154.73,156.55 2 1
github.com/muety/wakapi/models/summary.go:161.2,161.16 1 1
github.com/muety/wakapi/models/summary.go:156.55,157.31 1 1
github.com/muety/wakapi/models/summary.go:157.31,159.4 1 1
github.com/muety/wakapi/models/summary.go:164.88,166.55 2 1
github.com/muety/wakapi/models/summary.go:174.2,174.16 1 1
github.com/muety/wakapi/models/summary.go:166.55,167.31 1 1
github.com/muety/wakapi/models/summary.go:167.31,168.23 1 1
github.com/muety/wakapi/models/summary.go:171.4,171.46 1 1
github.com/muety/wakapi/models/summary.go:168.23,169.13 1 1
github.com/muety/wakapi/models/summary.go:177.79,178.33 1 1
github.com/muety/wakapi/models/summary.go:181.2,181.16 1 1
github.com/muety/wakapi/models/summary.go:178.33,180.3 1 1
github.com/muety/wakapi/models/summary.go:184.71,185.63 1 1
github.com/muety/wakapi/models/summary.go:225.2,231.10 6 1
github.com/muety/wakapi/models/summary.go:185.63,188.45 2 1
github.com/muety/wakapi/models/summary.go:197.3,197.31 1 1
github.com/muety/wakapi/models/summary.go:204.3,204.31 1 1
github.com/muety/wakapi/models/summary.go:221.3,221.16 1 1
github.com/muety/wakapi/models/summary.go:188.45,189.32 1 1
github.com/muety/wakapi/models/summary.go:194.4,194.14 1 1
github.com/muety/wakapi/models/summary.go:189.32,190.24 1 1
github.com/muety/wakapi/models/summary.go:190.24,192.6 1 1
github.com/muety/wakapi/models/summary.go:197.31,199.60 1 1
github.com/muety/wakapi/models/summary.go:199.60,201.5 1 1
github.com/muety/wakapi/models/summary.go:204.31,206.60 1 1
github.com/muety/wakapi/models/summary.go:206.60,207.55 1 1
github.com/muety/wakapi/models/summary.go:207.55,209.6 1 1
github.com/muety/wakapi/models/summary.go:209.11,217.6 1 1
github.com/muety/wakapi/utils/common.go:9.48,11.2 1 0
github.com/muety/wakapi/utils/common.go:13.40,15.2 1 0
github.com/muety/wakapi/utils/common.go:17.45,19.2 1 0
@ -149,7 +153,6 @@ github.com/muety/wakapi/utils/date.go:63.21,66.3 2 0
github.com/muety/wakapi/utils/date.go:67.21,70.3 2 0
github.com/muety/wakapi/utils/http.go:9.73,12.58 3 0
github.com/muety/wakapi/utils/http.go:12.58,14.3 1 0
github.com/muety/wakapi/utils/http.go:17.67,25.2 1 0
github.com/muety/wakapi/utils/strings.go:8.34,10.2 1 0
github.com/muety/wakapi/utils/strings.go:12.77,13.29 1 0
github.com/muety/wakapi/utils/strings.go:18.2,18.19 1 0
@ -203,48 +206,51 @@ github.com/muety/wakapi/utils/color.go:8.93,10.41 2 0
github.com/muety/wakapi/utils/color.go:15.2,15.15 1 0
github.com/muety/wakapi/utils/color.go:10.41,11.50 1 0
github.com/muety/wakapi/utils/color.go:11.50,13.4 1 0
github.com/muety/wakapi/config/config.go:72.31,74.2 1 0
github.com/muety/wakapi/config/config.go:76.74,77.19 1 0
github.com/muety/wakapi/config/config.go:78.10,79.34 1 0
github.com/muety/wakapi/config/config.go:79.34,88.4 8 0
github.com/muety/wakapi/config/config.go:92.73,93.33 1 0
github.com/muety/wakapi/config/config.go:93.33,101.17 5 0
github.com/muety/wakapi/config/config.go:105.3,106.13 2 0
github.com/muety/wakapi/config/config.go:101.17,103.4 1 0
github.com/muety/wakapi/config/config.go:110.50,111.19 1 0
github.com/muety/wakapi/config/config.go:124.2,124.12 1 0
github.com/muety/wakapi/config/config.go:112.23,116.5 1 0
github.com/muety/wakapi/config/config.go:117.26,120.5 1 0
github.com/muety/wakapi/config/config.go:121.24,122.48 1 0
github.com/muety/wakapi/config/config.go:127.53,137.2 1 1
github.com/muety/wakapi/config/config.go:139.56,147.2 1 1
github.com/muety/wakapi/config/config.go:149.54,151.2 1 1
github.com/muety/wakapi/config/config.go:153.29,155.2 1 1
github.com/muety/wakapi/config/config.go:157.27,159.16 2 0
github.com/muety/wakapi/config/config.go:162.2,165.16 3 0
github.com/muety/wakapi/config/config.go:169.2,169.22 1 0
github.com/muety/wakapi/config/config.go:159.16,161.3 1 0
github.com/muety/wakapi/config/config.go:165.16,167.3 1 0
github.com/muety/wakapi/config/config.go:172.45,182.16 4 0
github.com/muety/wakapi/config/config.go:186.2,186.57 1 0
github.com/muety/wakapi/config/config.go:190.2,190.30 1 0
github.com/muety/wakapi/config/config.go:194.2,194.15 1 0
github.com/muety/wakapi/config/config.go:182.16,184.3 1 0
github.com/muety/wakapi/config/config.go:186.57,188.3 1 0
github.com/muety/wakapi/config/config.go:190.30,192.3 1 0
github.com/muety/wakapi/config/config.go:197.38,198.43 1 0
github.com/muety/wakapi/config/config.go:202.2,202.15 1 0
github.com/muety/wakapi/config/config.go:198.43,200.3 1 0
github.com/muety/wakapi/config/config.go:205.26,207.2 1 0
github.com/muety/wakapi/config/config.go:209.20,211.2 1 0
github.com/muety/wakapi/config/config.go:213.21,220.96 4 0
github.com/muety/wakapi/config/config.go:224.2,231.52 4 0
github.com/muety/wakapi/config/config.go:235.2,235.47 1 0
github.com/muety/wakapi/config/config.go:241.2,242.14 2 0
github.com/muety/wakapi/config/config.go:220.96,222.3 1 0
github.com/muety/wakapi/config/config.go:231.52,233.3 1 0
github.com/muety/wakapi/config/config.go:235.47,236.14 1 0
github.com/muety/wakapi/config/config.go:236.14,238.4 1 0
github.com/muety/wakapi/config/config.go:74.70,76.2 1 0
github.com/muety/wakapi/config/config.go:78.65,80.2 1 0
github.com/muety/wakapi/config/config.go:82.82,92.2 1 0
github.com/muety/wakapi/config/config.go:94.31,96.2 1 0
github.com/muety/wakapi/config/config.go:98.74,99.19 1 0
github.com/muety/wakapi/config/config.go:100.10,101.34 1 0
github.com/muety/wakapi/config/config.go:101.34,110.4 8 0
github.com/muety/wakapi/config/config.go:114.73,115.33 1 0
github.com/muety/wakapi/config/config.go:115.33,123.17 5 0
github.com/muety/wakapi/config/config.go:127.3,128.13 2 0
github.com/muety/wakapi/config/config.go:123.17,125.4 1 0
github.com/muety/wakapi/config/config.go:132.50,133.19 1 0
github.com/muety/wakapi/config/config.go:146.2,146.12 1 0
github.com/muety/wakapi/config/config.go:134.23,138.5 1 0
github.com/muety/wakapi/config/config.go:139.26,142.5 1 0
github.com/muety/wakapi/config/config.go:143.24,144.48 1 0
github.com/muety/wakapi/config/config.go:149.53,159.2 1 1
github.com/muety/wakapi/config/config.go:161.56,169.2 1 1
github.com/muety/wakapi/config/config.go:171.54,173.2 1 1
github.com/muety/wakapi/config/config.go:175.29,177.2 1 1
github.com/muety/wakapi/config/config.go:179.27,181.16 2 0
github.com/muety/wakapi/config/config.go:184.2,187.16 3 0
github.com/muety/wakapi/config/config.go:191.2,191.22 1 0
github.com/muety/wakapi/config/config.go:181.16,183.3 1 0
github.com/muety/wakapi/config/config.go:187.16,189.3 1 0
github.com/muety/wakapi/config/config.go:194.45,204.16 4 0
github.com/muety/wakapi/config/config.go:208.2,208.57 1 0
github.com/muety/wakapi/config/config.go:212.2,212.30 1 0
github.com/muety/wakapi/config/config.go:216.2,216.15 1 0
github.com/muety/wakapi/config/config.go:204.16,206.3 1 0
github.com/muety/wakapi/config/config.go:208.57,210.3 1 0
github.com/muety/wakapi/config/config.go:212.30,214.3 1 0
github.com/muety/wakapi/config/config.go:219.38,220.43 1 0
github.com/muety/wakapi/config/config.go:224.2,224.15 1 0
github.com/muety/wakapi/config/config.go:220.43,222.3 1 0
github.com/muety/wakapi/config/config.go:227.26,229.2 1 0
github.com/muety/wakapi/config/config.go:231.20,233.2 1 0
github.com/muety/wakapi/config/config.go:235.21,242.96 4 0
github.com/muety/wakapi/config/config.go:246.2,253.52 4 0
github.com/muety/wakapi/config/config.go:257.2,257.47 1 0
github.com/muety/wakapi/config/config.go:263.2,264.14 2 0
github.com/muety/wakapi/config/config.go:242.96,244.3 1 0
github.com/muety/wakapi/config/config.go:253.52,255.3 1 0
github.com/muety/wakapi/config/config.go:257.47,258.14 1 0
github.com/muety/wakapi/config/config.go:258.14,260.4 1 0
github.com/muety/wakapi/config/legacy.go:13.33,14.57 1 0
github.com/muety/wakapi/config/legacy.go:14.57,16.3 1 0
github.com/muety/wakapi/config/legacy.go:16.8,16.16 1 0
@ -275,6 +281,43 @@ github.com/muety/wakapi/config/legacy.go:75.23,77.3 1 0
github.com/muety/wakapi/config/legacy.go:82.33,84.3 1 0
github.com/muety/wakapi/config/legacy.go:114.16,116.3 1 0
github.com/muety/wakapi/config/legacy.go:119.78,121.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:27.116,34.2 1 1
github.com/muety/wakapi/middlewares/authenticate.go:36.71,37.71 1 0
github.com/muety/wakapi/middlewares/authenticate.go:37.71,39.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:42.107,43.37 1 0
github.com/muety/wakapi/middlewares/authenticate.go:50.2,53.16 3 0
github.com/muety/wakapi/middlewares/authenticate.go:57.2,57.16 1 0
github.com/muety/wakapi/middlewares/authenticate.go:67.2,70.29 3 0
github.com/muety/wakapi/middlewares/authenticate.go:43.37,44.58 1 0
github.com/muety/wakapi/middlewares/authenticate.go:44.58,47.4 2 0
github.com/muety/wakapi/middlewares/authenticate.go:53.16,55.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:57.16,58.44 1 0
github.com/muety/wakapi/middlewares/authenticate.go:64.3,64.9 1 0
github.com/muety/wakapi/middlewares/authenticate.go:58.44,60.4 1 0
github.com/muety/wakapi/middlewares/authenticate.go:60.9,63.4 2 0
github.com/muety/wakapi/middlewares/authenticate.go:73.92,75.16 2 1
github.com/muety/wakapi/middlewares/authenticate.go:79.2,82.9 4 1
github.com/muety/wakapi/middlewares/authenticate.go:90.2,90.18 1 1
github.com/muety/wakapi/middlewares/authenticate.go:75.16,77.3 1 1
github.com/muety/wakapi/middlewares/authenticate.go:82.9,84.17 2 1
github.com/muety/wakapi/middlewares/authenticate.go:84.17,86.4 1 0
github.com/muety/wakapi/middlewares/authenticate.go:87.8,89.3 1 1
github.com/muety/wakapi/middlewares/authenticate.go:93.92,95.16 2 0
github.com/muety/wakapi/middlewares/authenticate.go:99.2,101.8 2 0
github.com/muety/wakapi/middlewares/authenticate.go:105.2,106.16 2 0
github.com/muety/wakapi/middlewares/authenticate.go:110.2,110.88 1 0
github.com/muety/wakapi/middlewares/authenticate.go:114.2,114.18 1 0
github.com/muety/wakapi/middlewares/authenticate.go:95.16,97.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:101.8,103.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:106.16,108.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:110.88,112.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:118.127,119.32 1 0
github.com/muety/wakapi/middlewares/authenticate.go:127.2,127.65 1 0
github.com/muety/wakapi/middlewares/authenticate.go:119.32,120.58 1 0
github.com/muety/wakapi/middlewares/authenticate.go:125.3,125.15 1 0
github.com/muety/wakapi/middlewares/authenticate.go:120.58,124.4 3 0
github.com/muety/wakapi/middlewares/logging.go:11.48,13.2 1 0
github.com/muety/wakapi/middlewares/logging.go:15.66,17.2 1 0
github.com/muety/wakapi/services/aggregation.go:24.142,31.2 1 0
github.com/muety/wakapi/services/aggregation.go:40.43,42.37 1 0
github.com/muety/wakapi/services/aggregation.go:46.2,47.18 2 0
@ -362,95 +405,95 @@ github.com/muety/wakapi/services/language_mapping.go:61.2,62.20 2 0
github.com/muety/wakapi/services/language_mapping.go:57.16,59.3 1 0
github.com/muety/wakapi/services/language_mapping.go:65.82,69.2 3 0
github.com/muety/wakapi/services/language_mapping.go:71.73,73.2 1 0
github.com/muety/wakapi/services/summary.go:27.149,35.2 1 0
github.com/muety/wakapi/services/summary.go:39.120,42.52 2 0
github.com/muety/wakapi/services/summary.go:47.2,47.44 1 0
github.com/muety/wakapi/services/summary.go:53.2,53.66 1 0
github.com/muety/wakapi/services/summary.go:58.2,59.16 2 0
github.com/muety/wakapi/services/summary.go:64.2,66.21 3 0
github.com/muety/wakapi/services/summary.go:27.149,35.2 1 1
github.com/muety/wakapi/services/summary.go:39.120,42.52 2 1
github.com/muety/wakapi/services/summary.go:47.2,47.44 1 1
github.com/muety/wakapi/services/summary.go:53.2,53.66 1 1
github.com/muety/wakapi/services/summary.go:58.2,59.16 2 1
github.com/muety/wakapi/services/summary.go:64.2,66.30 3 1
github.com/muety/wakapi/services/summary.go:42.52,44.3 1 0
github.com/muety/wakapi/services/summary.go:47.44,50.3 2 0
github.com/muety/wakapi/services/summary.go:47.44,50.3 2 1
github.com/muety/wakapi/services/summary.go:53.66,55.3 1 0
github.com/muety/wakapi/services/summary.go:59.16,61.3 1 0
github.com/muety/wakapi/services/summary.go:69.101,72.52 2 0
github.com/muety/wakapi/services/summary.go:77.2,78.16 2 0
github.com/muety/wakapi/services/summary.go:83.2,84.44 2 0
github.com/muety/wakapi/services/summary.go:93.2,94.16 2 0
github.com/muety/wakapi/services/summary.go:99.2,100.21 2 0
github.com/muety/wakapi/services/summary.go:69.101,72.52 2 1
github.com/muety/wakapi/services/summary.go:77.2,78.16 2 1
github.com/muety/wakapi/services/summary.go:83.2,84.44 2 1
github.com/muety/wakapi/services/summary.go:93.2,94.16 2 1
github.com/muety/wakapi/services/summary.go:99.2,100.30 2 1
github.com/muety/wakapi/services/summary.go:72.52,74.3 1 0
github.com/muety/wakapi/services/summary.go:78.16,80.3 1 0
github.com/muety/wakapi/services/summary.go:84.44,85.78 1 0
github.com/muety/wakapi/services/summary.go:85.78,87.4 1 0
github.com/muety/wakapi/services/summary.go:84.44,85.78 1 1
github.com/muety/wakapi/services/summary.go:85.78,87.4 1 1
github.com/muety/wakapi/services/summary.go:87.9,89.4 1 0
github.com/muety/wakapi/services/summary.go:94.16,96.3 1 0
github.com/muety/wakapi/services/summary.go:103.102,106.89 2 0
github.com/muety/wakapi/services/summary.go:112.2,116.26 4 0
github.com/muety/wakapi/services/summary.go:121.2,127.34 6 0
github.com/muety/wakapi/services/summary.go:143.2,143.26 1 0
github.com/muety/wakapi/services/summary.go:148.2,161.21 3 0
github.com/muety/wakapi/services/summary.go:106.89,108.3 1 0
github.com/muety/wakapi/services/summary.go:103.102,106.89 2 1
github.com/muety/wakapi/services/summary.go:112.2,116.26 4 1
github.com/muety/wakapi/services/summary.go:121.2,127.34 6 1
github.com/muety/wakapi/services/summary.go:143.2,143.26 1 1
github.com/muety/wakapi/services/summary.go:148.2,161.30 2 1
github.com/muety/wakapi/services/summary.go:106.89,108.3 1 1
github.com/muety/wakapi/services/summary.go:108.8,110.3 1 0
github.com/muety/wakapi/services/summary.go:116.26,118.3 1 0
github.com/muety/wakapi/services/summary.go:127.34,129.20 2 0
github.com/muety/wakapi/services/summary.go:130.30,131.29 1 0
github.com/muety/wakapi/services/summary.go:132.31,133.30 1 0
github.com/muety/wakapi/services/summary.go:134.29,135.28 1 0
github.com/muety/wakapi/services/summary.go:136.25,137.24 1 0
github.com/muety/wakapi/services/summary.go:138.30,139.29 1 0
github.com/muety/wakapi/services/summary.go:143.26,146.3 2 0
github.com/muety/wakapi/services/summary.go:116.26,118.3 1 1
github.com/muety/wakapi/services/summary.go:127.34,129.20 2 1
github.com/muety/wakapi/services/summary.go:130.30,131.29 1 1
github.com/muety/wakapi/services/summary.go:132.31,133.30 1 1
github.com/muety/wakapi/services/summary.go:134.29,135.28 1 1
github.com/muety/wakapi/services/summary.go:136.25,137.24 1 1
github.com/muety/wakapi/services/summary.go:138.30,139.29 1 1
github.com/muety/wakapi/services/summary.go:143.26,146.3 2 1
github.com/muety/wakapi/services/summary.go:166.76,168.2 1 0
github.com/muety/wakapi/services/summary.go:170.62,172.2 1 0
github.com/muety/wakapi/services/summary.go:174.66,176.2 1 0
github.com/muety/wakapi/services/summary.go:180.127,183.31 2 0
github.com/muety/wakapi/services/summary.go:206.2,207.30 2 0
github.com/muety/wakapi/services/summary.go:215.2,215.40 1 0
github.com/muety/wakapi/services/summary.go:219.2,219.67 1 0
github.com/muety/wakapi/services/summary.go:183.31,186.35 2 0
github.com/muety/wakapi/services/summary.go:190.3,190.13 1 0
github.com/muety/wakapi/services/summary.go:194.3,199.27 2 0
github.com/muety/wakapi/services/summary.go:203.3,203.26 1 0
github.com/muety/wakapi/services/summary.go:186.35,188.4 1 0
github.com/muety/wakapi/services/summary.go:190.13,191.12 1 0
github.com/muety/wakapi/services/summary.go:199.27,202.4 2 0
github.com/muety/wakapi/services/summary.go:207.30,213.3 1 0
github.com/muety/wakapi/services/summary.go:215.40,217.3 1 0
github.com/muety/wakapi/services/summary.go:222.97,223.24 1 0
github.com/muety/wakapi/services/summary.go:227.2,239.30 4 0
github.com/muety/wakapi/services/summary.go:259.2,262.26 3 0
github.com/muety/wakapi/services/summary.go:180.127,183.31 2 1
github.com/muety/wakapi/services/summary.go:206.2,207.30 2 1
github.com/muety/wakapi/services/summary.go:215.2,215.40 1 1
github.com/muety/wakapi/services/summary.go:219.2,219.67 1 1
github.com/muety/wakapi/services/summary.go:183.31,186.35 2 1
github.com/muety/wakapi/services/summary.go:190.3,190.13 1 1
github.com/muety/wakapi/services/summary.go:194.3,199.27 2 1
github.com/muety/wakapi/services/summary.go:203.3,203.26 1 1
github.com/muety/wakapi/services/summary.go:186.35,188.4 1 1
github.com/muety/wakapi/services/summary.go:190.13,191.12 1 1
github.com/muety/wakapi/services/summary.go:199.27,202.4 2 1
github.com/muety/wakapi/services/summary.go:207.30,213.3 1 1
github.com/muety/wakapi/services/summary.go:215.40,217.3 1 1
github.com/muety/wakapi/services/summary.go:222.97,223.24 1 1
github.com/muety/wakapi/services/summary.go:227.2,239.30 4 1
github.com/muety/wakapi/services/summary.go:259.2,262.26 3 1
github.com/muety/wakapi/services/summary.go:223.24,225.3 1 0
github.com/muety/wakapi/services/summary.go:239.30,240.38 1 0
github.com/muety/wakapi/services/summary.go:244.3,244.37 1 0
github.com/muety/wakapi/services/summary.go:248.3,248.34 1 0
github.com/muety/wakapi/services/summary.go:252.3,256.83 5 0
github.com/muety/wakapi/services/summary.go:239.30,240.38 1 1
github.com/muety/wakapi/services/summary.go:244.3,244.37 1 1
github.com/muety/wakapi/services/summary.go:248.3,248.34 1 1
github.com/muety/wakapi/services/summary.go:252.3,256.83 5 1
github.com/muety/wakapi/services/summary.go:240.38,242.4 1 0
github.com/muety/wakapi/services/summary.go:244.37,246.4 1 0
github.com/muety/wakapi/services/summary.go:248.34,250.4 1 0
github.com/muety/wakapi/services/summary.go:265.127,269.32 2 0
github.com/muety/wakapi/services/summary.go:273.2,273.27 1 0
github.com/muety/wakapi/services/summary.go:281.2,283.26 3 0
github.com/muety/wakapi/services/summary.go:288.2,288.43 1 0
github.com/muety/wakapi/services/summary.go:292.2,292.17 1 0
github.com/muety/wakapi/services/summary.go:269.32,271.3 1 0
github.com/muety/wakapi/services/summary.go:273.27,274.37 1 0
github.com/muety/wakapi/services/summary.go:274.37,276.4 1 0
github.com/muety/wakapi/services/summary.go:276.9,278.4 1 0
github.com/muety/wakapi/services/summary.go:283.26,286.3 2 0
github.com/muety/wakapi/services/summary.go:288.43,290.3 1 0
github.com/muety/wakapi/services/summary.go:295.116,296.25 1 0
github.com/muety/wakapi/services/summary.go:300.2,303.44 2 0
github.com/muety/wakapi/services/summary.go:308.2,308.40 1 0
github.com/muety/wakapi/services/summary.go:324.2,324.54 1 0
github.com/muety/wakapi/services/summary.go:328.2,328.18 1 0
github.com/muety/wakapi/services/summary.go:244.37,246.4 1 1
github.com/muety/wakapi/services/summary.go:248.34,250.4 1 1
github.com/muety/wakapi/services/summary.go:265.127,269.32 2 1
github.com/muety/wakapi/services/summary.go:273.2,273.27 1 1
github.com/muety/wakapi/services/summary.go:281.2,283.26 3 1
github.com/muety/wakapi/services/summary.go:288.2,288.43 1 1
github.com/muety/wakapi/services/summary.go:292.2,292.17 1 1
github.com/muety/wakapi/services/summary.go:269.32,271.3 1 1
github.com/muety/wakapi/services/summary.go:273.27,274.37 1 1
github.com/muety/wakapi/services/summary.go:274.37,276.4 1 1
github.com/muety/wakapi/services/summary.go:276.9,278.4 1 1
github.com/muety/wakapi/services/summary.go:283.26,286.3 2 1
github.com/muety/wakapi/services/summary.go:288.43,290.3 1 1
github.com/muety/wakapi/services/summary.go:295.116,296.25 1 1
github.com/muety/wakapi/services/summary.go:300.2,303.44 2 1
github.com/muety/wakapi/services/summary.go:308.2,308.40 1 1
github.com/muety/wakapi/services/summary.go:324.2,324.54 1 1
github.com/muety/wakapi/services/summary.go:328.2,328.18 1 1
github.com/muety/wakapi/services/summary.go:296.25,298.3 1 0
github.com/muety/wakapi/services/summary.go:303.44,305.3 1 0
github.com/muety/wakapi/services/summary.go:308.40,310.19 2 0
github.com/muety/wakapi/services/summary.go:303.44,305.3 1 1
github.com/muety/wakapi/services/summary.go:308.40,310.19 2 1
github.com/muety/wakapi/services/summary.go:315.3,318.22 3 0
github.com/muety/wakapi/services/summary.go:310.19,311.12 1 0
github.com/muety/wakapi/services/summary.go:310.19,311.12 1 1
github.com/muety/wakapi/services/summary.go:318.22,320.4 1 0
github.com/muety/wakapi/services/summary.go:324.54,326.3 1 0
github.com/muety/wakapi/services/summary.go:331.59,333.25 2 0
github.com/muety/wakapi/services/summary.go:336.2,336.32 1 0
github.com/muety/wakapi/services/summary.go:333.25,335.3 1 0
github.com/muety/wakapi/services/summary.go:324.54,326.3 1 1
github.com/muety/wakapi/services/summary.go:331.59,333.25 2 1
github.com/muety/wakapi/services/summary.go:336.2,336.32 1 1
github.com/muety/wakapi/services/summary.go:333.25,335.3 1 1
github.com/muety/wakapi/services/user.go:16.73,21.2 1 0
github.com/muety/wakapi/services/user.go:23.74,25.2 1 0
github.com/muety/wakapi/services/user.go:27.72,29.2 1 0
@ -466,40 +509,3 @@ github.com/muety/wakapi/services/user.go:64.106,66.96 2 0
github.com/muety/wakapi/services/user.go:71.2,71.68 1 0
github.com/muety/wakapi/services/user.go:66.96,68.3 1 0
github.com/muety/wakapi/services/user.go:68.8,70.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:27.116,34.2 1 1
github.com/muety/wakapi/middlewares/authenticate.go:36.71,37.71 1 0
github.com/muety/wakapi/middlewares/authenticate.go:37.71,39.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:42.107,43.37 1 0
github.com/muety/wakapi/middlewares/authenticate.go:50.2,53.16 3 0
github.com/muety/wakapi/middlewares/authenticate.go:57.2,57.16 1 0
github.com/muety/wakapi/middlewares/authenticate.go:67.2,70.29 3 0
github.com/muety/wakapi/middlewares/authenticate.go:43.37,44.58 1 0
github.com/muety/wakapi/middlewares/authenticate.go:44.58,47.4 2 0
github.com/muety/wakapi/middlewares/authenticate.go:53.16,55.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:57.16,58.44 1 0
github.com/muety/wakapi/middlewares/authenticate.go:64.3,64.9 1 0
github.com/muety/wakapi/middlewares/authenticate.go:58.44,60.4 1 0
github.com/muety/wakapi/middlewares/authenticate.go:60.9,63.4 2 0
github.com/muety/wakapi/middlewares/authenticate.go:73.92,75.16 2 1
github.com/muety/wakapi/middlewares/authenticate.go:79.2,82.9 4 1
github.com/muety/wakapi/middlewares/authenticate.go:90.2,90.18 1 1
github.com/muety/wakapi/middlewares/authenticate.go:75.16,77.3 1 1
github.com/muety/wakapi/middlewares/authenticate.go:82.9,84.17 2 1
github.com/muety/wakapi/middlewares/authenticate.go:84.17,86.4 1 0
github.com/muety/wakapi/middlewares/authenticate.go:87.8,89.3 1 1
github.com/muety/wakapi/middlewares/authenticate.go:93.92,95.16 2 0
github.com/muety/wakapi/middlewares/authenticate.go:99.2,101.8 2 0
github.com/muety/wakapi/middlewares/authenticate.go:105.2,106.16 2 0
github.com/muety/wakapi/middlewares/authenticate.go:110.2,110.88 1 0
github.com/muety/wakapi/middlewares/authenticate.go:114.2,114.18 1 0
github.com/muety/wakapi/middlewares/authenticate.go:95.16,97.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:101.8,103.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:106.16,108.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:110.88,112.3 1 0
github.com/muety/wakapi/middlewares/authenticate.go:118.127,119.32 1 0
github.com/muety/wakapi/middlewares/authenticate.go:127.2,127.65 1 0
github.com/muety/wakapi/middlewares/authenticate.go:119.32,120.58 1 0
github.com/muety/wakapi/middlewares/authenticate.go:125.3,125.15 1 0
github.com/muety/wakapi/middlewares/authenticate.go:120.58,124.4 3 0
github.com/muety/wakapi/middlewares/logging.go:11.48,13.2 1 0
github.com/muety/wakapi/middlewares/logging.go:15.66,17.2 1 0

View File

@ -58,7 +58,7 @@ func (m *AuthenticateMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Reques
if strings.HasPrefix(r.URL.Path, "/api") {
w.WriteHeader(http.StatusUnauthorized)
} else {
utils.ClearCookie(w, models.AuthCookieKey, !m.config.Security.InsecureCookies)
http.SetCookie(w, m.config.GetClearCookie(models.AuthCookieKey, "/"))
http.Redirect(w, r, fmt.Sprintf("%s/?error=unauthorized", m.config.Server.BasePath), http.StatusFound)
}
return

View File

@ -1,6 +1,7 @@
package models
import (
"sort"
"time"
)
@ -39,13 +40,15 @@ type Summary struct {
UserID string `json:"user_id" gorm:"not null; index:idx_time_summary_user"`
FromTime CustomTime `json:"from" gorm:"not null; type:timestamp; default:CURRENT_TIMESTAMP; index:idx_time_summary_user"`
ToTime CustomTime `json:"to" gorm:"not null; type:timestamp; default:CURRENT_TIMESTAMP; index:idx_time_summary_user"`
Projects []*SummaryItem `json:"projects" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Languages []*SummaryItem `json:"languages" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Editors []*SummaryItem `json:"editors" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
OperatingSystems []*SummaryItem `json:"operating_systems" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Machines []*SummaryItem `json:"machines" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Projects SummaryItems `json:"projects" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Languages SummaryItems `json:"languages" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Editors SummaryItems `json:"editors" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
OperatingSystems SummaryItems `json:"operating_systems" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Machines SummaryItems `json:"machines" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
}
type SummaryItems []*SummaryItem
type SummaryItem struct {
ID uint `json:"-" gorm:"primary_key"`
Summary *Summary `json:"-" gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
@ -81,12 +84,21 @@ func SummaryTypes() []uint8 {
return []uint8{SummaryProject, SummaryLanguage, SummaryEditor, SummaryOS, SummaryMachine}
}
func (s *Summary) Sorted() *Summary {
sort.Sort(sort.Reverse(s.Projects))
sort.Sort(sort.Reverse(s.Machines))
sort.Sort(sort.Reverse(s.OperatingSystems))
sort.Sort(sort.Reverse(s.Languages))
sort.Sort(sort.Reverse(s.Editors))
return s
}
func (s *Summary) Types() []uint8 {
return SummaryTypes()
}
func (s *Summary) MappedItems() map[uint8]*[]*SummaryItem {
return map[uint8]*[]*SummaryItem{
func (s *Summary) MappedItems() map[uint8]*SummaryItems {
return map[uint8]*SummaryItems{
SummaryProject: &s.Projects,
SummaryLanguage: &s.Languages,
SummaryEditor: &s.Editors,
@ -230,3 +242,15 @@ func (s *Summary) WithResolvedAliases(resolve AliasResolver) *Summary {
return s
}
func (s SummaryItems) Len() int {
return len(s)
}
func (s SummaryItems) Less(i, j int) bool {
return s[i].Total < s[j].Total
}
func (s SummaryItems) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

View File

@ -163,3 +163,33 @@ func TestSummary_WithResolvedAliases(t *testing.T) {
assert.Empty(t, sut.OperatingSystems)
assert.Empty(t, sut.Machines)
}
func TestSummaryItems_Sorted(t *testing.T) {
testDuration1, testDuration2, testDuration3 := 10*time.Minute, 5*time.Minute, 20*time.Minute
sut := &Summary{
Projects: []*SummaryItem{
{
Type: SummaryProject,
Key: "wakapi",
Total: testDuration1,
},
{
Type: SummaryProject,
Key: "anchr",
Total: testDuration2,
},
{
Type: SummaryProject,
Key: "anchr-mobile",
Total: testDuration3,
},
},
}
sut = sut.Sorted()
assert.Equal(t, testDuration3, sut.Projects[0].Total)
assert.Equal(t, testDuration1, sut.Projects[1].Total)
assert.Equal(t, testDuration2, sut.Projects[2].Total)
}

View File

@ -8,7 +8,6 @@ import (
"github.com/muety/wakapi/models"
"github.com/muety/wakapi/models/view"
"github.com/muety/wakapi/services"
"github.com/muety/wakapi/utils"
"net/http"
"time"
)
@ -87,14 +86,7 @@ func (h *HomeHandler) PostLogin(w http.ResponseWriter, r *http.Request) {
user.LastLoggedInAt = models.CustomTime(time.Now())
h.userSrvc.Update(user)
cookie := &http.Cookie{
Name: models.AuthCookieKey,
Value: encoded,
Path: "/",
Secure: !h.config.Security.InsecureCookies,
HttpOnly: true,
}
http.SetCookie(w, cookie)
http.SetCookie(w, h.config.CreateCookie(models.AuthCookieKey, encoded, "/"))
http.Redirect(w, r, fmt.Sprintf("%s/summary", h.config.Server.BasePath), http.StatusFound)
}
@ -103,7 +95,7 @@ func (h *HomeHandler) PostLogout(w http.ResponseWriter, r *http.Request) {
loadTemplates()
}
utils.ClearCookie(w, models.AuthCookieKey, !h.config.Security.InsecureCookies)
http.SetCookie(w, h.config.GetClearCookie(models.AuthCookieKey, "/"))
http.Redirect(w, r, fmt.Sprintf("%s/", h.config.Server.BasePath), http.StatusFound)
}

View File

@ -98,15 +98,7 @@ func (h *SettingsHandler) PostCredentials(w http.ResponseWriter, r *http.Request
return
}
cookie := &http.Cookie{
Name: models.AuthCookieKey,
Value: encoded,
Path: "/",
Secure: !h.config.Security.InsecureCookies,
HttpOnly: true,
}
http.SetCookie(w, cookie)
http.SetCookie(w, h.config.CreateCookie(models.AuthCookieKey, encoded, "/"))
templates[conf.SettingsTemplate].Execute(w, h.buildViewModel(r).WithSuccess("password was updated successfully"))
}

View File

@ -63,7 +63,7 @@ func (srv *SummaryService) Aliased(from, to time.Time, user *models.User, f Summ
// Post-process summary and cache it
summary := s.WithResolvedAliases(resolve)
srv.cache.SetDefault(cacheKey, summary)
return summary, nil
return summary.Sorted(), nil
}
func (srv *SummaryService) Retrieve(from, to time.Time, user *models.User) (*models.Summary, error) {
@ -97,7 +97,7 @@ func (srv *SummaryService) Retrieve(from, to time.Time, user *models.User) (*mod
// Cache 'em
srv.cache.SetDefault(cacheKey, summary)
return summary, nil
return summary.Sorted(), nil
}
func (srv *SummaryService) Summarize(from, to time.Time, user *models.User) (*models.Summary, error) {
@ -158,7 +158,7 @@ func (srv *SummaryService) Summarize(from, to time.Time, user *models.User) (*mo
//summary.FillUnknown()
return summary, nil
return summary.Sorted(), nil
}
// CRUD methods

View File

@ -13,13 +13,3 @@ func RespondJSON(w http.ResponseWriter, status int, object interface{}) {
log.Printf("error while writing json response: %v", err)
}
}
func ClearCookie(w http.ResponseWriter, name string, secure bool) {
http.SetCookie(w, &http.Cookie{
Name: name,
Value: "",
Path: "/",
Secure: secure,
HttpOnly: true,
})
}

View File

@ -1 +1 @@
1.16.3
1.16.4