public function actionProfile() { $username = Yii::app()->Ini->v('user'); $current_user_id = 0; $current_user_role = 0; $model = Homeowners::model()->findByAttributes(array('username' => $username)); if (count($model) > 0) { if (!Yii::app()->user->isGuest) { $current_user_id = Yii::app()->user->getId(); $current_user_role = Yii::app()->user->role; } $criteria = new CDbCriteria(); $criteria->condition = "homeowner_id = " . $model->homeowner_id; $criteria->limit = 8; $this->pageTitle = 'Handyman.com - Homeowner - ' . $model->firstname . ' ' . $model->lastname . ' Profile'; $this->render('homeowner-profile', array('model' => $model, 'projects' => Projects::model()->findAll($criteria), 'current_user_id' => $current_user_id, 'current_user_role' => $current_user_role)); //update views if (!Yii::app()->user->isGuest) { $userid = Yii::app()->user->getId(); $role = Yii::app()->user->role; $views = HomeownerViews::model()->findByAttributes(array('viewed_by' => $userid, 'homeowner_id' => $model->homeowner_id, 'viewed_user_type' => $role)); if (count($views) > 0) { } else { $views = new HomeownerViews(); $views->homeowner_id = $model->homeowner_id; $views->viewed_by = $userid; $views->viewed_user_type = $role; $views->save(); } } } else { $this->redirect(Yii::app()->homeUrl . 'home/error'); } }
private function SendMailAfterSignUp($userid) { $hmodel = Homeowners::model()->findByPk($userid); $subject = Yii::app()->name . ' Account Details For Home Owner'; $content = $this->renderPartial('signup', array('huser' => $hmodel), true); $headers = "From: admin <admin@>" . Yii::app()->name . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=UTF-8"; mail($hmodel->email, $subject, $content, $headers); }
protected function loadUser($id = null) { if ($this->_model === null) { if ($id !== null) { $this->_model = Homeowners::model()->findByPk($id); } } return $this->_model; }
private function sendEmailNotification($subject, $message, $homeowener_id, $domain_name) { $receiver_details = Homeowners::model()->findByPk($homeowener_id); $receiver_name = $receiver_details->firstname . " " . $receiver_details->lastname; $receiver_email = $receiver_details->email; $subject = Yii::app()->name . " - " . $subject; $content = $this->renderPartial('message_notif_template', array('domain_name' => $domain_name, 'message' => $message, 'receiver_name' => $receiver_name), true); $headers = "From: admin <admin@>" . Yii::app()->name . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=UTF-8"; //$receiver_email = "*****@*****.**"; mail($receiver_email, $subject, $content, $headers); }
public function actionHomeowner_account() { if (!Yii::app()->user->isGuest) { if (Yii::app()->user->role == 'homeowner') { $this->pageTitle = 'Handyman.com - Home Owner Account'; $param['hmodel'] = Homeowners::model()->findByPk(Yii::app()->user->getId()); $param['state'] = States::model()->findAll(array('order' => 'Name ASC')); $param['page'] = "homeOwnerAccount"; $this->render('homeowner-account', $param); } else { $this->redirect(Yii::app()->homeUrl); } } else { $this->redirect(Yii::app()->homeUrl); } }
/** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate() { if ($this->role == "homeowner") { $user = Homeowners::model()->findByAttributes(array('email' => $this->username)); if ($user === null) { // No user found! $this->errorMessage = self::ERROR_USERNAME_INVALID; } else { if ($user->password !== $this->password) { // Invalid password! $this->errorMessage = self::ERROR_PASSWORD_INVALID; } else { // Okay! $this->errorMessage = self::ERROR_NONE; // Store the role in a session: $this->setState('role', $this->role); $this->setState('loginname', $user->firstname); $this->_id = $user->homeowner_id; $this->_username = $user->username; } } } else { $user = Contractors::model()->findByAttributes(array('Email' => $this->username)); if ($user === null) { // No user found! $this->errorMessage = self::ERROR_USERNAME_INVALID; } else { if ($user->Password !== $this->password) { // Invalid password! $this->errorMessage = self::ERROR_PASSWORD_INVALID; } else { // Okay! $this->errorMessage = self::ERROR_NONE; // Store the role in a session: $this->setState('role', $this->role); $this->setState('loginname', $user->ContactName); $this->_id = $user->ContractorId; $this->_username = $user->Username; } } } return !$this->errorMessage; }
public function getOwnerUname($homeowner_id2) { $name = ""; $details = Homeowners::model()->findByAttributes(array('homeowner_id' => $homeowner_id2)); if (count($details) > 0) { $name = $details->username; } return $name; }
public function savetoaffiliate($userid, $user_type) { $domain = "handyman.com"; $url = "http://www.api.contrib.com/forms/addaffiliate"; $headers = array('Accept: application/json'); if ($user_type == "homeowner") { $model = Homeowners::model()->findByPk($userid); $param = array('domain' => $domain, 'email' => $model->email, 'username' => $model->username, 'password' => $model->password, 'firstname' => $model->firstname, 'lastname' => $model->lastname); } else { $model = Contractors::model()->findByPk($userid); $param = array('domain' => $domain, 'email' => $model->Email, 'username' => $model->Username, 'password' => $model->Password, 'firstname' => $model->ContactName, 'lastname' => ""); } $affiliate_id = Yii::app()->Ini->createApiCall($url, 'POST', $headers, $param); if ($affiliate_id != "") { $details = Affiliates::model()->findByAttributes(array('userid' => $userid, 'user_type' => $user_type)); if (count($details) > 0) { $details->affiliate_id = $affiliate_id; $details->save(); } else { $details = new Affiliates(); $details->userid = $userid; $details->user_type = $user_type; $details->affiliate_id = $affiliate_id; $details->save(); } } }
public function savemessagewithAttachedProject() { $subject = Yii::app()->Ini->v('subject'); $message = Yii::app()->Ini->v('message'); $project_id = Yii::app()->Ini->v('project_id'); $receiver_id = Yii::app()->Ini->v('receiver_id'); $from_id = Yii::app()->user->getId(); $from_user_type = Yii::app()->user->role; $to_id = Yii::app()->Ini->v('receiver_id'); $sent_date = date("Y-m-d H:i:s"); $homeowner_details = Homeowners::model()->findByPk($from_id); /* get project info */ $concat_message = ""; $proj_info = Projects::model()->findByPk($project_id); if (count($proj_info) > 0) { $concat_message = "<br><br>Project Details:<br>\r\n\t\t\t\t<b>Description: </b>" . $proj_info->description . "<br>\r\n\t\t\t\t<b>Project Type: </b>" . $this->getProjectTypeName($proj_info->project_type_id) . "<br>\r\n\t\t\t\t<b>Start Date: </b>" . $proj_info->start_date . "<br>\r\n\t\t\t\t<b>Time Frame: </b>" . $proj_info->time_frame . "<br>\r\n\t\t\t\t<b>Budget: </b>" . $proj_info->budget . "<br>\r\n\t\t\t\t<b>Home Owner: </b> <a href='http://handyman.com/homeowner/profile/user/" . $homeowner_details->username . "'>" . $homeowner_details->firstname . " " . $homeowner_details->lastname . "</a><br>\r\n\t\t\t\tLearn more <a href='http://handyman.com/project/jobdetails/pj_id/" . $project_id . "'>here</a>.<br>\r\n\t\t\t\t"; } $messages = new Messages(); $messages->subject = $subject; $messages->message = $message . " " . $concat_message; $messages->from_id = $from_id; $messages->to_id = $to_id; $messages->to_user_type = 'contractor'; $messages->from_user_type = $from_user_type; $messages->date_sent = $sent_date; $this->sendEmailNotification($subject, $message . " " . $concat_message, $to_id, Yii::app()->name); if ($messages->save()) { $status = array('success' => true); } else { $status = array('success' => false, 'error_message' => print_r($messages->getErrors())); } $this->renderJSON($status); }
public function loginhomeowner($post) { $identity = new UserIdentity($post['homeowner_email'], $post['homeowner_password'], 'homeowner'); if ($identity->authenticate()) { Yii::app()->user->login($identity); $owner_id = Yii::app()->user->getId(); $status = true; $user = Homeowners::model()->findByPk($owner_id); $return['code'] = $this->encrypt_decrypt('encrypt', json_encode(array('firstname' => $user->firstname, 'lastname' => $user->lastname, 'username' => $user->username, 'password' => $user->password, 'email' => $user->email))); } else { $status = false; $return['message'] = $identity->errorMessage; } $return['status'] = $status; $this->renderJSON($return, $status); }
public function emailnotification($post) { $project_owner_id = $post['project_owner2']; $details = $post['project_details']; $message = $post['msg_content']; $subject = $post['msg_subject']; $project_owner = Homeowners::model()->findByPk($project_owner_id); $project_owner_fname = $project_owner->firstname; $project_owner_email = $project_owner->email; $sender_name = Yii::app()->user->loginname; $content = $this->renderPartial('emailnotificationmessage', array('name' => $project_owner_fname, 'message' => $message, 'subject' => $subject, 'details' => $details, 'sender_name' => $sender_name), true); $headers = "From: admin <admin@>" . Yii::app()->name . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=UTF-8"; mail($project_owner_email, $subject, $content, $headers); $status = array('success' => true); $this->renderJSON($status); }
public function deactivateaccount($post) { $role = Yii::app()->user->role; $password = $post['password']; $reason = $post['reason']; if ($role == 'homeowner') { $homeowner_id = Yii::app()->user->getId(); $hmodel = Homeowners::model()->findByPk($homeowner_id); if ($hmodel->password == $password) { $subject = 'Handyman Homeowner Deactivated Account'; $content = $hmodel->firstname . ' ' . $hmodel->lastname . ' ' . $hmodel->email . ' has deactivated his/her account.<br>'; $content .= 'Reason:<br>'; $content .= $reason; $headers = "From: admin <admin@>" . Yii::app()->name . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=UTF-8"; mail('*****@*****.**', $subject, $content, $headers); Homeowners::model()->deactivate($homeowner_id); $status = true; } else { $status = false; $return['message'] = 'Invalid password.'; } } else { $contractor_id = Yii::app()->user->getId(); $cmodel = Contractors::model()->findByPk($contractor_id); if ($cmodel->Password == $password) { $subject = 'Handyman Contractor Deactivated Account'; $content = $cmodel->Name . ' - ' . $cmodel->Email . ' has deactivated his/her account.<br>'; $content .= 'Reason:<br>'; $content .= $reason; $headers = "From: admin <admin@>" . Yii::app()->name . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=UTF-8"; mail('*****@*****.**', $subject, $content, $headers); Contractors::model()->deactivate($contractor_id); $status = true; } else { $status = false; $return['message'] = 'Invalid password.'; } } $return['status'] = $status; $this->renderJSON($return, $status); }