tbs
This commit is contained in:
@@ -352,11 +352,11 @@ func (db AuthSqlite) DeleteToken(token string) error {
|
|||||||
func (db AuthSqlite) InsertSession(session *Session) error {
|
func (db AuthSqlite) InsertSession(session *Session) error {
|
||||||
|
|
||||||
_, err := db.db.Exec(`
|
_, err := db.db.Exec(`
|
||||||
INSERT INTO session (session_id, user_id, created_at)
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
||||||
VALUES (?, ?, ?)`, session.Id, session.UserId, session.CreatedAt)
|
VALUES (?, ?, ?, ?)`, session.Id, session.UserId, session.CreatedAt, session.ExpiresAt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Could not insert new session", err)
|
log.Error("Could not insert new session %v", err)
|
||||||
return types.ErrInternal
|
return types.ErrInternal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ var (
|
|||||||
|
|
||||||
func (handler AuthImpl) handleSignInPage() http.HandlerFunc {
|
func (handler AuthImpl) handleSignInPage() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 != nil {
|
||||||
if !session.User.EmailVerified {
|
if !session.User.EmailVerified {
|
||||||
utils.DoRedirect(w, r, "/auth/verify")
|
utils.DoRedirect(w, r, "/auth/verify")
|
||||||
@@ -122,7 +122,7 @@ func (handler AuthImpl) handleSignIn() http.HandlerFunc {
|
|||||||
|
|
||||||
func (handler AuthImpl) handleSignUpPage() http.HandlerFunc {
|
func (handler AuthImpl) handleSignUpPage() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 != nil {
|
||||||
if !session.User.EmailVerified {
|
if !session.User.EmailVerified {
|
||||||
@@ -140,7 +140,7 @@ func (handler AuthImpl) handleSignUpPage() http.HandlerFunc {
|
|||||||
|
|
||||||
func (handler AuthImpl) handleSignUpVerifyPage() http.HandlerFunc {
|
func (handler AuthImpl) handleSignUpVerifyPage() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 == nil {
|
||||||
utils.DoRedirect(w, r, "/auth/signin")
|
utils.DoRedirect(w, r, "/auth/signin")
|
||||||
return
|
return
|
||||||
@@ -158,7 +158,7 @@ func (handler AuthImpl) handleSignUpVerifyPage() http.HandlerFunc {
|
|||||||
|
|
||||||
func (handler AuthImpl) handleVerifyResendComp() http.HandlerFunc {
|
func (handler AuthImpl) handleVerifyResendComp() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 == nil {
|
||||||
utils.DoRedirect(w, r, "/auth/signin")
|
utils.DoRedirect(w, r, "/auth/signin")
|
||||||
return
|
return
|
||||||
@@ -221,7 +221,7 @@ func (handler AuthImpl) handleSignUp() http.HandlerFunc {
|
|||||||
|
|
||||||
func (handler AuthImpl) handleSignOut() http.HandlerFunc {
|
func (handler AuthImpl) handleSignOut() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 != nil {
|
||||||
err := handler.service.SignOut(session.Id)
|
err := handler.service.SignOut(session.Id)
|
||||||
@@ -248,9 +248,10 @@ func (handler AuthImpl) handleSignOut() http.HandlerFunc {
|
|||||||
|
|
||||||
func (handler AuthImpl) handleDeleteAccountPage() http.HandlerFunc {
|
func (handler AuthImpl) handleDeleteAccountPage() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 == nil {
|
||||||
utils.DoRedirect(w, r, "/auth/signin")
|
utils.DoRedirect(w, r, "/auth/signin")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
comp := auth.DeleteAccountComp()
|
comp := auth.DeleteAccountComp()
|
||||||
@@ -260,7 +261,7 @@ func (handler AuthImpl) handleDeleteAccountPage() http.HandlerFunc {
|
|||||||
|
|
||||||
func (handler AuthImpl) handleDeleteAccountComp() http.HandlerFunc {
|
func (handler AuthImpl) handleDeleteAccountComp() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 == nil {
|
||||||
utils.DoRedirect(w, r, "/auth/signin")
|
utils.DoRedirect(w, r, "/auth/signin")
|
||||||
return
|
return
|
||||||
@@ -289,7 +290,7 @@ func (handler AuthImpl) handleChangePasswordPage() http.HandlerFunc {
|
|||||||
|
|
||||||
isPasswordReset := r.URL.Query().Has("token")
|
isPasswordReset := r.URL.Query().Has("token")
|
||||||
|
|
||||||
session := r.Context().Value(middleware.SessionKey).(*service.Session)
|
session := middleware.GetSession(r)
|
||||||
|
|
||||||
if session == nil && !isPasswordReset {
|
if session == nil && !isPasswordReset {
|
||||||
utils.DoRedirect(w, r, "/auth/signin")
|
utils.DoRedirect(w, r, "/auth/signin")
|
||||||
@@ -304,7 +305,7 @@ func (handler AuthImpl) handleChangePasswordPage() http.HandlerFunc {
|
|||||||
func (handler AuthImpl) handleChangePasswordComp() http.HandlerFunc {
|
func (handler AuthImpl) handleChangePasswordComp() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 == nil {
|
||||||
utils.DoRedirect(w, r, "/auth/signin")
|
utils.DoRedirect(w, r, "/auth/signin")
|
||||||
return
|
return
|
||||||
@@ -326,7 +327,7 @@ func (handler AuthImpl) handleChangePasswordComp() http.HandlerFunc {
|
|||||||
func (handler AuthImpl) handleResetPasswordPage() http.HandlerFunc {
|
func (handler AuthImpl) handleResetPasswordPage() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 == nil {
|
||||||
utils.DoRedirect(w, r, "/auth/signin")
|
utils.DoRedirect(w, r, "/auth/signin")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func (handler IndexImpl) Handle(router *http.ServeMux) {
|
|||||||
|
|
||||||
func (handler IndexImpl) handleIndexAnd404() http.HandlerFunc {
|
func (handler IndexImpl) handleIndexAnd404() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session := r.Context().Value(middleware.SessionKey).(*service.Session)
|
session := middleware.GetSession(r)
|
||||||
var user *service.User
|
var user *service.User
|
||||||
if session != nil {
|
if session != nil {
|
||||||
user = session.User
|
user = session.User
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func (handler WorkoutImpl) Handle(router *http.ServeMux) {
|
|||||||
|
|
||||||
func (handler WorkoutImpl) handleWorkoutPage() http.HandlerFunc {
|
func (handler WorkoutImpl) handleWorkoutPage() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 == nil {
|
||||||
utils.DoRedirect(w, r, "/auth/signin")
|
utils.DoRedirect(w, r, "/auth/signin")
|
||||||
return
|
return
|
||||||
@@ -53,7 +53,7 @@ func (handler WorkoutImpl) handleWorkoutPage() http.HandlerFunc {
|
|||||||
|
|
||||||
func (handler WorkoutImpl) handleAddWorkout() http.HandlerFunc {
|
func (handler WorkoutImpl) handleAddWorkout() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 == nil {
|
||||||
utils.DoRedirect(w, r, "/auth/signin")
|
utils.DoRedirect(w, r, "/auth/signin")
|
||||||
return
|
return
|
||||||
@@ -80,7 +80,7 @@ func (handler WorkoutImpl) handleAddWorkout() http.HandlerFunc {
|
|||||||
|
|
||||||
func (handler WorkoutImpl) handleGetWorkout() http.HandlerFunc {
|
func (handler WorkoutImpl) handleGetWorkout() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 == nil {
|
||||||
utils.DoRedirect(w, r, "/auth/signin")
|
utils.DoRedirect(w, r, "/auth/signin")
|
||||||
return
|
return
|
||||||
@@ -103,7 +103,7 @@ func (handler WorkoutImpl) handleGetWorkout() http.HandlerFunc {
|
|||||||
|
|
||||||
func (handler WorkoutImpl) handleDeleteWorkout() http.HandlerFunc {
|
func (handler WorkoutImpl) handleDeleteWorkout() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 == nil {
|
||||||
utils.DoRedirect(w, r, "/auth/signin")
|
utils.DoRedirect(w, r, "/auth/signin")
|
||||||
return
|
return
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -49,8 +49,7 @@ func run(ctx context.Context, database *sql.DB, env func(string) string) {
|
|||||||
// init db
|
// init db
|
||||||
err := db.RunMigrations(database, "")
|
err := db.RunMigrations(database, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Could not run migrations: %v", err)
|
log.Fatal("Could not run migrations: %v", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// init servers
|
// init servers
|
||||||
@@ -81,7 +80,6 @@ func startServer(s *http.Server) {
|
|||||||
log.Info("Starting server on %v", s.Addr)
|
log.Info("Starting server on %v", s.Addr)
|
||||||
if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||||
log.Error("error listening and serving: %v", err)
|
log.Error("error listening and serving: %v", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user