Register
\Modules\Api\User\Register
Important !
The use of third party Oauth2 must not use
Register:post()
. Use the Login:post() method directly with theaccess_token
andlogin
will save the user account to the database if it does not exist and connect it in the process.This method is therefore to be used only to record "native" accounts
Methods
post
<?php public static function \Modules\Api\User\Register::post($data = array(), $custom = array())
Description
Register the user.
Parameters
data
An associative array whose keys are the columns' name and whose values are the privacy data, containing the following fields :
Name | Type | Required | Description |
---|---|---|---|
login | string | Yes | user's login |
password | string | Yes | user's password |
token | string | No | user access token from a third-party provider |
token_expires_at | string | No | expiry date of the user access token (format Y-m-d H:i:s) |
source | string | No (default : "native") | type of authentication |
provider_user_id | string | No | user's id from the third-party provider |
last_name | string | No | user's last name |
first_name | string | No | user's first name |
picture | string | No | uri of the user's image |
username | string | No | user's nickname |
company | string | No | user's company |
phone | string | No | user's phone number |
bo_access | boolean | No (default : 0) | Does this user have access to the back office ? |
api_access | boolean | No (default : 1) | Does this user have access to api ? |
need_activation | boolean | No (default : 0) | Does this user need an activation link ? |
activation_type | string | No (default : "approval") | Type of activation (possible values : "approval" or "email") |
custom
key / value array containing custom fields that you have added to theusers
table
Return
Int : user's id
Note
If the
need_activation
field is set totrue
, an email with an activation link is sent to the user if you receive a success in response to this webservice.
Note
These are the values of
activation_type
:
approval
: the user account must be activated through the Appspanel backoffice by an admin.status
will change to the value 1)
Example
Here is a simple example of what your register webservice might look like.
<?php
namespace App\Modules\Users;
use \Lib\Controller\WSController;
use \Modules\Api\User\Register as RegisterController;
use \Modules\Api\User\Login as LoginController;
/**
* Class Register
* @package App\Modules\Users
*/
class Register extends \Modules\Elements
{
/**
* @description Register and Log in the user.
* @param WSController $controller
* @param array $params
* @doc string $login User's login
* @doc string $password User's password
* @return array
* @throws \Lib\ApiException
*/
public static function post(WSController $controller, $params = array())
{
$post = \Lib\DataRequest::getInstance()->get('post');
$post['password'] = !empty($_SERVER['AP-SEC-DATA']['password']) ? $_SERVER['AP-SEC-DATA']['password'] : $post['password'];
if(RegisterController::post($post)){
return LoginController::post($post['login'], $post['password']);
}
}
}
Updated almost 6 years ago