/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new AUser(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['AUser'])) { $model->attributes = $_POST['AUser']; $model->password = CFunction::encrypt($_POST['AUser']['password'], Yii::app()->params->hashkey); $model->user_group_id = $_REQUEST['group_id']; $model->created_date = time(); if ($_REQUEST['group_id'] == 4) { $listTrainee = Yii::app()->session->get('listTrainee') ? json_decode(Yii::app()->session->get('listTrainee'), true) : array(); } if ($model->save()) { if ($_REQUEST['group_id'] == 4) { if (!empty($listTrainee)) { foreach ($listTrainee as $item) { $modelTraineeTeam = ATrainingTeam::model()->find('team_leader_id=' . $model->id . ' AND trainee_id=' . $item['id']); if (empty($modelTraineeTeam)) { $modelTraineeTeam = new ATrainingTeam(); $modelTraineeTeam->team_leader_id = $model->id; $modelTraineeTeam->trainee_id = $item['id']; } if ($modelTraineeTeam->save()) { unset($_SESSION['listTrainee']); } } } } Yii::app()->user->setFlash('success', 'Đã tạo mới thành công'); $this->redirect(array('admin', 'group_id' => $_REQUEST['group_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 wUsers(); if (isset($_POST['wUsers'])) { $model->attributes = $_POST['wUsers']; $model->id = CFunction::GUID(); $model->password = CFunction::encrypt($_POST['wUsers']['password'], Yii::app()->params->hashkey); $model->repassword = CFunction::encrypt($_POST['wUsers']['repassword'], Yii::app()->params->hashkey); $model->created_date = date("Y-m-d H:i:s"); $model->active_key = CFunction::random_generator(Yii::app()->params->number_active); $model->status = 0; if ($model->save()) { $activation_url = $this->createAbsoluteUrl('/wUsers/activation', array("activekey" => $model->active_key, "email" => $model->email)); } //CFunction::sendMail($model->email, Yii::t('web/app',"registed"), Yii::t("web/app","active_code").$activation_url); //Yii::app()->user->setFlash('success', Yii::t('adm/app','register_success')); $this->render('alert', array('msg' => Yii::t('web/app', 'register_success'))); //$this->redirect(array('create','type'=>$_GET['type'])); } $this->render('create', array('model' => $model)); }
public function actionCreateTrainee() { $cs = Yii::app()->getClientScript(); //$cs->registerScriptFile(Yii::app()->theme->baseUrl.'/js/ckeditor/ckeditor.js'); $cs->registerCssFile(Yii::app()->theme->baseUrl . '/js/jqueryUpload/jquery.fileupload.css'); $cs->registerScriptFile(Yii::app()->theme->baseUrl . '/js/bootstrap-datepicker/bootstrap-datetimepicker.js', CClientScript::POS_END); $cs->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jqueryUpload/jquery.ui.widget.js', CClientScript::POS_END); $cs->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jqueryUpload/jquery.fileupload.js', CClientScript::POS_END); $model = new WUser(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['WUser'])) { $model->attributes = $_POST['WUser']; $model->password = CFunction::encrypt(Yii::app()->params->password_default, Yii::app()->params->hashkey); $model->supervisor_code = Yii::app()->user->id; $model->status = 1; if ($model->save()) { $this->redirect(array('AllTrainee')); } } $this->render('createtrainee', array('model' => $model)); }
public function actionChangepassupdate() { // check login if (empty(Yii::app()->user->id)) { $this->redirect(Yii::app()->createurl('')); } $id_user = Yii::app()->user->id; $model = WUserUpdate::model()->findByPk($id_user); if (!empty($id_user)) { $criteria = new CDbCriteria(); $criteria->select = array('*'); $criteria->addCondition('id=' . $id_user); $data = WUser::model()->find($criteria); $data = CJSON::decode(CJSON::encode($data)); // print_r($data);die; } if (!empty($data)) { $check_save = 1; $old_pass = ''; $new_pass = ''; if (!empty($_REQUEST['currentpass'])) { $pass = CFunction::encrypt($_REQUEST['currentpass'], Yii::app()->params->hashkey); // $pass = $_REQUEST['currentpass']; // var_dump($pass); if ($data['password'] == $pass) { $check_save = 1; } else { $check_save = 0; $old_pass = '******'; } } else { $check_save = 0; $old_pass = '******'; } if ($check_save == 1) { if (!empty($_REQUEST['newpass'])) { if ($_REQUEST['newpass'] == $_REQUEST['re_newpass']) { $model->password = CFunction::encrypt($_REQUEST['newpass'], Yii::app()->params->hashkey); $new_pass = '******'; if ($model->save()) { } else { $new_pass = '******'; } } else { $new_pass = '******'; $check_save = 0; } } } } $this->render('change_pass', array('old_pass' => $old_pass, 'new_pass' => $new_pass)); }
public function actionImportTrainee() { header('Content-Type: text/html; charset=utf-8'); $model = new WUserTrainee(); require_once Yii::app()->basePath . '/components/reader.php'; //require_once Yii::app()->basePath . '/components/SpreadsheetReader_XLSX.php'; date_default_timezone_set('Asia/Saigon'); //var_dump($Filepath); die; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['ok'])) { $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('UTF-8'); $filename = $_FILES["traineeexcel"]["tmp_name"]; //var_dump($filename);exit; if ($_FILES["traineeexcel"]["size"] > 0) { $data->read($filename); //var_dump($data);exit(); for ($x = 3; $x <= count($data->sheets[0]["cells"]); $x++) { $mahocvien = mysql_real_escape_string($data->sheets[0]["cells"][$x][2]); $hovaten = mysql_real_escape_string($data->sheets[0]["cells"][$x][3]); $gioitinh = mysql_real_escape_string($data->sheets[0]["cells"][$x][4]); //echo $question_name;exit(); $birthday = mysql_real_escape_string($data->sheets[0]["cells"][$x][5]); $cmt = mysql_real_escape_string($data->sheets[0]["cells"][$x][6]); //echo $link_group;exit(); $phone = mysql_real_escape_string($data->sheets[0]["cells"][$x][7]); $email = mysql_real_escape_string($data->sheets[0]["cells"][$x][8]); $tencty = mysql_real_escape_string($data->sheets[0]["cells"][$x][9]); $supervisor = mysql_real_escape_string($data->sheets[0]["cells"][$x][10]); $start_datework = mysql_real_escape_string($data->sheets[0]["cells"][$x][11]); $course_intro = mysql_real_escape_string($data->sheets[0]["cells"][$x][12]); $chucvu = mysql_real_escape_string($data->sheets[0]["cells"][$x][13]); $level = mysql_real_escape_string($data->sheets[0]["cells"][$x][14]); $channel_job = mysql_real_escape_string($data->sheets[0]["cells"][$x][15]); $area = mysql_real_escape_string($data->sheets[0]["cells"][$x][16]); $system = mysql_real_escape_string($data->sheets[0]["cells"][$x][17]); $supermarket = mysql_real_escape_string($data->sheets[0]["cells"][$x][18]); $category = mysql_real_escape_string($data->sheets[0]["cells"][$x][19]); $password = CFunction::encrypt('123456', Yii::app()->params->hashkey); $status = 1; $user_group_id = 2; $created_date = time(); $model->username = $mahocvien; $model->password = $password; $model->fullname = $hovaten; $model->sex = $gioitinh; $model->date_birth = date('Y-m-d H:i:s', strtotime($birthday)); $model->cmt = $cmt; $model->email = $email; $model->user_group_id = $user_group_id; $model->company_code = $tencty; $model->supervisor_code = $supervisor; $model->created_date = $created_date; $model->time_startwork = date('Y-m-d H:i:s', strtotime($start_datework)); $model->course_induction_training = $course_intro; $model->position = $chucvu; $model->level = $level; $model->channel_work = $channel_job; $model->region = $area; $model->system = $system; $model->supermarket = $supermarket; $model->category_job = $category; $model->status = $status; if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('web/home', 'Import success')); $this->redirect(array('wUser/AllTrainee')); } /* $sql = "INSERT INTO quiz_questions (id, question_name, question_name_text, answer1, answer2, answer3, answer4, answer, category_id, if_teacher, name_teacher, avatar) VALUES ('', '$question_name', '$question_name_text', '$answer1', '$answer2', '$answer3', '$answer4', '$answer', '1', '1', '$name_teacher', '$avatar')"; query($sql); */ } } else { Yii::app()->user->setFlash('unsuccess', Yii::t('web/home', 'Please select file have xls extension.')); $this->redirect(array('wUser/ImportTrainee')); } } $this->render('_import', array('model' => $model)); }
public function afterValidate() { $this->password = CFunction::encrypt($this->password, Yii::app()->params->hashkey); $this->repeatpassword = CFunction::encrypt($this->repeatpassword, Yii::app()->params->hashkey); return parent::afterValidate(); }
public function actionRspass() { // thu vien mail Yii::import('application.extensions.phpmailer.JPhpMailer'); $check_date = ''; // check login if (!empty(Yii::app()->user->id)) { $this->redirect(Yii::app()->createurl('')); } $page = 0; if (!empty($_REQUEST['acc']) && !empty($_REQUEST['token'])) { $username_var = trim($_REQUEST['acc']); $username_var = str_replace(array(',', "'", '"', ' ', '%'), '', $username_var); $token_string = trim($_REQUEST['token']); $token_string = str_replace(array(',', "'", '"', ' ', '%'), '', $token_string); //check token $criteria = new CDbCriteria(); $criteria->select = array('*'); $criteria->addCondition('user_name= "' . $username_var . '" AND token_check="' . $token_string . '"'); $check_token = WUserLosePass::model()->find($criteria); $check_token = CJSON::decode(CJSON::encode($check_token)); if (empty($check_token)) { $check_date = 'Chuỗi kick hoạt không đúng ! bạn vui lòng sử dụng đúng URL trong Email !'; } else { $date_now = date('Y-m-d'); //get id lost $criteria = new CDbCriteria(); $criteria->select = array('*'); $criteria->addCondition('user_name= "' . $username_var . '"'); $get_lost_id = WUserLosePass::model()->findAll($criteria); $get_lost_id = CJSON::decode(CJSON::encode($get_lost_id)); $criteria = new CDbCriteria(); $criteria->select = array('*'); $criteria->addCondition('user_name= "' . $username_var . '" AND end_time_change >= "' . $date_now . '"'); $data_lost = WUserLosePass::model()->findAll($criteria); $data_lost = CJSON::decode(CJSON::encode($data_lost)); //check user $criteria = new CDbCriteria(); $criteria->select = array('*'); $criteria->addCondition('username= "******"'); $data = WUser::model()->find($criteria); $data = CJSON::decode(CJSON::encode($data)); if (empty($data_lost)) { // var_dump($data_lost); $check_date = 'Quá hạn kich hoạt email!'; } if (empty($check_date) && !empty($data)) { if (!empty($_REQUEST['password'])) { $pass_new = CFunction::encrypt($_REQUEST['password'], Yii::app()->params->hashkey); $model = WUserUpdate::model()->find('id=' . $data['id']); $model->password = $pass_new; if ($model->save()) { if ($get_lost_id) { foreach ($get_lost_id as $key => $value) { $id = $value['id']; $this->loadModel($id)->delete(); } } $this->render('success_change_pass'); $page = 1; } } } } } if ($page == 0) { $dataProvider = new CActiveDataProvider('WUserLosePass'); $this->render('lostpass', array('dataProvider' => $dataProvider, 'check_date' => $check_date)); } }
public function validatePassword($password, $hashKey) { return $this->password === CFunction::encrypt($password, $hashKey); }