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

[AuthController] Admin Interface shows password instead of email near "Logout" button #58

Closed
ndL-1990 opened this issue Jul 16, 2019 · 5 comments

Comments

@ndL-1990
Copy link
Contributor

ndL-1990 commented Jul 16, 2019

Hi,

I followed the steps to implement the AuthController to the admin interface using the guide.
All is working fine until I saw an error in display.

I did no changes at core files.

Expected Result

In front of the "Logout" button should be the email of currently logged in user.

Actual Result

In my case the password is shown instead ?!

Versions

  • Ubiquity framework 2.2.0 (Latest , Downloaded on 15/07/2019)

Kind regards,
ndL-1990

@ndL-1990
Copy link
Contributor Author

I was not able to fix this problem but I continued with the guide.
At the part where we can import the "messagerie.sql" database, I changed my database connection and tried again the login form based on the new database.
Here the problem seems to be solved but I can't understand why.

In my case I created a table called "User" with phpMyAdmin and used the web-tools to create the models.
But in '@framwork/auth/info.html' the '{{ connected | raw }}' variable will contain the password of the currently logged in user...

Maybe you can give me an explanation.

Thank you in advance.

Kind regards,
ndL-1990

@jcheron
Copy link
Contributor

jcheron commented Jul 16, 2019

@ndL-1990
Logically, the connected variable displayed in the view corresponds to a User instance.

To display this instance as a string, the __toString method of User is requested.

In my opinion, if the result displayed does not match the user's email, but his password, it is because the __toString method, probably generated automatically, should be modified accordingly.

You would have to put the code of your model User, in order to confirm or invalidate my hypothesis.

@ndL-1990
Copy link
Contributor Author

Hi @jcheron ,

Thank you for your help.
I tried to reproduce the error and it appeared again but this time I found the "bug".

I use a mySQL database where I created the "User" model:

User Class Diagram

After creating the model (model/User.php) from database using the UbiquityAdmin, I checked out the class in detail. Because of your answer I checked out the __toString method and you were right.

public function __toString(){ return $this->password; }

The function generated by the UbiquityAdmin returns the password instead of email but in the example with "messagerie" database, there it works.

Here is the User Class Diagram of messagerie database:
User Class Diagram Messagerie

I can't find a difference between them when they are created, only in phpMyAdmin I can see that I added a Unique to the email field because the queries work faster when important fields are indexed.

So it seems that we have to pay attention at the autogenerated models.

Thank you for your advise and keep on the good work. 👍

P.S: You can close the issue if you have no idea why the __toString() function is generated in a different way. It's not important to find the problem, it is just useful to mention it somewhere in the documentation. (Models and Orm - Generation Topic)

Kind regards,
ndL-1990

@jcheron
Copy link
Contributor

jcheron commented Jul 17, 2019

Hi @ndL-1990 ,
The choice of the field used in the __toString method is the responsibility of the Ubiquity\orm\creator\Model::getToStringField method.
This method chooses the last of the non-null, non-primary, simple type field.

	private function getToStringField(){
		$result=null;
		foreach ( $this->members as $member ) {
			if ($member->getDbType()!=="mixed" && $member->isNullable()!==true && !$member->isPrimary()) {
				$result=$member->getName();
			}
		}
		return $result;
	}

Which explains the difference between the two cases:
In your database, password was certainly the last non-null field.
In the case of the messagerie database, the password accepts null values, so the last non-null field is email.

This method makes a few arbitrary choices: it can certainly be improved.
For example, we could add to exclude certain fields according to their name (id, password, age, date*).

But it remains the developer's responsibility to then modify the automatically generated __toString.

@ndL-1990
Copy link
Contributor Author

Hi @jcheron ,

Thank you for the explanation.
This makes sense now after reading this function.

I'll try to modify my local framework to add this to avoid running again into this error.
When it works I let you know it, maybe you want to implement it in your version.
I didn't develop for a long time in PHP so I need to refresh my skills.

Kind regards,
ndL-1990

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

No branches or pull requests

2 participants