Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Yii2-user for user registration in Yii2 Rest Api

Tags:

rest

php

yii2

I want to implement user registration/login process in my project in which i have web client application made in angular and mobile client is on android.

I am using REST for client/server communication. I have installed yii2-user in my yii developed back-end. What I want is to create a rest api in such a way that each of my client application use yii2-user for user registration and login process. So that in client if user want to register the request will be handled by yii-2 user module? Any suggestion that how can I achieve this? Or is there any better way to make REST api for registration and authentication in Yii2?

like image 372
james Avatar asked Sep 09 '15 12:09

james


1 Answers

Use the yii2-user controller e.g dektrium "UserController" and extend it from \yii\rest\ActiveController then you can specify the model class in the UserController as

public $modelClass = 'dektrium\user\models\User';

In the rest post request use some parameter to give json response for rest request. i.e

register-form[username]=YOURUSERNAME&register-form[password]=YOURPASS&register-form[email][email protected]&someparam=true

In the controller

$model->load(\Yii::$app->request->post()) && $model->register()

will successfully register the user.

You can extend the idea from here. cheers :)

like image 143
Fareed Ud Din Avatar answered Oct 21 '22 16:10

Fareed Ud Din