Profile

\Modules\Api\User\Profile

Methods

get

<?php public static function \Modules\Api\User\Profile::get($token = null)

Description
Get the user information.

Parameters

  • token
    The user's authentication token

Return

{
  "id": 1,
  "first_name": "my firstname",
  "last_name": "my lastname",
  "username": "username",
  "picture": null,
  "company": "Apps Panel",
  "phone": "0600000000",
  "last_updated_at": null,
  "status": 1,
  "bo_access": 1,
  "api_access": 1,
  "created_at": "2018-05-22 11:02:39"
}

put

<?php public static function \Modules\Api\User\Profile::put($token = null, $data = array(), $debug = false)

Description
Update the user information.

Parameters

  • token
    The user's authentication token
  • data
    An associative array whose keys are the columns' name and whose values are the user's new data.
  • debug (optional)
    true to print the SQL query when an error happens so as to facilitate debugging. (default : false)

Return
array : a success or error message

{
  "success": {
    "message": "Request was successful",
    "key": "ok",
    "code": 200
  }
}

// or an error object like : 

{
  "error": {
    "message": "invalid_token",
    "key": "invalid_token",
    "code": 1
  }
}

Example

Here is a simple example of what your profile webservice might look like.

<?php

namespace App\Modules\Users;

use \Lib\Controller\WSController;
use \Modules\Api\User\Profile as ProfileController;

/**
 * Class Profile
 * @package App\Modules\Users
 */
class Profile extends \Modules\Elements
{


    /**
     * @description Get the user information.
     * @param WSController $controller
     * @param array $params
     * @doc string $token user's token
     * @return array|boolean
     * @throws \Lib\ApiException
     */
    public static function get(WSController $controller, $params = array())
    {
        $token = !empty($_SERVER['AP-UTOKEN']) ? $_SERVER['AP-UTOKEN'] : $params['token'];

        return ProfileController::get($token);
    }


    /**
     * @description Update the user information.
     * @param WSController $controller
     * @param array $params
     * @doc string $token user's token
     * @return array|boolean
     * @throws \Lib\ApiException
     */
    public static function put(WSController $controller, $params = array())
    {
        $post = \Lib\DataRequest::getInstance()->get('input');
        $token = !empty($_SERVER['AP-UTOKEN']) ? $_SERVER['AP-UTOKEN'] : $post['token'];
        $post['password'] = !empty($_SERVER['AP-SEC-DATA']['password']) ? $_SERVER['AP-SEC-DATA']['password'] : $post['password'];

        return ProfileController::put($token, $post, false);
    }
}