Added support for migration on changepassword and login

This commit is contained in:
Tracker-Friendly 2024-07-21 09:09:30 +01:00
parent 1fb0d1c85a
commit 9725de7fb3
1 changed files with 28 additions and 0 deletions

28
main.go
View File

@ -454,6 +454,11 @@ func main() {
c.JSON(400, gin.H{"error": "Invalid JSON"})
return
}
modern, ok := data["modern"].(bool)
if !ok {
c.JSON(400, gin.H{"error": "Invalid JSON"})
return
}
userid, taken, err := checkUsernameTaken(username)
if !taken {
@ -499,6 +504,15 @@ func main() {
c.JSON(401, gin.H{"error": "Incorrect password", "migrated": true})
return
}
} else {
if modern && migrated == 0 {
_, err := conn.Exec("UPDATE users SET migrated = 1 WHERE id = ?", userid)
if err != nil {
log.Println("[ERROR] Unknown in /api/login modern Exec():", err)
c.JSON(500, gin.H{"error": "Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-MODERN"})
return
}
}
}
token, err := randomChars(512)
@ -655,6 +669,11 @@ func main() {
c.JSON(400, gin.H{"error": "Invalid JSON"})
return
}
migrate, ok := data["migration"].(bool)
if !ok {
c.JSON(400, gin.H{"error": "Invalid JSON"})
return
}
_, userid, err := getSession(token)
if err != nil {
@ -682,6 +701,15 @@ func main() {
return
}
if migrate {
_, err = conn.Exec("UPDATE users SET migrated = 1 WHERE id = ?", userid)
if err != nil {
log.Println("[ERROR] Unknown in /api/changepassword migrate Exec():", err)
c.JSON(500, gin.H{"error": "Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-CHANGEPASSWORD-MIGRATE"})
return
}
}
c.JSON(200, gin.H{"success": true})
})