/** 
  * Edit a karma record
  */
 public function actionEdit()
 {
     $_POST = Yii::app()->input->stripClean($_POST);
     $id = (int) Yii::app()->request->getQuery('id');
     $user = User::model()->resetScope()->findByPk($id);
     $karma = Karma::model()->resetScope()->findByPk($id);
     if ($karma == null) {
         throw new CHttpException(404, "Karma record not found!");
     }
     // Build Form Definition
     $definition = array();
     $definition['elements'] = array();
     $groupModels = Group::model()->findAll(array('order' => 'name'));
     // Define Form Eleements
     $definition['elements']['Karma'] = array('type' => 'form', 'title' => 'Karma', 'elements' => array('name' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'points' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 10), 'description' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 1000)));
     // Get Form Definition
     $definition['buttons'] = array('save' => array('type' => 'submit', 'label' => 'Save', 'class' => 'btn btn-primary'), 'delete' => array('type' => 'submit', 'label' => 'Delete', 'class' => 'btn btn-danger'));
     $form = new HForm($definition);
     $form['Karma']->model = $karma;
     if ($form->submitted('save') && $form->validate()) {
         $this->forcePostRequest();
         if ($form['Karma']->model->save()) {
             $this->redirect($this->createUrl('edit', array('id' => $karma->id)));
             return;
         }
     }
     if ($form->submitted('delete')) {
         $this->redirect(Yii::app()->createUrl('karma/admin/delete', array('id' => $user->id)));
     }
     $this->render('edit', array('form' => $form));
 }
 /**
  * Edits a user
  *
  * @return type
  */
 public function actionEdit()
 {
     $_POST = Yii::app()->input->stripClean($_POST);
     $id = (int) Yii::app()->request->getQuery('id');
     $user = User::model()->resetScope()->findByPk($id);
     if ($user == null) {
         throw new CHttpException(404, Yii::t('AdminModule.controllers_UserController', 'User not found!'));
     }
     $user->scenario = 'adminEdit';
     $user->profile->scenario = 'adminEdit';
     $profile = $user->profile;
     // Build Form Definition
     $definition = array();
     $definition['elements'] = array();
     $groupModels = Group::model()->findAll(array('order' => 'name'));
     // Add User Form
     $definition['elements']['User'] = array('type' => 'form', 'title' => 'Account', 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'email' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 100), 'group_id' => array('type' => 'dropdownlist', 'class' => 'form-control', 'items' => CHtml::listData($groupModels, 'id', 'name')), 'super_admin' => array('type' => 'checkbox'), 'status' => array('type' => 'dropdownlist', 'class' => 'form-control', 'items' => array(User::STATUS_ENABLED => Yii::t('AdminModule.controllers_UserController', 'Enabled'), User::STATUS_DISABLED => Yii::t('AdminModule.controllers_UserController', 'Disabled'), User::STATUS_NEED_APPROVAL => Yii::t('AdminModule.controllers_UserController', 'Unapproved')))));
     // Add Profile Form
     $definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profile->getFormDefinition());
     // Get Form Definition
     $definition['buttons'] = array('save' => array('type' => 'submit', 'label' => Yii::t('AdminModule.controllers_UserController', 'Save'), 'class' => 'btn btn-primary'), 'become' => array('type' => 'submit', 'label' => Yii::t('AdminModule.controllers_UserController', 'Become this user'), 'class' => 'btn btn-danger'), 'delete' => array('type' => 'submit', 'label' => Yii::t('AdminModule.controllers_UserController', 'Delete'), 'class' => 'btn btn-danger'));
     $form = new HForm($definition);
     $form['User']->model = $user;
     $form['Profile']->model = $profile;
     if ($form->submitted('save') && $form->validate()) {
         $this->forcePostRequest();
         if ($form['User']->model->save()) {
             $form['Profile']->model->save();
             $this->redirect(Yii::app()->createUrl('admin/user'));
             return;
         }
     }
     // This feature is used primary for testing, maybe remove this in future
     if ($form->submitted('become')) {
         // Switch Identity
         Yii::import('application.modules_core.user.components.*');
         $newIdentity = new UserIdentity($user->username, '');
         $newIdentity->fakeAuthenticate();
         Yii::app()->user->login($newIdentity);
         $this->redirect(Yii::app()->createUrl('//'));
     }
     if ($form->submitted('delete')) {
         $this->redirect(Yii::app()->createUrl('admin/user/delete', array('id' => $user->id)));
     }
     $this->render('edit', array('form' => $form));
 }
 public function actionIndex()
 {
     $_POST = Yii::app()->input->stripClean($_POST);
     $assetPrefix = Yii::app()->assetManager->publish(dirname(__FILE__) . '/../resources', true, 0, defined('YII_DEBUG'));
     Yii::app()->clientScript->registerScriptFile($assetPrefix . '/md5.min.js');
     Yii::app()->clientScript->registerScriptFile($assetPrefix . '/jdenticon-1.3.0.min.js');
     $needApproval = HSetting::Get('needApproval', 'authentication_internal');
     if (!Yii::app()->user->isGuest) {
         throw new CHttpException(401, 'Your are already logged in! - Logout first!');
     }
     // Check for valid user invite
     $userInvite = UserInvite::model()->findByAttributes(array('token' => Yii::app()->request->getQuery('token')));
     if (!$userInvite) {
         throw new CHttpException(404, 'Token not found!');
     }
     if ($userInvite->language) {
         Yii::app()->setLanguage($userInvite->language);
     }
     $userModel = new User('register');
     $userModel->email = $userInvite->email;
     $userPasswordModel = new UserPassword('newPassword');
     $profileModel = $userModel->profile;
     $profileModel->scenario = 'register';
     ///////////////////////////////////////////////////////
     // Generate a random first name
     $firstNameOptions = explode("\n", HSetting::GetText('anonAccountsFirstNameOptions'));
     $randomFirstName = trim(ucfirst($firstNameOptions[array_rand($firstNameOptions)]));
     // Generate a random last name
     $lastNameOptions = explode("\n", HSetting::GetText('anonAccountsLastNameOptions'));
     $randomLastName = trim(ucfirst($lastNameOptions[array_rand($lastNameOptions)]));
     // Pre-set the random first and last name
     $profileModel->lastname = $randomLastName;
     $profileModel->firstname = $randomFirstName;
     // Make the username from the first and lastnames (only first 25 chars)
     $userModel->username = substr(str_replace(" ", "_", strtolower($profileModel->firstname . "_" . $profileModel->lastname)), 0, 25);
     ///////////////////////////////////////////////////////
     // Build Form Definition
     $definition = array();
     $definition['elements'] = array();
     $groupModels = Group::model()->findAll(array('order' => 'name'));
     $defaultUserGroup = HSetting::Get('defaultUserGroup', 'authentication_internal');
     $groupFieldType = "dropdownlist";
     if ($defaultUserGroup != "") {
         $groupFieldType = "hidden";
     } else {
         if (count($groupModels) == 1) {
             $groupFieldType = "hidden";
             $defaultUserGroup = $groupModels[0]->id;
         }
     }
     // Add Identicon Form
     $identiconForm = new IdenticonForm();
     $definition['elements']['IdenticonForm'] = array('type' => 'form', 'elements' => array('image' => array('type' => 'hidden', 'class' => 'form-control', 'id' => 'image')));
     // Add Profile Form
     $definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition());
     // Add User Form
     $definition['elements']['User'] = array('type' => 'form', 'title' => 'Password', 'elements' => array('username' => array('type' => 'hidden', 'class' => 'form-control', 'maxlength' => 25), 'email' => array('type' => 'hidden', 'class' => 'form-control'), 'group_id' => array('type' => $groupFieldType, 'class' => 'form-control', 'items' => CHtml::listData($groupModels, 'id', 'name'), 'value' => $defaultUserGroup)));
     // Add User Password Form
     $definition['elements']['UserPassword'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255)));
     // Get Form Definition
     $definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('UserModule.controllers_AuthController', 'Create account')));
     $form = new HForm($definition);
     $form['User']->model = $userModel;
     $form['UserPassword']->model = $userPasswordModel;
     $form['Profile']->model = $profileModel;
     $form['IdenticonForm']->model = $identiconForm;
     /// ----- WE DONT WANT TO SAVE YET -------
     if ($form->submitted('save') && $form->validate() && $identiconForm->validate()) {
         $this->forcePostRequest();
         // Registe User
         $form['User']->model->email = $userInvite->email;
         $form['User']->model->language = Yii::app()->getLanguage();
         if ($form['User']->model->save()) {
             // Save User Profile
             $form['Profile']->model->user_id = $form['User']->model->id;
             $form['Profile']->model->save();
             // Save User Password
             $form['UserPassword']->model->user_id = $form['User']->model->id;
             $form['UserPassword']->model->setPassword($form['UserPassword']->model->newPassword);
             $form['UserPassword']->model->save();
             // Autologin user
             if (!$needApproval) {
                 $user = $form['User']->model;
                 $newIdentity = new UserIdentity($user->username, '');
                 $newIdentity->fakeAuthenticate();
                 Yii::app()->user->login($newIdentity);
                 // Prepend Data URI scheme (stripped out for safety)
                 $identiconForm->image = str_replace("[removed]", "data:image/png;base64,", $identiconForm->image);
                 // Upload new Profile Picture for user
                 $this->uploadProfilePicture(Yii::app()->user->guid, $identiconForm->image);
                 // Redirect to dashboard
                 $this->redirect(array('//dashboard/dashboard'));
                 return;
             }
             $this->render('createAccount_success', array('form' => $form, 'needApproval' => $needApproval));
             return;
         }
     }
     $this->render('createAccount', array('form' => $form, 'identiconForm' => $identiconForm, 'needAproval' => $needApproval));
 }
