public function actionStep2()
 {
     $model = new Step2();
     $form = new Form('install.Step2', $model);
     $this->performAjaxValidation($model);
     if ($form->submitted() && $model->validate()) {
         $configs = CMap::mergeArray(Yii::app()->user->getState('install_configs'), $model->getConfigs());
         Yii::app()->user->setState('install_configs', $configs);
         $step1 = Step1::loadFromSession();
         Yii::app()->setComponent('db', $step1->createDbConnection());
         //install modules
         Yii::app()->setModules($model->modules);
         //$step1->deleteDisableModules();
         //migrate
         Yii::app()->getModule('users');
         Yii::app()->executor->migrate('up --module=main');
         foreach (Yii::app()->getModules() as $id => $data) {
             if ($id == 'main') {
                 continue;
             }
             Yii::app()->getModule($id);
             if (is_dir(Yii::getPathOfAlias($id . '.migrations'))) {
                 $response = Yii::app()->executor->migrate('up --module=' . $id);
                 if (stripos($response, 'successfully') === false) {
                     echo $response;
                     die;
                 }
             }
         }
         //create admin user
         $user = new User();
         list($user->name) = explode('@', $model->admin_email);
         $user->name = ucfirst($user->name);
         $user->email = $model->admin_email;
         $user->password = UserIdentity::crypt($model->admin_pass);
         $user->status = User::STATUS_ACTIVE;
         $user->save(false);
         //set admin
         $auth = Yii::app()->authManager;
         $auth->clearAll();
         $auth->createRole('Admin');
         $auth->assign('Admin', $user->id);
         //commands collect
         Yii::app()->executor->addCommandsFromModules(Yii::app()->getModules());
         //run install method
         foreach (Yii::app()->getModules() as $id => $conf) {
             @mkdir(Yii::getPathOfAlias('webroot.upload.' . $id), 0755, true);
             Yii::app()->getModule($id)->install();
         }
         $model->saveInSession();
         //install base modules
         $this->redirect('/install.php?r=/install/install/step3');
     }
     $this->render('step2', array('form' => $form));
 }
Beispiel #2
0
 protected function afterValidate()
 {
     if ($this->isNewRecord) {
         $this->password = UserIdentity::crypt($this->password);
     } else {
         if ($this->newPassword) {
             $this->password = UserIdentity::crypt($this->newPassword);
         }
     }
     return parent::afterValidate();
 }
 public function up()
 {
     $user = new User();
     $user->name = 'admin';
     $user->email = '*****@*****.**';
     $user->password = UserIdentity::crypt('123456');
     $user->status = 'active';
     $user->birthdate = '2011-01-01';
     $user->gender = User::GENDER_MAN;
     $user->save();
 }
 public function up()
 {
     $this->createTable('user', array('id' => 'pk', 'fname' => 'string', 'lname' => 'string', 'username' => 'string', 'password' => 'string', 'pw_reset_token' => 'string', 'email' => 'string', 'role' => 'string', 'is_deleted' => 'int', 'create_date' => 'datetime'), 'ENGINE=InnoDB');
     $this->createTable('cookie', array('id' => 'pk', 'username' => 'string', 'token' => 'string', 'create_date' => 'datetime'), 'ENGINE=InnoDB');
     $this->createTable('event', array('id' => 'pk', 'user_id' => 'int', 'place' => 'string', 'start' => 'datetime', 'end' => 'datetime', 'comment' => 'text', 'create_date' => 'datetime'), 'ENGINE=InnoDB');
     //---Add users
     $password = UserIdentity::crypt('1111');
     // => md5('1111'.UserIdentity::$salt);
     $this->insert('user', array('fname' => 'Admin', 'lname' => 'Adminovich', 'username' => 'admin', 'password' => $password, 'pw_reset_token' => '', 'email' => '*****@*****.**', 'role' => 'admin', 'is_deleted' => 0, 'create_date' => new CDbExpression('NOW()')));
     $adminId = Yii::app()->db->getLastInsertId();
     $this->insert('user', array('fname' => 'User', 'lname' => 'Userovich', 'username' => 'user', 'password' => $password, 'pw_reset_token' => '', 'email' => '*****@*****.**', 'role' => 'user', 'is_deleted' => 0, 'create_date' => new CDbExpression('NOW()')));
     $userId = Yii::app()->db->getLastInsertId();
     //--- Add base event
     $this->insert('event', array('user_id' => $userId, 'place' => 'Italia', 'start' => new CDbExpression('NOW() - INTERVAL 1 DAY'), 'end' => new CDbExpression('NOW() + INTERVAL 2 DAY'), 'comment' => 'Unitary state', 'create_date' => new CDbExpression('NOW()')));
     $this->insert('event', array('user_id' => $userId, 'place' => 'Francia', 'start' => new CDbExpression('NOW() + INTERVAL 3 DAY'), 'end' => new CDbExpression('NOW() + INTERVAL 7 DAY'), 'comment' => 'I want romance!', 'create_date' => new CDbExpression('NOW()')));
     $this->insert('event', array('user_id' => $userId, 'place' => 'Mexico', 'start' => new CDbExpression('NOW()  + INTERVAL 10 DAY'), 'end' => new CDbExpression('NOW() + INTERVAL 15 DAY'), 'comment' => 'I <3 TEQUILA', 'create_date' => new CDbExpression('NOW()')));
     $this->insert('event', array('user_id' => $userId, 'place' => 'Ukraine', 'start' => new CDbExpression('NOW() - INTERVAL 20 DAY'), 'end' => new CDbExpression('NOW() - INTERVAL 15 DAY'), 'comment' => 'Oh... We want the European Union...', 'create_date' => new CDbExpression('NOW()')));
     $this->insert('event', array('user_id' => $userId, 'place' => 'USA', 'start' => new CDbExpression('NOW()'), 'end' => new CDbExpression('NOW() + INTERVAL 10 DAY'), 'comment' => 'O say, can you see, by the dawn’s early light...', 'create_date' => new CDbExpression('NOW()')));
     $this->insert('event', array('user_id' => $userId, 'place' => 'Russia', 'start' => new CDbExpression('NOW() - INTERVAL 7 DAY'), 'end' => new CDbExpression('NOW() - INTERVAL 3 DAY'), 'comment' => 'I would drink vodka with a bear on unicycle', 'create_date' => new CDbExpression('NOW()')));
 }
Beispiel #5
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->isNewRecord) {
             if (UserIdentity::isCrypted($this->password)) {
                 $this->password = UserIdentity::crypt($this->password);
             }
         }
         return true;
     }
     return false;
 }