I want a new user to create an account and go through this wizard before he can login.
See the block below:
Building Manager -> Manager completed -> Building -> Login
Getting to the application, he creates a building account, and he gets a user_id
7025
public function actionManager()
{
$this->layout = 'welcome-layout';
$model = new BuildingManager();
$user = new User();
$auth_assign = new AuthAssignment();
if (Yii::$app->request->isAjax) {
if($model->load(Yii::$app->request->post())) {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
}
$manager_uniq_no = \app\modules\consumers\models\BuildingManager::find()->max('manager_unique_id');
$uniq_id = NULL;
if(empty($manager_uniq_no)) {
$uniq_id = $model->manager_unique_id = 1;
}
else {
$chk_id = BuildingManager::find()->where(['manager_unique_id' => $manager_uniq_no])->exists();
if($chk_id)
$uniq_id = $manager_uniq_no + 1;
else
$uniq_id = $manager_uniq_no;
}
//$manager_rand=rand(0,9999);
if($model->load(Yii::$app->request->post()))
{
$org_manager_prefix = "MANAGER";
$login_id = $org_manager_prefix.$uniq_id;
$model->attributes = $_POST['BuildingManager'];
if(empty($_POST['BuildingManager']['manager_email']))
$model->manager_email = NULL;
else
$model->manager_email = strtolower($_POST['BuildingManager']['manager_email']);
$user->user_login_id = $login_id;
//$user->user_password = md5($user->user_login_id.$user->user_login_id);
$user->user_password = md5($user->user_login_id.$user->user_login_id);
$user->user_type = "M";
$user->created_by = Yii::$app->getid->getId();
$user->created_at = new \yii\db\Expression('NOW()');
$user->save(false);
$model->manager_user_id = $user->user_id;
$model->created_by = Yii::$app->getid->getId();
$model->created_at = new \yii\db\Expression('NOW()');
$model->save(false);
$auth_assign->item_name = 'Manager';
$auth_assign->user_id = $user->user_id;
$auth_assign->created_at = date_format(date_create(),'U');
$auth_assign->save(false);
if ($model->save()) {
return $this->redirect(['manager-completed', 'id'=>$model->manager_id]);
}
else
return $this->render('manager', ['model' => $model, 'uniq_id'=>$uniq_id]);
} else {
return $this->render('manager', ['model' => $model, 'uniq_id'=>$uniq_id
]);
}
}
step 2 : manager completed
public function actionManagerCompleted()
{
$this->layout = 'welcome-layout';
// $model = $this->findModel($id);
if(isset($_POST['building-button']))
{
$managerid = Yii::app()->getRequest()->getQuery('id'); //x=2 again
//$applicant=CPreApplicant::model()->findByPK($id);
//$this->render('studentpreapply2',array('applicant'=>$applicant));
// $this->render('studentaccountdetail',array(
// 'model'=>$model,'applicant'=>$applicant));
//return $this->redirect(['manager-completed', 'id'=>$model->manager_id]);
$manager=BuildingManager::model()->find('manager_id=:id',array(':id'=>$managerid));
// return $this->redirect(array('building'));
return $this->redirect(['building', 'id'=>$manager->manager_id]);
}
if(Yii::$app->request->post()) {
return $this->redirect(['site/login']);
//return $this->redirect(['building', 'id'=>$model->manager_id]);
}
return $this->render('manager-completed', [
]);
}
Step 2 should in user_id and manager_id from step1
Step3: Building
public function actionBuilding()
{
$this->layout = 'welcome-layout';
$model = new Building();
$managerid = Yii::app()->getRequest()->getQuery('id');
$manager=BuildingManager::model()->find('manager_id=:id',array(':id'=>$managerid));
// $model->updated_by = Yii::$app->getid->getId();
// $model->updated_at= new \yii\db\Expression('NOW()');
if ($model->load(Yii::$app->request->post())) //&& $model->save()) {
{
// $model->updated_by = Yii::$app->getid->getId();
// $model->updated_at= new \yii\db\Expression('NOW()');
$i_plan=new InspectionPlan();
$i_plan->building_id=$model->building_id;
if(!$model->last_inspection)
$i_plan->last_inspection=date('Y-m-d');
else
$i_plan->last_inspection=date('Y-m-d', strtotime($model->last_inspection));
if((!$model->last_inspection))
$i_plan->next_inspection=date('Y-m-d');
else{
$t1=strtotime($model->last_inspection);
$t2=strtotime('-3 years');
if($t1<$t2)
$i_plan->next_inspection=date('Y-m-d');
else
$i_plan->next_inspection=date('Y-m-d', strtotime('+3 years',strtotime($i_plan->last_inspection)));
}
// die(var_dump($i_plan->attributes));
$i_plan->save();
// return $this->redirect(['view', 'id' => $model->building_id]);
return $this->redirect(['site/login']);
} else {
return $this->render('building', [
'model' => $model,
]);
}
}
Step 3 should should inherit the user_id and manager_id from step 2, and save the manager_id in its table
The the user can go to step 4 to login
Please help.