Exemple #4
0
 /**
  * Edit Users Profile
  */
 public function actionEdit()
 {
     $_POST = Yii::app()->input->stripClean($_POST);
     $profile = Profile::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
     if ($profile == null) {
         $profile = new Profile();
         $profile->user_id = Yii::app()->user->id;
     }
     // Get Form Definition
     $definition = $profile->getFormDefinition();
     $definition['buttons'] = array('save' => array('type' => 'submit', 'label' => Yii::t('UserModule.controllers_AccountController', 'Save profile'), 'class' => 'btn btn-primary'));
     // Create Form
     $form = new HForm($definition, $profile);
     $form->showErrorSummary = true;
     if ($form->submitted('save') && $form->validate()) {
         $this->forcePostRequest();
         $profile->save();
         // set flash message
         Yii::app()->user->setFlash('data-saved', Yii::t('UserModule.controllers_AccountController', 'Saved'));
     }
     $this->render('edit', array('form' => $form));
 }
Exemple #5
0
 /**
  * Create an account 
  *
  * This action is called after e-mail validation.
  */
 public function actionCreateAccount()
 {
     $_POST = Yii::app()->input->stripClean($_POST);
     $needApproval = HSetting::Get('needApproval', 'authentication_internal');
     if (!Yii::app()->user->isGuest) {
         throw new CHttpException(401, 'Your are already logged in! - Logout first!');
     }
     // Check for valid user invite
     $userInvite = UserInvite::model()->findByAttributes(array('token' => Yii::app()->request->getQuery('token')));
     if (!$userInvite) {
         throw new CHttpException(404, 'Token not found!');
     }
     $userModel = new User('register');
     $userModel->email = $userInvite->email;
     $userPasswordModel = new UserPassword('newPassword');
     $profileModel = $userModel->profile;
     $profileModel->scenario = 'register';
     // Build Form Definition
     $definition = array();
     $definition['elements'] = array();
     $groupModels = Group::model()->findAll(array('order' => 'name'));
     $defaultUserGroup = HSetting::Get('defaultUserGroup', 'authentication_internal');
     $groupFieldType = "dropdownlist";
     if ($defaultUserGroup != "") {
         $groupFieldType = "hidden";
     } else {
         if (count($groupModels) == 1) {
             $groupFieldType = "hidden";
             $defaultUserGroup = $groupModels[0]->id;
         }
     }
     // Add User Form
     $definition['elements']['User'] = array('type' => 'form', 'title' => Yii::t('UserModule.controllers_AuthController', 'Account'), 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 32), 'group_id' => array('type' => $groupFieldType, 'class' => 'form-control', 'items' => CHtml::listData($groupModels, 'id', 'name'), 'value' => $defaultUserGroup)));
     // Add User Password Form
     $definition['elements']['UserPassword'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255)));
     // Add Profile Form
     $definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition());
     // Get Form Definition
     $definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('UserModule.controllers_AuthController', 'Create account')));
     $form = new HForm($definition);
     $form['User']->model = $userModel;
     $form['UserPassword']->model = $userPasswordModel;
     $form['Profile']->model = $profileModel;
     if ($form->submitted('save') && $form->validate()) {
         $this->forcePostRequest();
         // Registe User
         $form['User']->model->email = $userInvite->email;
         if ($form['User']->model->save()) {
             // Save User Profile
             $form['Profile']->model->user_id = $form['User']->model->id;
             $form['Profile']->model->save();
             // Save User Password
             $form['UserPassword']->model->user_id = $form['User']->model->id;
             $form['UserPassword']->model->setPassword($form['UserPassword']->model->newPassword);
             $form['UserPassword']->model->save();
             // Autologin user
             if (!$needApproval) {
                 $user = $form['User']->model;
                 $newIdentity = new UserIdentity($user->username, '');
                 $newIdentity->fakeAuthenticate();
                 Yii::app()->user->login($newIdentity);
                 $this->redirect(array('//dashboard/dashboard'));
                 return;
             }
             $this->render('createAccount_success', array('form' => $form, 'needApproval' => $needApproval));
             return;
         }
     }
     $this->render('createAccount', array('form' => $form, 'needAproval' => $needApproval));
 }
 public function actionEditField()
 {
     // XSS Protection
     $_POST = Yii::app()->input->stripClean($_POST);
     $id = (int) Yii::app()->request->getQuery('id');
     // Get Base Field
     $field = ProfileField::model()->findByPk($id);
     if ($field == null) {
         $field = new ProfileField();
     }
     // Get all Available Field Class Instances, also bind current profilefield to the type
     $fieldTypes = ProfileFieldType::getTypeInstances($field);
     // Build Form Definition
     $definition = array();
     #$definition['activeForm'] = array(
     #    'class' => 'CActiveForm',
     #    'enableAjaxValidation' => true,
     #    'id' => 'login-form',
     #);
     $definition['elements'] = array();
     // Add all sub forms
     $definition['elements'] = array_merge($definition['elements'], $field->getFormDefinition());
     foreach ($fieldTypes as $fieldType) {
         $definition['elements'] = array_merge($definition['elements'], $fieldType->getFormDefinition());
     }
     // Add Form Buttons
     $definition['buttons'] = array('save' => array('type' => 'submit', 'label' => Yii::t('AdminModule.controllers_UserprofileController', 'Save'), 'class' => 'btn btn-primary'));
     if (!$field->isNewRecord && !$field->is_system) {
         $definition['buttons']['delete'] = array('type' => 'submit', 'label' => Yii::t('AdminModule.controllers_UserprofileController', 'Delete'), 'class' => 'btn btn-danger pull-right');
     }
     // Create Form Instance
     $form = new HForm($definition);
     // Add used models to the CForm, so we can validate it
     $form['ProfileField']->model = $field;
     foreach ($fieldTypes as $fieldType) {
         $form[get_class($fieldType)]->model = $fieldType;
     }
     // Form Submitted?
     if ($form->submitted('save') && $form->validate()) {
         $this->forcePostRequest();
         // Use ProfileField Instance from Form with new Values
         $field = $form['ProfileField']->model;
         $fieldType = $form[$field->field_type_class]->model;
         $field->save();
         $fieldType->save();
         $this->redirect(Yii::app()->createUrl('//admin/userprofile'));
     }
     if ($form->submitted('delete')) {
         $this->forcePostRequest();
         $field->delete();
         $this->redirect(Yii::app()->createUrl('//admin/userprofile'));
     }
     $this->render('editField', array('form' => $form, 'field' => $field));
 }
