Register

\Modules\Api\User\Register

❗️

Important !

The use of third party Oauth2 must not use Register:post(). Use the Login:post() method directly with the access_token and login 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 :
NameTypeRequiredDescription
loginstringYesuser's login
passwordstringYesuser's password
tokenstringNouser access token from a third-party provider
token_expires_atstringNoexpiry date of the user access token (format Y-m-d H:i:s)
sourcestringNo
(default : "native")
type of authentication
provider_user_idstringNouser's id from the third-party provider
last_namestringNouser's last name
first_namestringNouser's first name
picturestringNouri of the user's image
usernamestringNouser's nickname
companystringNouser's company
phonestringNouser's phone number
bo_accessbooleanNo
(default : 0)
Does this user have access to the back office ?
api_accessbooleanNo
(default : 1)
Does this user have access to api ?
need_activationbooleanNo
(default : 0)
Does this user need an activation link ?
activation_typestringNo
(default : "approval")
Type of activation (possible values : "approval" or "email")
  • custom
    key / value array containing custom fields that you have added to the users table

Return
Int : user's id

📘

Note

If the need_activation field is set to true, 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.
  • email : the user will receive a link by email. By clicking on the link his account will be activated (the 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']);
        }
    }
}