2
votes

Hello PHP and Yii friends,

I think this is not a true chalenge for someone with more experience with Yii. Anny reference or general idea will mean a lot as i'm pretty new to Yii. Thanks in advance for even a view!

Scenario:

Yii web application and the problem of custom scenario of user validation based not on the existence of the user in the local database but the external site db, it's own validation and well covered public accessible API.

I consider creating the bridge module between the Yii application and external API that will provide with the data that will be used to create specific Yii models and views for member users.

However to make this models and views public only to the user/member i must create a custom validation part wit the data i get as a return type of external API validation function with a help of cUrl.

Example data i get as a result from external API user validation:

[result] => success
[userid] => 2
[passwordhash] => 04462efbd433dbb66ca25b67145a1848ed9e1044

Question:
How can i customize Yii user validation based on the values i get in the array above?

1
create a model class with method findByPk to retrieve the data. Then use the model in UserIdentity like any other db model. - Imre L
@Imre Yeah,thanks Imre, so to create a custom model which will not use db connection, but the connection with the external API and fill its fields with retrieved data and use that data for validation? - maljukan

1 Answers

1
votes

You'll also want to validate the user existence after signup, e.g. during each login. So you should:

  1. Write an application component that calls the remote API and determines if the user is valid.
  2. Write a custom validator class that calls this component to do the validation. See documentation, you want to write your own class extending CValidator.
  3. Write additional code to call the validation component after the user logs in.