Created
July 15, 2013 18:27
-
-
Save alexbaumgertner/6002221 to your computer and use it in GitHub Desktop.
customer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/********************************************************************************************** | |
* Easy CMS | |
***********************************************************************************************/ | |
class CustomerController extends Controller | |
{ | |
public $layout = '//layouts/onecolumn'; | |
private $_model; | |
public function accessRules() | |
{ | |
return array( | |
array('allow', | |
'actions' => array('index', 'logout', 'recovery'), | |
'users' => array('*'), | |
), | |
array('deny', | |
'users' => array('*'), | |
), | |
); | |
} | |
public function actionIndex() | |
{ | |
$NextPage = Yii::app()->createUrl("order/params"); | |
// Уже авторизованы | |
if( !Yii::app()->user->isGuest ) { | |
$this->redirect($NextPage); | |
} | |
$model = null; | |
//var_dump($_POST['LoginForm']); | |
//var_dump($_POST['RegistrationForm']); | |
// Покупатель регистрируется | |
if (isset($_POST['RegistrationForm']) and isset($_POST['RegistrationForm']['email'])and $_POST['RegistrationForm']['email']!='') { | |
$model = new CustomerRegistrationForm; | |
$model->attributes = $_POST['RegistrationForm']; | |
if ($model->validate()) { | |
// generate password | |
$model->password = $model->generatePassword(); | |
$model->save(); | |
// Send Mail to Customer | |
$message = new YiiMailMessage; | |
$message->view = 'mailRegistrationSuccess'; | |
//$message->view = 'registrationFollowup'; | |
$message->setBody($model, 'text/html'); | |
$message->subject = 'Регистрация покупателя'; | |
$message->addTo($model->email); | |
// Внимание! Для отправки через smtp From и реальная почта должны совпадать | |
$message->from = Yii::app()->params['adminEmail']; | |
Yii::app()->mail->send($message); | |
// Send Mail to Admin | |
$message = new YiiMailMessage; | |
$message->view = 'mailRegistrationSuccess'; | |
$message->setBody($model, 'text/html'); | |
$message->subject = 'Регистрация покупателя'; | |
$message->addTo(Yii::app()->params['adminEmail']); | |
$message->from = Yii::app()->params['adminEmail']; | |
Yii::app()->mail->send($message); | |
$this->render("successful-registration"); | |
Yii::app()->end(); | |
} | |
//var_dump($model->errors); | |
} | |
// Покупатель логинится | |
// TODO: попробовать залогинится после регистрации? | |
if (isset($_POST['LoginForm']) and isset($_POST['LoginForm']['email']) and $_POST['LoginForm']['email']!='') { | |
$model = new CustomerLoginForm; | |
$model->attributes = $_POST['LoginForm']; | |
if ($model->validate() && $model->login()) { | |
$this->redirect($NextPage); | |
} else { | |
$model->addError('login', 'validate or login error'); | |
} | |
} | |
$this->pageTitle = "Покупатель"; | |
$this->render('index', array('form' => $model)); | |
} | |
public function actionLogout() | |
{ | |
Yii::app()->user->logout(); | |
$this->redirect(Yii::app()->createUrl("order")); | |
} | |
public function actionRecovery() | |
{ | |
if (isset($_POST['Recovery']) and isset($_POST['Recovery']['email'])) { | |
$user = CustomerRegistrationForm::model()->find('LOWER(email)=?', array(strtolower($_POST['Recovery']['email']))); | |
if($user===null){ | |
// Пользователь не найден | |
} else { | |
// Пользователь найден | |
$user->password = $user->generatePassword(); | |
// Внимание! Поместить пароль в текст до сохраниения. | |
$text = "<p>Восстановление покупателя</p>"; | |
$text .= "<p>Имя и Фамилия: ".$user->username."</p>"; | |
$text .= "<p>E-mail: ".$user->email."</p>"; | |
$text .= "<p><i>В дальнейшем почта будет логином для авторизации на сайте</i></p>"; | |
$text .= "<p>Ваш пароль: ".$user->password."</p>"; | |
$text .= "<p>Телефон: ".$user->phone."</p>"; | |
$text .= "<p><i>Наши менеджеры сами перезвонят для уточнения и подтверждения заказа</i></p>"; | |
$user->save(); | |
// Send Mail to Customer | |
$message = new YiiMailMessage; | |
//$message->view = 'registrationFollowup'; | |
$message->setBody($text, 'text/html'); | |
$message->subject = 'Восстановление покупателя'; | |
$message->addTo($user->email); | |
// Внимание! Для отправки через smtp From и реальная почта должны совпадать | |
$message->from = Yii::app()->params['adminEmail']; | |
$send_result = Yii::app()->mail->send($message); | |
if(!$send_result) { | |
$send_error = Yii::app()->mail->getError(); | |
} | |
// Send Mail to Admin | |
$message = new YiiMailMessage; | |
$message->setBody($text, 'text/html'); | |
$message->subject = 'Восстановление покупателя'; | |
$message->addTo(Yii::app()->params['adminEmail']); | |
$message->from = Yii::app()->params['adminEmail']; | |
$send_result = Yii::app()->mail->send($message); | |
if(!$send_result) { | |
$send_error = Yii::app()->mail->getError(); | |
} | |
$this->render("mail-send"); | |
Yii::app()->end(); | |
} | |
} | |
$this->pageTitle = "Восстановление пароля"; | |
$this->render('recovery', array()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment