migrate old database format correctly, fix typo, update readme

This commit is contained in:
Christoph Haas 2021-02-26 23:13:11 +01:00
parent 9bd80dbd33
commit 2b77148b81
3 changed files with 12 additions and 1 deletions

View File

@ -3,6 +3,7 @@
[![Build Status](https://travis-ci.com/h44z/wg-portal.svg?token=q4pSqaqT58Jzpxdx62xk&branch=master)](https://travis-ci.com/h44z/wg-portal) [![Build Status](https://travis-ci.com/h44z/wg-portal.svg?token=q4pSqaqT58Jzpxdx62xk&branch=master)](https://travis-ci.com/h44z/wg-portal)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT)
![GitHub last commit](https://img.shields.io/github/last-commit/h44z/wg-portal) ![GitHub last commit](https://img.shields.io/github/last-commit/h44z/wg-portal)
[![Go Report Card](https://goreportcard.com/badge/github.com/h44z/wg-portal)](https://goreportcard.com/report/github.com/h44z/wg-portal)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/h44z/wg-portal) ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/h44z/wg-portal)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/h44z/wg-portal) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/h44z/wg-portal)
[![Docker Pulls](https://img.shields.io/docker/pulls/h44z/wg-portal.svg)](https://hub.docker.com/r/h44z/wg-portal/) [![Docker Pulls](https://img.shields.io/docker/pulls/h44z/wg-portal.svg)](https://hub.docker.com/r/h44z/wg-portal/)
@ -27,6 +28,7 @@ It also supports LDAP (Active Directory or OpenLDAP) as authentication provider.
* Dockerized * Dockerized
* Responsive template * Responsive template
* One single binary * One single binary
* Can be used with existing WireGuard setups
![Screenshot](screenshot.png) ![Screenshot](screenshot.png)

View File

@ -59,7 +59,7 @@ func (provider Provider) Login(ctx *authentication.AuthContext) (string, error)
return "", errors.New("empty username or password") return "", errors.New("empty username or password")
} }
// Authenticate agains the users database // Authenticate against the users database
user := users.User{} user := users.User{}
provider.db.Where("email = ?", username).First(&user) provider.db.Where("email = ?", username).First(&user)

View File

@ -75,6 +75,15 @@ func NewManager(cfg *Config) (*Manager, error) {
return nil, errors.Wrapf(err, "failed to setup user database %s", cfg.Database) return nil, errors.Wrapf(err, "failed to setup user database %s", cfg.Database)
} }
// check if old user table exists (from version <= 1.0.2), if so rename it to peers.
if m.db.Migrator().HasTable("users") && !m.db.Migrator().HasTable("peers") {
if err := m.db.Migrator().RenameTable("users", "peers"); err != nil {
return nil, errors.Wrapf(err, "failed to migrate old database structure")
} else {
logrus.Infof("upgraded database format from version v1.0.2")
}
}
return m, m.MigrateUserDB() return m, m.MigrateUserDB()
} }