/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionSelect_user() { $model = new User(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $dua = $model->password; $model->saltPassword = $model->generateSalt(); $model->password = $model->hashPassword($dua, $model->saltPassword); //$model->level_id=2; $model->isActive = 0; $sss; if (strlen(trim(CUploadedFile::getInstance($model, 'avatar'))) > 0) { $sss = CUploadedFile::getInstance($model, 'avatar'); $model->avatar = $model->username . '.' . $sss->extensionName; } if ($model->save()) { if (strlen(trim($model->avatar)) > 0) { $sss->saveAs(Yii::app()->basePath . '/../avatar/' . $model->avatar); } // $model2=new LoginForm; // $model2->username=$model->username; // $model2->password=$dua; // if($model2->login()) $this->redirect(array('select_user')); } } $this->render('select_user', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new User(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $acak = $model->generateSalt(); $model->password = $model->hashPassword($_POST['User']['password'], $acak); if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new User(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['User'])) { //Generating The Salt and hasing the password $salt = $model->generateSalt(); $_POST['User']['password'] = $model->hashPassword($_POST['User']['password'], $salt); $_POST['User']['salt'] = $salt; $model->attributes = $_POST['User']; if ($model->save()) { $this->redirect(array('/rights')); } } $this->render('create', array('model' => $model)); }
public function actionSetup() { $this->layout = 'no_layout'; $model = new User(); if (isset($_POST['User'])) { //Generating The Salt and hasing the password $salt = $model->generateSalt(); $_POST['User']['password'] = $model->hashPassword($_POST['User']['password'], $salt); $_POST['User']['salt'] = $salt; $model->attributes = $_POST['User']; if ($model->save()) { $model = new Configurations(); $logo = new Logo(); $posts_1 = Configurations::model()->findByAttributes(array('id' => 1)); $posts_1->config_value = $_POST['collegename']; $posts_1->save(); $posts_2 = Configurations::model()->findByAttributes(array('id' => 2)); $posts_2->config_value = $_POST['address']; $posts_2->save(); $posts_3 = Configurations::model()->findByAttributes(array('id' => 3)); $posts_3->config_value = $_POST['phone']; $posts_3->save(); $posts_4 = Configurations::model()->findByAttributes(array('id' => 4)); $posts_4->config_value = $_POST['attentance']; $posts_4->save(); $posts_5 = Configurations::model()->findByAttributes(array('id' => 13)); $posts_5->config_value = $_POST['startyear']; $posts_5->save(); $posts_6 = Configurations::model()->findByAttributes(array('id' => 14)); $posts_6->config_value = $_POST['endyear']; $posts_6->save(); $posts_8 = Configurations::model()->findByAttributes(array('id' => 5)); $posts_8->config_value = $_POST['currency']; $posts_8->save(); $posts_9 = Configurations::model()->findByAttributes(array('id' => 6)); $posts_9->config_value = $_POST['language']; $posts_9->save(); /*$posts_10=Configurations::model()->findByAttributes(array('id'=>6)); $posts_10->config_value = $_POST['logo']; $posts_10->save();*/ if ($file = CUploadedFile::getInstance($logo, 'uploadedFile')) { $logo = new Logo(); $logo->photo_file_name = $file->name; $logo->photo_content_type = $file->type; $logo->photo_file_size = $file->size; $logo->photo_data = file_get_contents($file->tempName); if (!is_dir('uploadedfiles/')) { mkdir('uploadedfiles/'); } if (!is_dir('uploadedfiles/school_logo/')) { mkdir('uploadedfiles/school_logo/'); } move_uploaded_file($file->tempName, 'uploadedfiles/school_logo/' . $file->name); $logo->save(); $posts_10 = Configurations::model()->findByAttributes(array('id' => 18)); $posts_10->config_value = Yii::app()->db->getLastInsertId(); $posts_10->save(); } if (isset($_POST['dateformat']) && isset($_POST['timeformat']) && isset($_POST['timezone']) && isset($_POST['language'])) { $settings = UserSettings::model()->findByAttributes(array('user_id' => Yii::app()->user->id)); $date = ''; if (settings != NULL) { $settings->user_id = Yii::app()->user->id; $settings->dateformat = $_POST['dateformat']; if ($_POST['dateformat'] == 'm/d/yy') { $settings->displaydate = 'm/d/Y'; } else { if ($_POST['dateformat'] == 'M d.yy') { $settings->displaydate = 'M d.Y'; } else { if ($_POST['dateformat'] == 'D, M d.yy') { $settings->displaydate = 'D, M d.Y'; } else { if ($_POST['dateformat'] == 'd M yy') { $settings->displaydate = 'd M Y'; } else { if ($_POST['dateformat'] == 'yy/m/d') { $settings->displaydate = 'Y/m/d'; } } } } } $settings->timeformat = $_POST['timeformat']; $settings->timezone = $_POST['timezone']; $settings->language = $_POST['language']; } else { $settings->user_id = Yii::app()->user->id; $settings->dateformat = $_POST['dateformat']; if ($_POST['dateformat'] == 'm/d/yy') { $settings->displaydate = 'm/d/Y'; } else { if ($_POST['dateformat'] == 'M d.yy') { $settings->displaydate = 'M d.Y'; } else { if ($_POST['dateformat'] == 'D, M d.yy') { $settings->displaydate = 'D, M d.Y'; } else { if ($_POST['dateformat'] == 'd M yy') { $settings->displaydate = 'd M Y'; } else { if ($_POST['dateformat'] == 'yy/m/d') { $settings->displaydate = 'Y/m/d'; } } } } } $settings->timeformat = $_POST['timeformat']; $settings->timezone = $_POST['timezone']; $settings->language = $_POST['language']; } $settings->save(); } $posts_11 = Configurations::model()->findByAttributes(array('id' => 12)); $posts_11->config_value = $_POST['network']; $posts_11->save(); $posts_12 = Configurations::model()->findByAttributes(array('id' => 7)); $posts_12->config_value = $_POST['admission_number']; $posts_12->save(); $posts_13 = Configurations::model()->findByAttributes(array('id' => 8)); $posts_13->config_value = $_POST['employee_number']; $posts_13->save(); $this->redirect(array('site/login')); } } $this->render('setup', array('model' => $model)); }
// Pas d'erreur, l'installation peut se faire. $constant = "<?php\n define('VERSION_NUMBER','1.6');\n define('VERSION_NAME','Dev');\n\n //Host de Mysql, le plus souvent localhost ou 127.0.0.1\n define('MYSQL_HOST','{$mysqlHost}');\n //Identifiant MySQL\n define('MYSQL_LOGIN','{$mysqlLogin}');\n //mot de passe MySQL\n define('MYSQL_MDP','{$mysqlMdp}');\n //Nom de la base MySQL ou se trouvera leed\n define('MYSQL_BDD','{$mysqlBase}');\n //Prefix des noms des tables leed pour les bases de données uniques\n define('MYSQL_PREFIX','{$mysqlPrefix}');\n?>"; file_put_contents('constant.php', $constant); if (!is_readable('constant.php')) { die('"constant.php" not found!'); } require_once 'constant.php'; require_once 'MysqlEntity.class.php'; class_exists('Update') or (require_once 'Update.class.php'); Update::ExecutePatch(true); require_once 'Feed.class.php'; require_once 'Event.class.php'; require_once 'User.class.php'; require_once 'Folder.class.php'; require_once 'Configuration.class.php'; $cryptographicSalt = User::generateSalt(); $synchronisationCode = substr(sha1(rand(0, 30) . time() . rand(0, 30)), 0, 10); $root = substr($_['root'], strlen($_['root']) - 1) == '/' ? $_['root'] : $_['root'] . '/'; // DOSSIERS À CONSERVER TELS QUELS, SI DÉJÀ EXISTANTS $feedManager = new Feed(); $feedManager->create(); $eventManager = new Event(); $eventManager->create(); // COMPTE ADMINISTRATEUR, RÀZ SI NÉCESSAIRE $userManager = new User(); if ($userManager->tableExists()) { // Suppose qu'il n'y a qu'un seul utilisateur $userManager->truncate(); } $userManager->create(); $admin = new User();
$configurationManager->put('articlePerPages', $_['articlePerPages']); $configurationManager->put('articleDisplayLink', $_['articleDisplayLink']); $configurationManager->put('articleDisplayDate', $_['articleDisplayDate']); $configurationManager->put('articleDisplayAuthor', $_['articleDisplayAuthor']); $configurationManager->put('articleDisplayHomeSort', $_['articleDisplayHomeSort']); $configurationManager->put('articleDisplayFolderSort', $_['articleDisplayFolderSort']); $configurationManager->put('articleDisplayMode', $_['articleDisplayMode']); $configurationManager->put('synchronisationType', $_['synchronisationType']); $configurationManager->put('synchronisationEnableCache', $_['synchronisationEnableCache']); $configurationManager->put('synchronisationForceFeed', $_['synchronisationForceFeed']); $configurationManager->put('feedMaxEvents', $_['feedMaxEvents']); $configurationManager->put('language', $_['ChgLanguage']); $configurationManager->put('theme', $_['ChgTheme']); $userManager->change(array('login' => $_['login']), array('id' => $myUser->getId())); if (trim($_['password']) != '') { $salt = User::generateSalt(); $userManager->change(array('password' => User::encrypt($_['password'], $salt)), array('id' => $myUser->getId())); /* /!\ En multi-utilisateur, il faudra changer l'information au niveau du compte lui-même et non au niveau du déploiement comme ici. C'est ainsi parce que c'est plus efficace de stocker le sel dans la config que dans le fichier de constantes, difficile à modifier. */ $oldSalt = $configurationManager->get('cryptographicSalt'); if (empty($oldSalt)) { /* Pendant la migration à ce système, les déploiements ne posséderont pas cette donnée. */ $configurationManager->add('cryptographicSalt', $salt); } else { $configurationManager->change(array('value' => $salt), array('key' => 'cryptographicSalt')); } }
public static function addPending($username, $password, $email) { //Error checking/validation... if (!User::validateUsername($username)) { throw new UserInvalidUsernameException($username); } if (!User::validatePassword($password)) { throw new UserInvalidPasswordException($password); } if (!User::validateEmail($email)) { throw new UserInvalidEmailException($email); } if (!User::availableUsername($username)) { throw new UserUnavailableUsernameException($username); } if (!User::availableEmail($email)) { throw new UserUnavailableEmailException($email); } //Main code follows... $salt = User::generateSalt(); $confirmCode = User::generateConfirmCode(); $db = User::getDB(); $query = $db->prepare('INSERT INTO usersPending(username, password, salt, email, date, confirmCode) VALUES(:username, :password, :salt, :email, :date, :confirmCode)'); $query->bindParam(':username', $username, PDO::PARAM_STR); $query->bindParam(':password', User::processPassword($password, $salt), PDO::PARAM_STR); $query->bindParam(':salt', $salt, PDO::PARAM_LOB); //is LOB right..? $query->bindParam(':email', $email, PDO::PARAM_STR); $query->bindParam(':date', time(), PDO::PARAM_STR); $query->bindParam(':confirmCode', hash(User::config('hash_algorithm'), $confirmCode), PDO::PARAM_STR); $query->execute(); //Send confirm email... $body = User::config('confirm_body_template'); $body = str_replace('[id]', $db->lastInsertId(), $body); $body = str_replace('[code]', $confirmCode, $body); mail($email, User::config('confirm_subject'), $body, 'From: ' . User::config('confirm_from')); }
public function actionConfig() { Controller::disableProfiler(); $model = new InstallForm(); if (isset($_POST['ajax']) && $_POST['ajax'] === 'install-form') { echo CActiveForm::validate($model); Yii::app()->end(); } $this->checkRequirements(); $this->checkRightFile(); if (isset($_POST['InstallForm'])) { $model->attributes = $_POST['InstallForm']; if ($model->validate()) { // form inputs are valid, do something here try { $ds = DIRECTORY_SEPARATOR; $dbConfFile = Yii::app()->basePath . "{$ds}config{$ds}db.php"; /*if(isFree()) { $sqlFile = $this->module->basePath . "{$ds}data{$ds}open-re.sql"; } else { $sqlFile = $this->module->basePath . "{$ds}data{$ds}open-re-full.sql"; }*/ $connectionString = "mysql:host={$model->dbHost};dbname={$model->dbName};port={$model->dbPort}"; $connection = new CDbConnection($connectionString, $model->dbUser, $model->dbPass); $connection->connectionString = $connectionString; $connection->username = $model->dbUser; $connection->password = $model->dbPass; $connection->emulatePrepare = true; $connection->charset = 'utf8'; $connection->tablePrefix = $model->dbPrefix; $connection->active = true; Yii::app()->setComponent('db', $connection); $params = array('components' => array('db' => array('class' => 'CDbConnection', 'connectionString' => $connectionString, 'username' => $model->dbUser, 'password' => $model->dbPass, 'emulatePrepare' => true, 'charset' => 'utf8', 'enableParamLogging' => false, 'enableProfiling' => false, 'schemaCachingDuration' => 7200, 'tablePrefix' => $model->dbPrefix)), 'language' => $model->language); $dbConfString = "<?php\n return " . var_export($params, true) . " ;\n?>"; $fh = fopen($dbConfFile, 'w+'); if (!$fh) { $model->addError('', tFile::getT('module_install', 'Can not open config/db.php file for record!')); } else { fwrite($fh, $dbConfString); fclose($fh); @chmod($dbConfFile, 0666); $adminSalt = User::generateSalt(); $adminPass = User::hashPassword($model->adminPass, $adminSalt); Yii::app()->user->setState('adminName', $model->adminName); Yii::app()->user->setState('adminPass', $adminPass); Yii::app()->user->setState('adminSalt', $adminSalt); Yii::app()->user->setState('adminEmail', $model->adminEmail); Yii::app()->user->setState('dbPrefix', $model->dbPrefix); Yii::app()->user->setState('siteName', $model->siteName); Yii::app()->user->setState('siteKeywords', $model->siteKeywords); Yii::app()->user->setState('siteDescription', $model->siteDescription); if (!isFree()) { Yii::app()->user->setState('installLang', $model->language); } $this->redirect(array('/install/main/install')); } } catch (Exception $e) { $model->addError('', $e->getMessage()); } } } if (Yii::app()->request->cookies['ore_is_first'] && Yii::app()->request->cookies['ore_is_first']->value == 1) { $is_first = 0; } else { $is_first = 1; $cookie = new CHttpCookie('ore_is_first', 1); $cookie->expire = time() + 24 * 60 * 60; Yii::app()->request->cookies['ore_is_first'] = $cookie; } $this->render('install', array('model' => $model, 'is_first' => $is_first)); }