Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password with Registration Fails #16

Open
danforbes opened this issue Sep 26, 2018 · 7 comments
Open

Password with Registration Fails #16

danforbes opened this issue Sep 26, 2018 · 7 comments

Comments

@danforbes
Copy link

I am unable to register a new user with a password. The UI states invalid account. The server output states (pq: missing FROM-clause entry for table "basics"). I am using code inspired by this project's README.md.

package main

import (
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/postgres"
	"github.com/qor/auth"
	"github.com/qor/auth/auth_identity"
	"github.com/qor/auth/providers/password"
	"github.com/qor/session/manager"

	"net/http"
)

var (
	// Initialize gorm DB
	gormDB, _ = gorm.Open("postgres", "host=localhost port=5432 user=postgres dbname=postgres password=postgres sslmode=disable")

	// Initialize Auth with configuration
	Auth = auth.New(&auth.Config{
		DB: gormDB,
	})
)

func init() {
	// Migrate AuthIdentity model, AuthIdentity will be used to save auth info, like username/password, oauth token, you could change that.
	gormDB.AutoMigrate(&auth_identity.AuthIdentity{})

	// Register Auth providers
	// Allow use username/password
	Auth.RegisterProvider(password.New(&password.Config{}))
}

func main() {
	mux := http.NewServeMux()

	// Mount Auth to Router
	mux.Handle("/auth/", Auth.NewServeMux())
	http.ListenAndServe(":8080", manager.SessionManager.Middleware(mux))
}
@lutfuahmet
Copy link

there is a bug about table name which prevent login,register ...

I have a server which have old version of qor, there is no error like this. but I tried to install new qor version on other server, I faced up same issue. I fixed issue via editing library files.

@xnamahx
Copy link

xnamahx commented Oct 3, 2018

I have the same. Solved with #15

@gstvg
Copy link

gstvg commented Oct 30, 2018

@jinzhu

@gstvg
Copy link

gstvg commented Nov 5, 2018

Hotfix:
type hotfixedAuthIdentity auth_identity.AuthIdentity
func(hotfixedAuthIdentity) TableName() string {return "basics"}

To use custom auth model without having to editing library files, name your user struct "Basics" or define a method TableName() string{return "basics"}, like above.
I dont tested #15 yet, but for me it seems like only works when you are using the default auth model: auth_identity.AuthIdentity()
The right fix would be "tx.Model(...).Where("provider = ? ", authInfo.Provider).Where("uid = ?", authInfo.UID)"

@sergolius
Copy link

sergolius commented Dec 29, 2019

Please see #12 (comment)

We faced this issue when upgraded GORM from v1.9.1 to v1.9.10. Downgrading back fixed the issue.

p.s. This issue appears because GORM v1.9.2 changed behaviour and lack of dependency management in QOR.
p.s.s. It's up to you to don't use defaults (handlers, renderers, etc).
Also there is not sense to modify original QOR files, because there is opportunity to override behaviour via config.

@sacarr
Copy link

sacarr commented Jan 2, 2020

I encountered similar problems with g01.13.4 darwin/amd64 while experimenting with the QOR Example server. I was seeing pq: missing FROM-clause entry for table "basics" in server logs. The messages were coming from

  • qor/auth/user_store.go (45)

  • qor/auth/providers/password/handler.go (27)

  • qor/auth/providers/password/confirm.go (81)

I resolved the problem by modifying each of the files. I changed the where() calls similarly in each file to this example from handlers.go line 27

if tx.Model(context.Auth.AuthIdentityModel).Where(authInfo).First(authIdentity).RecordNotFound()

to

if tx.Model(context.Auth.AuthIdentityModel).tx.Where("UID = ?", authInfo.UID).First(authIdentity).RecordNotFound()

@ghost
Copy link

ghost commented Feb 29, 2020

I created a fork of qor where I committed several fixes/pull requests to make it work. Available at, https://github.com/qorpress/qorpress-auth-example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants