/** * Displays the update profile page of a student. * @param integer $id the student id */ public function actionUpdate($id) { $model = $this->loadModel($id); if (isset($_POST['Student'])) { $model->attributes = $_POST['Student']; if ($model->validate()) { $photo = CUploadedFile::getInstance($model, 'file'); if ($photo !== null) { $savePath = Yii::app()->params['photosDir']; if ($model->photo != Yii::app()->params['defaultProfilePhoto']) { unlink($savePath . $model->photo); } Yii::import('ext.randomness.*'); $fileName = Randomness::randomString(Student::MAX_FILENAME_LENGTH - strlen($photo->extensionName) - strlen('' + $model->id) - 1); $fileName = $fileName . $model->id . '.' . $photo->extensionName; $photo->saveAs($savePath . $fileName); $model->photo = $fileName; Yii::app()->user->setState('profilePhoto', $fileName); } $model->save(false); Yii::app()->user->setName($model->name); Yii::app()->user->setNotification('success', 'Profil berhasil diubah.'); } else { Yii::app()->user->setNotification('danger', 'Terdapat kesalahan pengisian.'); } } $this->render('update', array('model' => $model, 'faculties' => Faculty::model()->findAll())); }
/** * Tests the student update action with invalid input. */ public function testUpdateInvalid() { $model = $this->students('student1'); // Empty name $fakeStudent = Student::model()->findByPk($model->id); $fakeStudent->name = null; $this->assertFalse($fakeStudent->validate()); // Lengthy name $fakeStudent = Student::model()->findByPk($model->id); Yii::import('ext.randomness.*'); $fakeStudent->name = Randomness::randomString(Student::MAX_NAME_LENGTH + 1); $this->assertFalse($fakeStudent->validate()); // Empty faculty_id $fakeStudent = Student::model()->findByPk($model->id); $fakeStudent->faculty_id = null; $this->assertFalse($fakeStudent->validate()); // Invalid faculty_id $fakeStudent = Student::model()->findByPk($model->id); $fakeStudent->faculty_id = self::INVALID_ID; $this->assertFalse($fakeStudent->validate()); // Invalid file type $fakeStudent = Student::model()->findByPk($model->id); $fakeFile = $this->testFile; $fakeFile['name'] = 'Test.avi'; $fakeFile['type'] = 'video/x-msvideo'; $fakeStudent->file = new CUploadedFile($fakeFile['name'], $fakeFile['tmp_name'], $fakeFile['type'], $fakeFile['size'], $fakeFile['error']); $this->assertFalse($fakeStudent->validate()); // Invalid file size $fakeStudent = Student::model()->findByPk($model->id); $fakeFile = $this->testFile; $fakeFile['size'] = Student::MAX_FILE_SIZE * 2; $fakeStudent->file = new CUploadedFile($fakeFile['name'], $fakeFile['tmp_name'], $fakeFile['type'], $fakeFile['size'], $fakeFile['error']); $this->assertFalse($fakeStudent->validate()); }
public function actionForgot() { $model = new ForgotPasswordForm(); if (isset($_POST['ForgotPasswordForm'])) { $model->attributes = $_POST['ForgotPasswordForm']; //$this->refresh(); if ($model->validate()) { $tempPassword = Randomness::randomString(16, true); $model = User::model()->findByAttributes(array('email' => $model->email)); $model->isNewPassword = true; $model->password = $tempPassword; if ($model->save()) { //use 'passwordrest' view from views/mail $mail = new YiiMailer('passwordReset', array('tempPassword' => $tempPassword)); //$mail->setSmtp('smtp.gmail.com', 465, 'ssl', true, '*****@*****.**', 'your_password'); //render HTML mail, layout is set from config file or with $mail->setLayout('layoutName') //$mail->render();smtp.secureserver.net $mail->IsSMTP(); $mail->Host = 'smtp.teksavvy.com'; //$mail->SMTPAuth = true; //$mail->Host = 'smtpout.secureserver.net'; $mail->Port = 25; //$mail ->Username ='******'; //$mail -> Password ='******'; //set properties as usually with PHPMailer $mail->From = Yii::app()->params['nonReplyEmail']; $mail->FromName = Yii::app()->name; $mail->Subject = Yii::app()->name . ' - Password Reset'; $mail->AddAddress(YII_DEBUG ? Yii::app()->params['adminEmail'] : $model->email); //$mail->AddAddress(YII_DEBUG?Yii::app()->params['adminEmail']); //$mail->AddAddress('*****@*****.**'); //send if ($mail->Send()) { $mail->ClearAddresses(); Yii::app()->user->setFlash('success-', Yii::t('app', 'msg.success.password_reset')); } else { Yii::app()->user->setFlash('error-', 'Error while sending email: ' . $mail->ErrorInfo); } $this->refresh(true); } } } $this->render('application.modules.account.views.common.forgot', array('model' => $model)); }
/** * Tests the note update action with invalid input. */ public function testUpdateInvalid() { $model = $this->notes('note3'); // Empty title $fakeNote = Note::model()->findByPk($model->id); $fakeNote->title = null; $this->assertFalse($fakeNote->validate()); // Lengthy title $fakeNote = Note::model()->findByPk($model->id); Yii::import('ext.randomness.*'); $fakeNote->title = Randomness::randomString(Note::MAX_TITLE_LENGTH + 1); $this->assertFalse($fakeNote->validate()); // Empty description $fakeNote = Note::model()->findByPk($model->id); $fakeNote->description = null; $this->assertFalse($fakeNote->validate()); }
public function actionDownloadPortfolioZip() { if (isset($_POST) && isset($_POST['stu_job_id']) && !empty($_POST['stu_job_id'])) { $criteria = new CDbCriteria(); $criteria->addInCondition('stu_job_id', $_POST['stu_job_id']); $criteria->select = 'stu_job_id,student_id,stu_job_id,first_name,last_name,portfolio_file'; $selectedJobs = ViewStudentJobTitle::model()->findAll($criteria); if ($selectedJobs != null) { $tmpZipFile = tempnam(sys_get_temp_dir(), 'zip'); //FileHelper::getFilePath(Yii::getPathOfAlias('site.files').'/resumes/temp/zip/',true); $zip = new ZipArchive(); if ($zip->open($tmpZipFile, ZipArchive::OVERWRITE) === true) { foreach ($selectedJobs as $key => $job) { $student_id = $job['student_id']; $stu_job_id = $job['stu_job_id']; $first_name = $job['first_name']; $last_name = $job['last_name']; $name = $job['portfolio_file']; if (empty($name)) { continue; } $ext = CFileHelper::getExtension($name); $userFilezipName = $first_name . $last_name . '_pf_jobtitle_' . $stu_job_id . '.' . $ext; if ($name !== null) { $userFilePath = Yii::getPathOfAlias('site.files') . '/resumes/' . $student_id; $userFilePath .= '/' . $name; if (file_exists($userFilePath)) { $zip->addFile($userFilePath, $userFilezipName); } } } if ($zip->close()) { if (!FileHelper::outputFile('portfoliosZip' . Randomness::randomString() . '.zip', $tmpZipFile)) { throw new CHttpException(404, 'Download zip failed'); } } } } die; } else { throw new CHttpException(400, "Unable to find the selected filesll"); } }