Ejemplo n.º 1
0
 public static function register($email, $pwd)
 {
     if (Yii::app()->request->isAjaxRequest && isset($email) && !empty($email)) {
         $account = PHDB::findOne(self::COLLECTION, array("email" => $email));
         if (!$account) {
             Person::clearUserSessionData();
             //validate isEmail
             $name = "";
             if (preg_match('#^([\\w.-])/<([\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,6})/>$#', $email, $matches)) {
                 $name = $matches[0];
                 $email = $matches[1];
             }
             if (!empty($pwd) && preg_match('#^[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,6}$#', $email)) {
                 //new user is creating account
                 $newAccount = array("@context" => array("@vocab" => "http://schema.org", "ph" => "http://pixelhumain.com/ph/ontology/"), 'email' => $email, 'pwd' => hash('sha256', $email . $pwd), 'ph:created' => time());
                 if (isset($_POST['name'])) {
                     $newAccount["name"] = $_POST['name'];
                 }
                 if (isset($_POST['cp'])) {
                     $newAccount["cp"] = $_POST['cp'];
                     $newAccount["address"] = array("@type" => "PostalAddress", "postalCode" => $_POST['cp']);
                 }
                 if (isset($_POST['country'])) {
                     $newAccount["address"]["addressLocality"] = $_POST['country'];
                 }
                 //save any inexistant tag to DB
                 if (isset($_POST['tags'])) {
                     $tagsList = PHDB::findOne(PHType::TYPE_LISTS, array("name" => "tags"), array('list'));
                     foreach (explode(",", $_POST['tags']) as $tag) {
                         if (!in_array($tag, $tagsList['list'])) {
                             PHDB::update(PHType::TYPE_LISTS, array("name" => "tags"), array('$push' => array("list" => $tag)));
                         }
                     }
                     $newAccount["tags"] = $_POST['tags'];
                 }
                 //add to DB
                 PHDB::insert(self::COLLECTION, $newAccount);
                 //set session elements for global credentials
                 Person::saveUserSessionData($newAccount);
                 //send validation mail
                 //TODO : make emails as cron jobs
                 $app = new Application($_POST["app"]);
                 Mail::send(array("tpl" => 'validation', "subject" => 'Confirmer votre compte  pour le site ' . $app->name, "from" => Yii::app()->params['adminEmail'], "to" => !PH::notlocalServer() ? Yii::app()->params['adminEmail'] : $email, "tplParams" => array("user" => $newAccount["_id"], "title" => $app->name, "logo" => $app->logoUrl)));
                 //TODO : add an admin notification
                 /*Notification::saveNotification(array("type"=>NotificationType::NOTIFICATION_REGISTER,
                   "user"=>$newAccount["_id"]));*/
                 $res = array("result" => true, "id" => $newAccount, "msg" => "Data Successfully Saved.");
             } else {
                 $res = array("result" => false, "msg" => "Vous devez remplir un email valide et un mot de passe .");
             }
         } else {
             $res = array("result" => true, "id" => $account["_id"], "msg" => "Existing User Successfully Saved.");
         }
     } else {
         $res = array("result" => false, "msg" => "Cette requete ne peut aboutir.");
     }
     return $res;
 }
Ejemplo n.º 2
0
</script>
</div>
		</li>	
		</ul>
		<?php 
} else {
    ?>
		<h2>Restricted Area</h2>
		<?php 
    /* ******************************
    			When first time users conenct to the api 
    			there is no data for a certain module 
    			this section will initialise the data
    			this is only shown if no admin user is found
    			******************************/
    if (!PH::notlocalServer()) {
        $admins = PHDB::noAdminExist($this->module->id);
        if (count($admins) > 0) {
            echo "<b>Data has allready been initialised</b><br/>Below is your list of admin users :<br/>";
            foreach ($admins as $key => $value) {
                echo "<b>" . $value["email"] . "</b><br/>";
            }
        } else {
            echo "Your Application instance <b>" . $this->module->id . "</b> has no admin user, first initialise your data below :<br/>";
            $this->renderPartial("application.components.api.views.adminPH.initData");
            //var_dump(json_decode(file_get_contents("X:\\X_Dev\\humanpixel\\modules\\sample\\data\\applications.js"),true));
        }
    }
    ?>
			<br/>or You can contact a PH admin <a class="btn" href="mail:contact@pixelhumain.com"><i class="fa fa-mail"></i></a>
		<?php