예제 #1
0
 public function actionRegisterGPSTracker()
 {
     $model = new RegisterGPSTrackerForm();
     $processOutput = true;
     $isMobileClient = false;
     // collect user input data
     if (isset($_POST['RegisterGPSTrackerForm'])) {
         $isMobileClient = false;
         if (isset($_REQUEST['client']) && $_REQUEST['client'] == 'mobile') {
             $isMobileClient = true;
         }
         $model->attributes = $_POST['RegisterGPSTrackerForm'];
         // validate user input and if ok return json data and end application.
         if ($model->validate()) {
             $users = new Users();
             $users->realname = $model->name;
             $users->deviceId = $model->deviceId;
             //For database recording, because of email and password are required fields
             $users->email = $model->deviceId;
             $users->password = md5($model->name);
             $users->save();
             if ($users->save()) {
                 $friend = new Friends();
                 $friend->friend1 = Yii::app()->user->id;
                 $friend->friend1Visibility = 1;
                 //default visibility setting is visible
                 $friend->friend2 = $users->getPrimaryKey();
                 $friend->friend2Visibility = 1;
                 //default visibility setting is visible
                 $friend->status = 1;
                 if ($friend->save()) {
                     echo CJSON::encode(array("result" => "1"));
                 } else {
                     echo CJSON::encode(array("result" => "Unknown error"));
                 }
             } else {
                 echo CJSON::encode(array("result" => "Unknown error"));
             }
             Yii::app()->end();
         }
         if (Yii::app()->request->isAjaxRequest) {
             $processOutput = false;
         }
     }
     if ($isMobileClient == true) {
         if ($model->getError('password') != null) {
             $result = $model->getError('password');
         } else {
             if ($model->getError('email') != null) {
                 $result = $model->getError('email');
             } else {
                 if ($model->getError('passwordAgain') != null) {
                     $result = $model->getError('passwordAgain');
                 } else {
                     if ($model->getError('passwordAgain') != null) {
                         $result = $model->getError('passwordAgain');
                     }
                 }
             }
         }
         echo CJSON::encode(array("result" => $result));
         Yii::app()->end();
     } else {
         Yii::app()->clientScript->scriptMap['jquery.js'] = false;
         Yii::app()->clientScript->scriptMap['jquery-ui.min.js'] = false;
         $this->renderPartial('registerGPSTracker', array('model' => $model), false, $processOutput);
     }
 }
 /**
  * Registra una solicitud de amistad
  */
 public function actionSendFriendshipRequest()
 {
     $output = array('errno' => 1, 'message' => 0);
     //Check if user is logged
     if (!Yii::app()->user->isGuest) {
         //check if they are friends now
         if (!$this->are_they_friends) {
             //Check if is pending
             $condition = "(from_user = :user_knight1 AND to_user = :knight1 AND status = :status1) OR (from_user = :knight2 AND to_user = :user_knight2 AND status = :status2)";
             $params = array(':knight1' => $this->knight->id, ':knight2' => $this->knight->id, ':user_knight1' => $this->user_data['knights']->id, ':user_knight2' => $this->user_data['knights']->id, ':status1' => Friends::STATUS_ONWAITING, ':status2' => Friends::STATUS_ONWAITING);
             $friendRelationship = Friends::model()->find($condition, $params);
             if ($friendRelationship == null) {
                 //We create
                 $friend = new Friends();
                 $friend->attributes = array('from_user' => Yii::app()->user->users_id, 'to_user' => $this->knight->users_id, 'status' => Friends::STATUS_ONWAITING, 'start_date' => date('Y-m-d H:i:s'));
                 if ($friend->save()) {
                     /*
                      * SEND EMAIL TO RIVAL
                      */
                     Yii::trace('[CHARACTER][sendChallenge] CHECK email');
                     //Check email of challenge
                     if ($knight_setting = KnightsSettings::model()->findByPk($this->knight->id)) {
                         if ($knight_setting->emailToFinishedCombat) {
                             Yii::trace('[CHARACTER][sendChallenge] Send email');
                             //Check email
                             if ($knight_user = Users::model()->findByPk($this->knight->users_id)) {
                                 Yii::trace('[CHARACTER][sendChallenge] Rival email' . $knight_user->email);
                                 //cargamos la plantilla
                                 $message = Yii::app()->controller->renderFile(Yii::app()->basePath . Yii::app()->params['email_templates_path'] . 'friendlyRequest.tpl', array(), true);
                                 // To send HTML mail, the Content-type header must be set
                                 $headers = 'MIME-Version: 1.0' . "\r\n";
                                 $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
                                 // Additional headers
                                 $headers .= 'To: ' . $knight_user->email . "\r\n";
                                 $headers .= 'From: <noreply@' . Yii::app()->params->url_domain . '>' . "\r\n";
                                 //$headers = array($headers);
                                 $email = new Emails();
                                 $email->attributes = array('destination' => $knight_user->email, 'headers' => $headers, 'title' => Yii::app()->name . ': solicitud de amistad.', 'body' => $message, 'status' => Emails::STATUS_PENDING, 'date' => date('Y-m-d H:i:s'));
                                 //Old
                                 //$aux = Yii::app()->email->send( '*****@*****.**',$knight_user->email , Yii::app()->name.': solicitud de amistad.' ,$message,$headers);
                                 if (!$email->save()) {
                                     Yii::trace('[CHARACTER][actionSendFriendshipRequest] No se ha podido guardar el email');
                                 }
                             } else {
                                 Yii::trace('[CHARACTER][actionSendFriendshipRequest] No se ha encontrado usuario del caballero ' . $this->knight->id, 'error');
                             }
                         }
                     } else {
                         Yii::trace('No se ha encontrado setting del caballero ' . $this->knight->id, 'error');
                     }
                     $output['errno'] = 0;
                     $output['message'] = 'La petición de amistad se ha enviado correctamente.';
                 } else {
                     $output['message'] = 'No se ha podido registrar la petición de amistad.';
                 }
             } else {
                 $output['message'] = '<p>Actualmente ya hay una solicitud en curso a la espera de que se acepte.</p>';
             }
         } else {
             $output['message'] = '<p>Sientes tanto aprecio por tu amigo como para hacerle una segunda petición de amistad.</p> <p>Eso es amor.</p>';
         }
     } else {
         $output['message'] = 'La sesion ha expirado. Necesitas hacer login de nuevo para realizar esta acción.';
     }
     echo CJSON::encode($output);
 }
예제 #3
0
 public function actionAddAsFriend()
 {
     $result = 'Missing parameter';
     if (isset($_REQUEST['friendId'])) {
         $friendId = (int) $_REQUEST['friendId'];
         $friend = new Friends();
         $friend->friend1 = Yii::app()->user->id;
         $friend->friend1Visibility = 1;
         //default visibility setting is visible
         $friend->friend2 = $friendId;
         $friend->friend2Visibility = 1;
         //default visibility setting is visible
         $friend->status = 0;
         $result = 'Error occured';
         if ($friend->save()) {
             $result = 1;
         }
     }
     echo CJSON::encode(array("result" => $result));
 }