Beispiel #1
0
 public function avatar_post($id)
 {
     $tempImage = tempnam_sfx(sys_get_temp_dir(), "jpg");
     $imageName = base64_to_png($this->post('image'), $tempImage);
     $thumbImage = create_thumb($imageName);
     $nameThumb = name_thumb($imageName);
     $handle = fopen($imageName, "r");
     $data = fread($handle, filesize($imageName));
     $headers = array('Authorization: Client-ID ' . IMGUR_CLIENT_ID);
     $postFields = array('image' => base64_encode($data));
     $dataImage = send_post(IMGUR_URL_UPLOAD_IMAGE, $postFields, $headers);
     $handle = fopen($nameThumb, "r");
     $data = fread($handle, filesize($nameThumb));
     $headers = array('Authorization: Client-ID ' . IMGUR_CLIENT_ID);
     $postFields = array('image' => base64_encode($data));
     $dataThumb = send_post(IMGUR_URL_UPLOAD_IMAGE, $postFields, $headers);
     $val['avatar_thumbnail'] = $dataThumb['data']['link'];
     $val['avatar_standar'] = $dataImage['data']['link'];
     $userId = $this->user_model->update($id, $val);
     if (!is_null($userId)) {
         //unlink($imageName);
         //unlink($nameThumb);
         $this->response(array('avatars' => $val), 200);
     } else {
         $this->response(array('error' => 'Internal Server Error'), 500);
     }
 }
Beispiel #2
0
    }
    /* Si il y a eu des erreurs on les affiche, sinon on continu l'inscription */
    if ($errors) {
        $allerror = "<ul>";
        foreach ($errors as $key) {
            $allerror .= "<li>" . $key . "</li>";
        }
        $allerror .= "</ul>";
        setFlash($allerror, "danger");
    } else {
        /* On commence l'inscription */
        $nom = ucwords(mb_strtolower($nom, 'UTF-8'));
        $prenom = ucwords(mb_strtolower($prenom, 'UTF-8'));
        /* On lui génère une image de profil */
        $identicon = new Identicon();
        $imageDataUri = $identicon->getImageDataUri($pseudo);
        base64_to_png($imageDataUri, $pseudo);
        $imgname = $pseudo . ".png";
        /* On enregistre notre utilisateur */
        if ($user->register($pseudo, $prenom, $nom, $email, $password, $imgname)) {
            /* Si l'inscription a bien eu lieu, on le connecte */
            $user->login($pseudo, $password);
            /* On rédirige l'utilisateur à l'index */
            $user::redirect('/');
        } else {
            setFlash("Une erreur est survenur lors de votre inscription :/", "danger");
        }
    }
}
//On importe la vue
require Config::get('view.paths') . 'inscription.view.php';