mirror of
https://github.com/vwxyzjn/portwarden
synced 2026-01-04 16:13:13 +00:00
API-6 # Allow the user to cancel backup setup
This commit is contained in:
@@ -16,6 +16,9 @@ const (
|
||||
ErrGettingPortwardenUser = "error getting a portwarden user"
|
||||
ErrLoginWithBitwarden = "error logging in with Bitwarden"
|
||||
ErrSettingupBackup = "error setting up backup"
|
||||
ErrBackupNotCancelled = "error cancelling back up"
|
||||
|
||||
MsgSuccessfullyCancelledBackingUp = "successfully cancelled backup process"
|
||||
|
||||
FrontEndBaseAddressTest = "http://localhost:8000/"
|
||||
FrontEndBaseAddressProd = ""
|
||||
@@ -28,8 +31,8 @@ func EncryptBackupHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": ErrBindingFromGin})
|
||||
return
|
||||
}
|
||||
if err := pu.LoginWithBitwarden(); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": ErrLoginWithBitwarden})
|
||||
if !pu.BackupSetting.WillSetupBackup {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"message": MsgSuccessfullyCancelledBackingUp})
|
||||
return
|
||||
}
|
||||
opu.Email = pu.Email
|
||||
@@ -37,9 +40,14 @@ func EncryptBackupHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": ErrGettingPortwardenUser})
|
||||
return
|
||||
}
|
||||
if err := pu.LoginWithBitwarden(); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": ErrLoginWithBitwarden})
|
||||
return
|
||||
}
|
||||
|
||||
opu.BackupSetting = pu.BackupSetting
|
||||
if err := opu.SetupAutomaticBackup(nil); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": ErrSettingupBackup})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": MsgSuccessfullyCancelledBackingUp})
|
||||
return
|
||||
}
|
||||
if err := opu.Set(); err != nil {
|
||||
@@ -48,11 +56,35 @@ func EncryptBackupHandler(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func CancelEncryptBackupHandler(c *gin.Context) {
|
||||
var pu PortwardenUser
|
||||
var opu PortwardenUser
|
||||
if err := c.ShouldBindJSON(&pu); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": ErrBindingFromGin})
|
||||
return
|
||||
}
|
||||
if pu.BackupSetting.WillSetupBackup {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "", "message": ErrBackupNotCancelled})
|
||||
return
|
||||
}
|
||||
opu.Email = pu.Email
|
||||
if err := opu.Get(); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": ErrGettingPortwardenUser})
|
||||
return
|
||||
}
|
||||
opu.BackupSetting = pu.BackupSetting
|
||||
if err := opu.Set(); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": ErrCreatingPortwardenUser})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": MsgSuccessfullyCancelledBackingUp})
|
||||
}
|
||||
|
||||
//TODO: GoogleDriveHandler() will return Json with the google login url
|
||||
// Not sure if it's supposed to call UploadFile() directly
|
||||
func (ps *PortwardenServer) GetGoogleDriveLoginURLHandler(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"login_url": ps.GoogleDriveAppConfig.AuthCodeURL("state-token", oauth2.AccessTypeOffline, oauth2.ApprovalForce),
|
||||
"login_url": web.GoogleDriveAppConfig.AuthCodeURL("state-token", oauth2.AccessTypeOffline, oauth2.ApprovalForce),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user