From 76b0751063bf948bb135f280f7b3e2548459fcd2 Mon Sep 17 00:00:00 2001 From: Thibault Junin Date: Fri, 4 Aug 2017 19:59:21 +0200 Subject: [PATCH] v2.1.1: Adding password requirement --- src/STAILEUAccounts.php | 193 +++++++++++++++++++++++----------------- 1 file changed, 109 insertions(+), 84 deletions(-) diff --git a/src/STAILEUAccounts.php b/src/STAILEUAccounts.php index c735d29..1a2e1d2 100644 --- a/src/STAILEUAccounts.php +++ b/src/STAILEUAccounts.php @@ -9,7 +9,7 @@ * @copyright 2015-2017 STAN-TAb Corp. * @license https://stantabcorp.com/license * @link https://stail.eu - * @version 2.0.5 + * @version 2.1.1 */ class STAILEUAccounts{ @@ -38,7 +38,8 @@ class STAILEUAccounts{ * * The construct method * - * @param boolean $cache If you want to use cache or not + * @param string $key Your app private key + * @param string $pkey Your app public key */ public function __construct($key, $pkey){ $this->key = $key; @@ -237,6 +238,83 @@ public function register($arr){ } } + /** + * loginForm() + * + * This function generate the login url + * + * @param string The redirect url + * @param string OPTIONAL A image url + * + * @return string The login url + */ + public function loginForm($redir, $img = NULL){ + if($img == NULL){ + return $this->url."/login?key=".$this->pkey."&redir=".$redir; + }else{ + return $this->url."/login?key=".$this->pkey."&redir=".$redir."&img=".$img; + } + } + + /** + * registerForm() + * + * This function generate the register url + * + * @param string The redirect url + * @param string OPTIONAL A image url + * + * @return string The login url + */ + public function registerForm($redir, $img = NULL){ + if($img == NULL){ + return $this->url."/register?key=".$this->pkey."&redir=".$redir; + }else{ + return $this->url."/register?key=".$this->pkey."&redir=".$redir."&img=".$img; + } + } + + /** + * checkLogin() + * + * This function verify the return code + * + * @param string The c-sa code + * + * @return boolean|string false or the user's uuid + */ + public function checkLogin($code){ + $rep = json_decode($this->sendRequest($this->url."/api/check", array( + "code" => $code, + "key" => $this->key, + ), true),true); + if($rep['success']){ + return $rep['uuid']; + }else{ + $this->error = $rep['error']; + return false; + } + } + + /** + * forgotForm() + * + * This function generate the forgotten password url + * + * @param string The redirect url + * @param string OPTIONAL A image url + * + * @return string The login url + */ + public function forgotForm($redir, $img = NULL){ + if($img == NULL){ + return $this->url."/forgot?key=".$this->pkey."&redir=".$redir; + }else{ + return $this->url."/forgot?key=".$this->pkey."&redir=".$redir."&img=".$img; + } + + } + /** * getEmail() * @@ -359,6 +437,26 @@ public function getAvatar($uuid){ } } + /** + * getAvatarURL() + * + * This function return the user's avatar url + * + * @param string The user's uuid + * + * @return string The user's avatar url + */ + public function getAvatarURL($uuid){ + // if($this->isCached("avatar_url", $uuid)){ + // return $this->getCache("avatar_url", $uuid); + // }else{ + // $rep = $this->url."/api/avatar/".$uuid.".png"; + // $this->setCache("avatar_url", $uuid, $rep->avatar); + // return $rep; + // } + return null; + } + /** * changeUsername() * @@ -369,10 +467,11 @@ public function getAvatar($uuid){ * * @return boolean true If the username has been changed */ - public function changeUsername($uuid, $username){ + public function changeUsername($uuid, $username, $password){ $rep = json_decode($this->sendRequest($this->url."/api/change/username", array( "uuid" => $uuid, "username" => $username, + "password" => md5($password), "key" => $this->key, ), true)); if($rep->success){ @@ -393,10 +492,11 @@ public function changeUsername($uuid, $username){ * * @return boolean true If the avatar has been changed */ - public function changeAvatar($uuid, $avatar){ + public function changeAvatar($uuid, $avatar, $password){ $rep = json_decode($this->sendRequest($this->url."/api/change/avatar", array( "uuid" => $uuid, "avatar" => $avatar, + "password" => md5($password), "key" => $this->key, ), true)); if($rep->success){ @@ -443,10 +543,11 @@ public function changePassword($uuid, $oldpass, $nvpass){ * * @return boolean true If the email address has been changed */ - public function changeEmail($uuid, $email){ + public function changeEmail($uuid, $email, $password){ $rep = json_decode($this->sendRequest($this->url."/api/change/email", array( "uuid" => $uuid, "email" => $email, + "password" => md5($password), "key" => $this->key, ), true)); if($rep->success){ @@ -458,7 +559,7 @@ public function changeEmail($uuid, $email){ } /** - * changeAvatar() + * changeNumber() * * This function change the user's phone number * @@ -467,10 +568,11 @@ public function changeEmail($uuid, $email){ * * @return boolean true If the phone number has been changed */ - public function changeNumber($uuid, $number){ + public function changeNumber($uuid, $number, $password){ $rep = json_decode($this->sendRequest($this->url."/api/change/number", array( "uuid" => $uuid, "number" => $number, + "password" => md5($password), "key" => $this->key, ), true)); if($rep->success){ @@ -506,81 +608,4 @@ public function getUserRegistredByMe(){ } } - /** - * loginForm() - * - * This function generate the login url - * - * @param string The redirect url - * @param string OPTIONAL A image url - * - * @return string The login url - */ - public function loginForm($redir, $img = NULL){ - if($img == NULL){ - return "https://accounts.stail.eu/login?key=".$this->pkey."&redir=".$redir; - }else{ - return "https://accounts.stail.eu/login?key=".$this->pkey."&redir=".$redir."&img=".$img; - } - } - - /** - * registerForm() - * - * This function generate the register url - * - * @param string The redirect url - * @param string OPTIONAL A image url - * - * @return string The login url - */ - public function registerForm($redir, $img = NULL){ - if($img == NULL){ - return "https://accounts.stail.eu/register?key=".$this->pkey."&redir=".$redir; - }else{ - return "https://accounts.stail.eu/register?key=".$this->pkey."&redir=".$redir."&img=".$img; - } - } - - /** - * checkLogin() - * - * This function verify the return code - * - * @param string The c-sa code - * - * @return boolean|string false or the user's uuid - */ - public function checkLogin($code){ - $rep = json_decode($this->sendRequest($this->url."/api/check", array( - "code" => $code, - "key" => $this->key, - ), true),true); - if($rep['success']){ - return $rep['uuid']; - }else{ - $this->error = $rep['error']; - return false; - } - } - - /** - * forgotForm() - * - * This function generate the forgotten password url - * - * @param string The redirect url - * @param string OPTIONAL A image url - * - * @return string The login url - */ - public function forgotForm($redir, $img = NULL){ - if($img == NULL){ - return "https://accounts.stail.eu/forgot?key=".$this->pkey."&redir=".$redir; - }else{ - return "https://accounts.stail.eu/forgot?key=".$this->pkey."&redir=".$redir."&img=".$img; - } - - } - }