qor-example icon indicating copy to clipboard operation
qor-example copied to clipboard

qor-example registration bug on fresh new installation (mariadb)

Open manuelbcd opened this issue 6 years ago • 11 comments

Fresh new qor-example installation

MariaDB: 10.3.10 O.S: Windows 10 x64 Go version: 1.9.2

Just installed qor-example to play around. After installation I can load the page on port 7000 but when I try to register a new user the UI launches this error "Invalid account". qor logs: (Error 1054: Unknown column 'basics.provider' in 'where clause') [2018-10-27 20:24:32] 2018/10/27 20:24:32 "POST http://localhost:7000/auth/password/register HTTP/1.1" from [::1]:61478 - 200 8951B in 8.0356ms

Could it be a bug related with mariadb?

Thank you

Best regards.

manuelbcd avatar Oct 27 '18 18:10 manuelbcd

For a quick fix,

Change DefaultAuthorizeHandler line 27 on /go/src/github.com/qor/auth/providers/password/handlers.go with that:

if tx.Model(context.Auth.AuthIdentityModel).Where(
		map[string]interface{}{
			"provider": authInfo.Provider,
			"uid":      authInfo.UID,
		}).Scan(&authInfo).RecordNotFound() {
		return nil, auth.ErrInvalidAccount
	}

turgayozgur avatar Oct 28 '18 09:10 turgayozgur

Thank you @turgayozgur but after applying this "patch", and "go clean"... re-launched and found the same error.

(Error 1054: Unknown column 'basics.provider' in 'where clause') [2018-10-28 12:33:32] 2018/10/28 12:33:32 "POST http://localhost:7000/auth/password/register HTTP/1.1" from 127.0.0.1:49675 - 200 8951B in 6.9773ms

manuelbcd avatar Oct 28 '18 11:10 manuelbcd

Ok. this workaround works for login page. You can do it the same method for register handle. Just change the Where clause of register handle from Where(authInfo) to

.Where(
	map[string]interface{}{
		"provider": authInfo.Provider,
		"uid":      authInfo.UID,
	})
`
``

turgayozgur avatar Oct 28 '18 11:10 turgayozgur

sorry @turgayozgur I'm not sure about what are you proposing this time. The usage of this map is not the same thing that we tried just before? Thank you and sorry, I'm just beggining with go language.

manuelbcd avatar Oct 28 '18 11:10 manuelbcd

Like I said before for line 27, same for line ~73. /go/src/github.com/qor/auth/providers/password/handlers.go line ~73 from

if !tx.Model(context.Auth.AuthIdentityModel).Where(authInfo).Scan(&authInfo).RecordNotFound() {
		return nil, auth.ErrInvalidAccount
	}

to

if tx.Model(context.Auth.AuthIdentityModel).Where(
		map[string]interface{}{
			"provider": authInfo.Provider,
			"uid":      authInfo.UID,
		}).Scan(&authInfo).RecordNotFound() {
		return nil, auth.ErrInvalidAccount
	}

turgayozgur avatar Oct 28 '18 11:10 turgayozgur

Hi @turgayozgur thank you for the try.

The log error gone but the UI error remains. "Invalid account" when triying to sign up.

log: 2018/10/28 18:49:01 "POST http://localhost:7000/auth/password/register HTTP/1.1" from [::1]:49357 - 200 8951B in 7.9805ms 2018/10/28 18:49:06 "POST http://localhost:7000/auth/password/register HTTP/1.1" from [::1]:49357 - 200 8951B in 10.003ms

manuelbcd avatar Oct 28 '18 17:10 manuelbcd

Hi @manuelbcd I checked again and make some fixes. Here is the last password/handlers.go

https://gist.github.com/turgayozgur/c2e7449d5e2e0caeb9961760757eb7de

turgayozgur avatar Oct 29 '18 09:10 turgayozgur

There are a few places in the auth/providers/password/*.go that incorrectly use auth_identity.Basic instead of auth_identity.AuthIdentity. I was able to get the demo to work by changing Basic to AuthIdentity. Might want to review all uses of the auth_identity.Basic type.

Without that change the confirmation link will corrupt the auth_identities table by setting the uid field of all records to the confirmed email address.

Neopallium avatar Nov 17 '18 10:11 Neopallium

+1

raulfortes avatar Jan 18 '19 12:01 raulfortes

Thanks @Neopallium , I change auth/providers/password/handlers

var authInfo auth_identity.AuthIdentity

It works~

jianfengye avatar Feb 18 '19 00:02 jianfengye

Please see https://github.com/qor/auth/issues/12#issuecomment-524820403

sergolius avatar Dec 29 '19 16:12 sergolius