/**
  * Creates a new Profile model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Profile(['scenario' => 'register']);
     $module = ProfileModule::getInstance();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //set uploaded file to Model Attribute
         $model->avatarFile = UploadedFile::getInstance($model, 'avatarFile');
         $this->uploadAvatar($model);
         //set default user role
         $auth = Yii::$app->authManager;
         $defaultRole = $auth->getRole($module->defaultRole);
         if ($defaultRole !== null) {
             //role exists
             $auth->assign($defaultRole, $model->id);
         }
         //if activate is false in config activate user manually else send mail with activation link
         if (!$module->isActivation) {
             $model->setAttribute('isactive', 1);
             $model->save();
         } else {
             $model->scenario = 'recover';
             $model->save(false);
             //send mail
             $url = Yii::$app->urlManager->createAbsoluteUrl(['/profile/account/activate', 'key' => base64_encode($model->recoverycode)], 'http');
             $url = Html::a(Yii::t('app', 'Here'), $url);
             $subject = Yii::t('app', 'Activating Account for {email}', ['email' => $model->email]);
             $msg = Yii::t('app', 'Dear {name}, Thank you for registering with us. Please click {link} to Activate your Account. Link expires in 24 Hours', ['name' => $model->fname, 'link' => $url]);
             try {
                 $this->sendMail($model->email, $subject, $msg);
             } catch (\Exception $e) {
                 throw new \yii\web\HttpException(500, 'Could Not Send Activation Mail. Please go to login and Resend the code again');
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }