Migrate from old credentials

This commit is contained in:
Michal Horejsek
2020-08-21 14:27:31 +02:00
parent 4973e38748
commit 2d9417d501
4 changed files with 19 additions and 2 deletions

View File

@ -15,11 +15,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>. // along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
// Code generated by ./release-notes.sh at 'Fri Aug 21 09:35:33 CEST 2020'. DO NOT EDIT. // Code generated by ./release-notes.sh at 'Fri Aug 21 14:17:14 CEST 2020'. DO NOT EDIT.
package importexport package importexport
const ReleaseNotes = `Complete code refactor in preparation of live release and open source of the Import-Export app const ReleaseNotes = `Note: you need to log in again
• Complete code refactor in preparation of live release and open source of the Import-Export app
• Increased number of supported mail providers by changing the way the folder structures are handled (NIL hierarchy delimiter) • Increased number of supported mail providers by changing the way the folder structures are handled (NIL hierarchy delimiter)
• Improved handling for unstable internet and pause & resume behavior • Improved handling for unstable internet and pause & resume behavior
` `

View File

@ -186,6 +186,13 @@ func (s *Store) List() (userIDs []string, err error) {
continue continue
} }
// Old credentials using username as a key does not work with new code.
// We need to ask user to login again to get ID from API and migrate creds.
if creds.UserID == creds.Name && creds.APIToken != "" {
creds.Logout()
_ = s.saveCredentials(creds)
}
credentialList = append(credentialList, creds) credentialList = append(credentialList, creds)
} }

View File

@ -249,6 +249,14 @@ func (u *Users) FinishLogin(authClient pmapi.Client, auth *pmapi.Auth, mbPassphr
} }
} }
// Old credentials use username as key (user ID) which needs to be removed
// once user logs in again with proper ID fetched from API.
if _, ok := u.hasUser(apiUser.Name); ok {
if err := u.DeleteUser(apiUser.Name, true); err != nil {
log.WithError(err).Error("Failed to delete old user")
}
}
u.events.Emit(events.UserRefreshEvent, apiUser.ID) u.events.Emit(events.UserRefreshEvent, apiUser.ID)
return u.GetUser(apiUser.ID) return u.GetUser(apiUser.ID)

View File

@ -1,3 +1,4 @@
• Note: you need to log in again
• Complete code refactor in preparation of live release and open source of the Import-Export app • Complete code refactor in preparation of live release and open source of the Import-Export app
• Increased number of supported mail providers by changing the way the folder structures are handled (NIL hierarchy delimiter) • Increased number of supported mail providers by changing the way the folder structures are handled (NIL hierarchy delimiter)
• Improved handling for unstable internet and pause & resume behavior • Improved handling for unstable internet and pause & resume behavior