Exemple #7
0
 /**
  * Create an account
  *
  * This action is called after e-mail validation.
  */
 public function actionCreateAccount()
 {
     $_POST = Yii::app()->input->stripClean($_POST);
     $check = UserInvite::model()->findByAttributes(array('token' => Yii::app()->request->getQuery('token')));
     if ($check != "") {
         $now = new DateTime(date("Y-m-d"));
         $diff = 0;
         $token = Yii::app()->request->getQuery('token');
         $timestamp = strtotime($check->created_at);
         $created_at = new DateTime(date("Y-m-d", $timestamp));
         $diff = date_diff($created_at, $now);
         $diff = (int) $diff->format('%a');
         if ($diff > 3) {
             $this->redirect(array("//user/auth/timeout", 'token' => $token, 'email' => $check->email));
         }
         if (Yii::app()->request->getQuery('mail') == "ok" && $check->flag == "R") {
             if (!Yii::app()->user->isGuest) {
                 Yii::app()->user->logout();
             }
             $verf = Yii::app()->db->createCommand()->delete('user_invite', 'token=:token', array(':token' => Yii::app()->request->getQuery('token')));
             $this->redirect(array('//user/auth/vsuccess'));
         }
     }
     $needApproval = HSetting::Get('needApproval', 'authentication_internal');
     if (!Yii::app()->user->isGuest) {
         throw new CHttpException(401, 'Your are already logged in! - Logout first!');
     }
     // Check for valid user invite
     $userInvite = UserInvite::model()->findByAttributes(array('token' => Yii::app()->request->getQuery('token')));
     if (!$userInvite) {
         throw new CHttpException(404, 'Token not found!');
     }
     if ($userInvite->language) {
         Yii::app()->setLanguage($userInvite->language);
     }
     $userModel = new User('register');
     $userModel->email = $userInvite->email;
     $userPasswordModel = new UserPassword('newPassword');
     $profileModel = $userModel->profile;
     $profileModel->scenario = 'register';
     // Build Form Definition
     $definition = array();
     $definition['elements'] = array();
     $groupModels = Group::model()->findAll(array('order' => 'name DESC'));
     $defaultUserGroup = HSetting::Get('defaultUserGroup', 'authentication_internal');
     $groupFieldType = "dropdownlist";
     if ($defaultUserGroup != "") {
         $groupFieldType = "hidden";
     } else {
         if (count($groupModels) == 1) {
             $groupFieldType = "hidden";
             $defaultUserGroup = $groupModels[0]->id;
         }
     }
     // Add User Form
     $definition['elements']['User'] = array('type' => 'form', 'title' => Yii::t('UserModule.controllers_AuthController', 'Account'), 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'group_id' => array('type' => $groupFieldType, 'class' => 'form-control', 'items' => CHtml::listData($groupModels, 'id', 'name'), 'value' => $defaultUserGroup)));
     // Add User Password Form
     $definition['elements']['UserPassword'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255)));
     // Add Profile Form
     $definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition());
     // Get Form Definition
     $definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('UserModule.controllers_AuthController', 'Create account')));
     $form = new HForm($definition);
     $form['User']->model = $userModel;
     $form['UserPassword']->model = $userPasswordModel;
     $form['Profile']->model = $profileModel;
     if ($form->submitted('save') && $form->validate()) {
         $this->forcePostRequest();
         // Registe User
         $form['User']->model->email = $userInvite->email;
         $form['User']->model->language = Yii::app()->getLanguage();
         if ($form['User']->model->save()) {
             // Save User Profile
             $form['Profile']->model->user_id = $form['User']->model->id;
             $form['Profile']->model->save();
             // Save User Password
             $form['UserPassword']->model->user_id = $form['User']->model->id;
             $form['UserPassword']->model->setPassword($form['UserPassword']->model->newPassword);
             $form['UserPassword']->model->save();
             if (Yii::app()->request->getQuery('mail') == NULL) {
                 $flag = Yii::app()->db->createCommand()->update('user_invite', array('flag' => 'R'), 'token=:token', array(':token' => Yii::app()->request->getQuery('token')));
             } else {
                 $flag = Yii::app()->db->createCommand()->delete('user_invite', 'token=:token', array(':token' => Yii::app()->request->getQuery('token')));
             }
             // Autologin user
             if (!$needApproval) {
                 $user = $form['User']->model;
                 $newIdentity = new UserIdentity($user->username, '');
                 $newIdentity->fakeAuthenticate();
                 Yii::app()->user->login($newIdentity);
                 $this->redirect(array('//user/profile', 'uguid' => Yii::app()->user->guid));
                 return;
             }
             $this->render('createAccount_success', array('form' => $form, 'needApproval' => $needApproval));
             return;
         }
     }
     $this->render('createAccount', array('form' => $form, 'needAproval' => $needApproval));
 }
 /**
  * Setup Administrative User
  *
  * This should be the last step, before the user is created also the
  * application secret will created.
  */
 public function actionAdmin()
 {
     Yii::import('installer.forms.*');
     $userModel = new User('register');
     $userPasswordModel = new UserPassword('newPassword');
     $profileModel = $userModel->profile;
     $profileModel->scenario = 'register';
     // Build Form Definition
     $definition = array();
     $definition['elements'] = array();
     // Add User Form
     $definition['elements']['User'] = array('type' => 'form', 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'email' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 100)));
     // Add User Password Form
     $definition['elements']['UserPassword'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255)));
     // Add Profile Form
     $definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition());
     // Get Form Definition
     $definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('InstallerModule.base', 'Create Admin Account')));
     $form = new HForm($definition);
     $form['User']->model = $userModel;
     $form['User']->model->group_id = 1;
     $form['UserPassword']->model = $userPasswordModel;
     $form['Profile']->model = $profileModel;
     if (isset($_POST['Profile'])) {
         $_POST['Profile'] = Yii::app()->input->stripClean($_POST['Profile']);
     }
     if (isset($_GET['Profile'])) {
         $_GET['Profile'] = Yii::app()->input->stripClean($_GET['Profile']);
     }
     if ($form->submitted('save') && $form->validate()) {
         $this->forcePostRequest();
         if (HSetting::Get('secret') == "") {
             HSetting::Set('secret', UUID::v4());
         }
         $form['User']->model->status = User::STATUS_ENABLED;
         $form['User']->model->super_admin = true;
         $form['User']->model->language = '';
         $form['User']->model->last_activity_email = new CDbExpression('NOW()');
         $form['User']->model->save();
         $form['Profile']->model->user_id = $form['User']->model->id;
         $form['Profile']->model->title = "System Administration";
         $form['Profile']->model->save();
         // Save User Password
         $form['UserPassword']->model->user_id = $form['User']->model->id;
         $form['UserPassword']->model->setPassword($form['UserPassword']->model->newPassword);
         $form['UserPassword']->model->save();
         $userId = $form['User']->model->id;
         // Switch Identity
         Yii::import('application.modules_core.user.components.*');
         $newIdentity = new UserIdentity($form['User']->model->username, '');
         $newIdentity->fakeAuthenticate();
         Yii::app()->user->login($newIdentity);
         // Create Welcome Space
         $space = new Space();
         $space->name = 'Welcome Space';
         $space->description = 'Your first sample space to discover the platform.';
         $space->join_policy = Space::JOIN_POLICY_FREE;
         $space->visibility = Space::VISIBILITY_ALL;
         $space->created_by = $userId;
         $space->auto_add_new_members = 1;
         $space->save();
         $profileImage = new ProfileImage($space->guid);
         $profileImage->setNew($this->getModule()->getPath() . DIRECTORY_SEPARATOR . "resources" . DIRECTORY_SEPARATOR . 'welcome_space.jpg');
         // Add Some Post to the Space
         $post = new Post();
         $post->message = "Yay! I've just installed HumHub :-)";
         $post->content->container = $space;
         $post->content->visibility = Content::VISIBILITY_PUBLIC;
         $post->save();
         $this->redirect($this->createUrl('finished'));
     }
     $this->render('admin', array('form' => $form));
 }
 public function actionAdd()
 {
     $_POST = Yii::app()->input->stripClean($_POST);
     $userModel = new User('register');
     $userPasswordModel = new UserPassword('newPassword');
     $profileModel = $userModel->profile;
     $profileModel->scenario = 'register';
     // Build Form Definition
     $definition = array();
     $definition['elements'] = array();
     $groupModels = Group::model()->findAll(array('order' => 'name'));
     $defaultUserGroup = HSetting::Get('defaultUserGroup', 'authentication_internal');
     $groupFieldType = "dropdownlist";
     if ($defaultUserGroup != "") {
         $groupFieldType = "hidden";
     } else {
         if (count($groupModels) == 1) {
             $groupFieldType = "hidden";
             $defaultUserGroup = $groupModels[0]->id;
         }
     }
     // Add User Form
     $definition['elements']['User'] = array('type' => 'form', 'title' => Yii::t('UserModule.controllers_AuthController', 'Account'), 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'email' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 100), 'group_id' => array('type' => $groupFieldType, 'class' => 'form-control', 'items' => CHtml::listData($groupModels, 'id', 'name'), 'value' => $defaultUserGroup)));
     // Add User Password Form
     $definition['elements']['UserPassword'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255)));
     // Add Profile Form
     $definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition());
     // Get Form Definition
     $definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('UserModule.controllers_AuthController', 'Create account')));
     $form = new HForm($definition);
     $form['User']->model = $userModel;
     $form['UserPassword']->model = $userPasswordModel;
     $form['Profile']->model = $profileModel;
     if ($form->submitted('save') && $form->validate()) {
         $this->forcePostRequest();
         $form['User']->model->status = User::STATUS_ENABLED;
         if ($form['User']->model->save()) {
             // Save User Profile
             $form['Profile']->model->user_id = $form['User']->model->id;
             $form['Profile']->model->save();
             // Save User Password
             $form['UserPassword']->model->user_id = $form['User']->model->id;
             $form['UserPassword']->model->setPassword($form['UserPassword']->model->newPassword);
             $form['UserPassword']->model->save();
             $this->redirect($this->createUrl('index'));
             return;
         }
     }
     $this->render('add', array('form' => $form));
 }