(c *gin.Context, data *repository.Session)
| 293 | } |
| 294 | |
| 295 | func (auth *AuthService) CreateSessionCookie(c *gin.Context, data *repository.Session) error { |
| 296 | uuid, err := uuid.NewRandom() |
| 297 | |
| 298 | if err != nil { |
| 299 | return err |
| 300 | } |
| 301 | |
| 302 | var expiry int |
| 303 | |
| 304 | if data.TotpPending { |
| 305 | expiry = 3600 |
| 306 | } else { |
| 307 | expiry = auth.config.SessionExpiry |
| 308 | } |
| 309 | |
| 310 | session := repository.CreateSessionParams{ |
| 311 | UUID: uuid.String(), |
| 312 | Username: data.Username, |
| 313 | Email: data.Email, |
| 314 | Name: data.Name, |
| 315 | Provider: data.Provider, |
| 316 | TotpPending: data.TotpPending, |
| 317 | OAuthGroups: data.OAuthGroups, |
| 318 | Expiry: time.Now().Add(time.Duration(expiry) * time.Second).Unix(), |
| 319 | CreatedAt: time.Now().Unix(), |
| 320 | OAuthName: data.OAuthName, |
| 321 | OAuthSub: data.OAuthSub, |
| 322 | } |
| 323 | |
| 324 | _, err = auth.queries.CreateSession(c, session) |
| 325 | |
| 326 | if err != nil { |
| 327 | return err |
| 328 | } |
| 329 | |
| 330 | c.SetCookie(auth.config.SessionCookieName, session.UUID, expiry, "/", fmt.Sprintf(".%s", auth.config.CookieDomain), auth.config.SecureCookie, true) |
| 331 | |
| 332 | return nil |
| 333 | } |
| 334 | |
| 335 | func (auth *AuthService) RefreshSessionCookie(c *gin.Context) error { |
| 336 | cookie, err := c.Cookie(auth.config.SessionCookieName) |
no test coverage detected