tbs
Some checks failed
Build Docker Image / Build-Docker-Image (push) Failing after 40s

This commit is contained in:
2024-12-05 23:46:40 +01:00
parent 84fc813704
commit 58946eb488
5 changed files with 20 additions and 21 deletions

View File

@@ -352,11 +352,11 @@ func (db AuthSqlite) DeleteToken(token string) error {
func (db AuthSqlite) InsertSession(session *Session) error {
_, err := db.db.Exec(`
INSERT INTO session (session_id, user_id, created_at)
VALUES (?, ?, ?)`, session.Id, session.UserId, session.CreatedAt)
INSERT INTO session (session_id, user_id, created_at, expires_at)
VALUES (?, ?, ?, ?)`, session.Id, session.UserId, session.CreatedAt, session.ExpiresAt)
if err != nil {
log.Error("Could not insert new session", err)
log.Error("Could not insert new session %v", err)
return types.ErrInternal
}

View File

@@ -59,7 +59,7 @@ var (
func (handler AuthImpl) handleSignInPage() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session != nil {
if !session.User.EmailVerified {
utils.DoRedirect(w, r, "/auth/verify")
@@ -122,7 +122,7 @@ func (handler AuthImpl) handleSignIn() http.HandlerFunc {
func (handler AuthImpl) handleSignUpPage() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session != nil {
if !session.User.EmailVerified {
@@ -140,7 +140,7 @@ func (handler AuthImpl) handleSignUpPage() http.HandlerFunc {
func (handler AuthImpl) handleSignUpVerifyPage() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session == nil {
utils.DoRedirect(w, r, "/auth/signin")
return
@@ -158,7 +158,7 @@ func (handler AuthImpl) handleSignUpVerifyPage() http.HandlerFunc {
func (handler AuthImpl) handleVerifyResendComp() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session == nil {
utils.DoRedirect(w, r, "/auth/signin")
return
@@ -221,7 +221,7 @@ func (handler AuthImpl) handleSignUp() http.HandlerFunc {
func (handler AuthImpl) handleSignOut() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session != nil {
err := handler.service.SignOut(session.Id)
@@ -248,9 +248,10 @@ func (handler AuthImpl) handleSignOut() http.HandlerFunc {
func (handler AuthImpl) handleDeleteAccountPage() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session == nil {
utils.DoRedirect(w, r, "/auth/signin")
return
}
comp := auth.DeleteAccountComp()
@@ -260,7 +261,7 @@ func (handler AuthImpl) handleDeleteAccountPage() http.HandlerFunc {
func (handler AuthImpl) handleDeleteAccountComp() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session == nil {
utils.DoRedirect(w, r, "/auth/signin")
return
@@ -289,7 +290,7 @@ func (handler AuthImpl) handleChangePasswordPage() http.HandlerFunc {
isPasswordReset := r.URL.Query().Has("token")
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session == nil && !isPasswordReset {
utils.DoRedirect(w, r, "/auth/signin")
@@ -304,7 +305,7 @@ func (handler AuthImpl) handleChangePasswordPage() http.HandlerFunc {
func (handler AuthImpl) handleChangePasswordComp() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session == nil {
utils.DoRedirect(w, r, "/auth/signin")
return
@@ -326,7 +327,7 @@ func (handler AuthImpl) handleChangePasswordComp() http.HandlerFunc {
func (handler AuthImpl) handleResetPasswordPage() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session == nil {
utils.DoRedirect(w, r, "/auth/signin")
return

View File

@@ -32,7 +32,7 @@ func (handler IndexImpl) Handle(router *http.ServeMux) {
func (handler IndexImpl) handleIndexAnd404() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
var user *service.User
if session != nil {
user = session.User

View File

@@ -39,7 +39,7 @@ func (handler WorkoutImpl) Handle(router *http.ServeMux) {
func (handler WorkoutImpl) handleWorkoutPage() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session == nil {
utils.DoRedirect(w, r, "/auth/signin")
return
@@ -53,7 +53,7 @@ func (handler WorkoutImpl) handleWorkoutPage() http.HandlerFunc {
func (handler WorkoutImpl) handleAddWorkout() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session == nil {
utils.DoRedirect(w, r, "/auth/signin")
return
@@ -80,7 +80,7 @@ func (handler WorkoutImpl) handleAddWorkout() http.HandlerFunc {
func (handler WorkoutImpl) handleGetWorkout() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session == nil {
utils.DoRedirect(w, r, "/auth/signin")
return
@@ -103,7 +103,7 @@ func (handler WorkoutImpl) handleGetWorkout() http.HandlerFunc {
func (handler WorkoutImpl) handleDeleteWorkout() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(middleware.SessionKey).(*service.Session)
session := middleware.GetSession(r)
if session == nil {
utils.DoRedirect(w, r, "/auth/signin")
return

View File

@@ -49,8 +49,7 @@ func run(ctx context.Context, database *sql.DB, env func(string) string) {
// init db
err := db.RunMigrations(database, "")
if err != nil {
log.Error("Could not run migrations: %v", err)
os.Exit(1)
log.Fatal("Could not run migrations: %v", err)
}
// init servers
@@ -81,7 +80,6 @@ func startServer(s *http.Server) {
log.Info("Starting server on %v", s.Addr)
if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Error("error listening and serving: %v", err)
os.Exit(1)
}
}