remp/crm-users-module

3.4.0 2024-08-27 13:26 UTC

README

Translation status @ Weblate

本文档描述了该模块提供的API处理程序和CLI命令,以便其他人使用。它假定您的应用程序基于我们提供的CRM 框架

安装模块

我们建议使用Composer进行安装和更新管理。

composer require remp/crm-users-module

启用模块

将已安装的扩展添加到您的app/config/config.neon文件中。

extensions:
	users: Crm\UsersModule\DI\UsersModuleExtension

生成ACL

用户访问资源用于控制CRM管理员的用户组的访问权限。这些资源由所有扩展Crm\AdminModule\Presenters\AdminPresenterrender*action*handle*方法生成。

要生成,请运行以下命令

php bin/command.php user:generate_access

每次发布新版本时,应运行此命令以验证和生成新资源。

所有新资源都自动分配给superadmin管理员组 - 请检查种子Crm\UsersModule\Seeders\UsersSeeder

其他管理员组不受影响。新资源必须通过以下方式手动分配:通过管理界面(http://crm.press/users/admin-group-admin/show/1)或在您的模块中设置种子。

ACL - admin-access-level

这些注释是可选的,不会影响资源访问权限的解析。

为了简化将访问权限分配给管理员组(http://crm.press/users/admin-group-admin/show/1),可以指定访问资源级别为方法注释admin-access-level。CRM现在使用两个级别:readwrite。级别write表示此方法可用于创建、更新或删除实体。其余资源级别为read

示例

use Crm\AdminModule\Presenters\AdminPresenter;

class ExampleAdminPresenter extends AdminPresenter {

    /**
     * @admin-access-level read
     */
    public function renderDefault()
    {
    }

    /**
     * @admin-access-level write
     */
    public function renderEdit()
    {
    }
}

如果缺少注释admin-access-level,则在分配资源/权限给管理员组的页面(http://crm.press/users/admin-group-admin/show/1)上不显示级别。

清理

命令也有清理选项

php bin/command.php user:generate_access --cleanup

资源生成后,它会将当前ACL资源和动作与之前的状态进行比较。孤儿ACL资源将从数据库中删除。当模块卸载或管理员表示/动作被删除时很有用。

警告:此选项不会在资源移动后修复ACL。这应由模块在资源移动/重命名(例如,通过迁移)时处理。

单点登录

Google登录

用户模块支持使用授权代码流和ID令牌进行Google登录认证。

配置

任何使用Google登录的应用程序都必须有授权凭证,以标识应用程序给Google的OAuth 2.0服务器。要设置凭证,请访问Google 凭证页面

获取凭证后,请使用以下格式将它们放入neon配置文件中

users:
	sso:
	    google:
	        client_id: CLIENT_ID
	        client_secret: CLIENT_SECRET

最后一步是在/admin/config-admin/认证部分CRM设置中/admin/config-admin/启用Google登录。

ID令牌

ID令牌是一个Google签名的JWT令牌,包含用户信息(请参阅文档)。此模块提供了一个API端点来验证令牌并将其与现有用户(或使用用户电子邮件地址创建新用户)相匹配。

授权代码流

标准OAuth2授权代码流在用户被重定向到http://crm.press/users/google/sign URL时启动。

一个可选参数是url,这是一个登录成功后要重定向到的URL。url需要与当前CRM域名验证 - url至少要与二级域名相同,例如,如果您的CRM在crm.yoursystem.com上可用,任何通过*.yoursystem.com的域名都将被视为有效的重定向URI。

示例

用于启动Google登录的HTML按钮

<a href="http://crm.press/users/google/sign">Google Sign-In</a>

Apple登录

用户模块支持使用授权代码流和ID令牌进行Apple登录认证。

配置

任何使用Apple登录的应用都必须有授权凭据来识别该应用给Apple。更多信息,请访问Apple的入门页面

获取凭证后,请使用以下格式将它们放入neon配置文件中

users:
	sso:
	    apple:
	        client_id: CLIENT_ID # default client ID used for signing in on the web
	        trusted_client_ids: [CLIENT_ID] # other trusted client IDs using the Apple ID to sign in (e.g. mobile apps)

最后一步是在/admin/config-admin/认证部分中的CRM设置中启用Apple登录。

ID令牌

ID令牌是一个包含用户信息的Apple签名JWT令牌。此模块提供了一个API端点,用于验证令牌并将其与现有用户(或使用用户电子邮件地址创建新用户)匹配。

授权代码流

标准OAuth2授权代码流在用户被重定向到http://crm.press/users/apple/sign URL时启动。

一个可选参数是url,这是一个登录成功后要重定向到的URL。url需要与当前CRM域名验证 - url至少要与二级域名相同,例如,如果您的CRM在crm.yoursystem.com上可用,任何通过*.yoursystem.com的域名都将被视为有效的重定向URI。

示例

用于启动Apple登录的HTML按钮

<a href="http://crm.press/users/apple/sign">Apple Sign-In</a>

允许在url重定向中的域名

要启用更多域名在url重定向中,请将以下配置添加到您的配置neon文件中

signInRedirectValidator:
    setup:
    	- addAllowedDomains('another.domain.com', 'some.other.domain.net')

安全的登录

必需的Google登录

为了增强安全性,可以要求所有具有管理员角色的用户使用Google登录来登录,如果他们想要访问管理员界面。用户验证安全性随后依赖于Google安全机制来识别潜在的滥用。

要启用此选项(称为“安全登录”)

  • 注册以下事件处理程序到您的内部模块之一,以确保登录过程正确标记登录源(例如,Google)是安全的
    public function registerEventHandlers(\League\Event\Emitter $emitter)
    {
        // ...
        $emitter->addListener(
            \Crm\UsersModule\Events\UserSignInEvent::class,
            $this->getInstance(\Crm\UsersModule\Events\SecureAccessSignInEventHandler::class)
        );
    );
    • 如果您想要更多控制或不同级别的安全性,创建自己的SecureAccessSignInEventHandler并实现您自定义的规则。
  • 检查CRM管理员设置的认证部分并启用安全登录
  • 启用此选项后,每个此类用户都必须通过将secure_login_allowed标志添加到user_meta表中来确认。

双因素认证

目前,尚未实现2FA认证。

数据保留配置

您可以使用(在您的项目配置文件中)配置在哪个时间之前application:cleanup会删除旧的存储库数据和它使用的列

autoLoginTokensRepository:
	setup:
		- setRetentionThreshold('now', 'valid_at')
changePasswordsLogsRepository:
	setup:
		- setRetentionThreshold('-12 months')
userActionsLogRepository:
	setup:
		- setRetentionThreshold('-12 months')

AccessTokenAuthenticator

用户模块为每次成功用户认证生成一个访问令牌。此令牌可用于在API调用中认证用户。

如果您有此类令牌,则可以使用AccessTokenAuthenticator自动将用户登录到CRM。

如何使用

CRM检查是否存在名为n_token的cookie,并从中提取值。如果该值是有效的访问令牌(它仍然存在于access_tokens表中),并且它不属于管理员账户,则它将自动登录用户而无需请求用户名或密码。

这在您的登录过程由其他域名(例如,通过CRM的API在您的CMS中处理)处理,并且您希望用户只登录一次时很有用。

事件

NewUserEvent

NewUserEvent 会在创建所有类型的新用户时触发 - 无论是常规(已声明)用户还是未声明用户。

UserRegisteredEvent

UserRegisteredEvent 在通过 UserBuilder 创建常规用户时触发。未声明用户不被视为常规用户。

如果您在自己的扩展中直接调用 UsersRepository::add 而它是一个常规用户,请确保在处理过程结束时触发 UserRegisteredEvent

UserCreatedEvent

UserCreatedEvent 以前是在用户注册过程中触发的事件。现在已被弃用。请使用 UserRegisteredEvent 和可能的 NewUserEvent 代替。

API 文档

所有示例都使用 http://crm.press 作为基本域名。请在执行示例之前将主机更改为您使用的域名。

所有示例都使用 XXX 作为默认的授权令牌值,请将其替换为实际令牌。

  • API 令牌。 标准的 API 密钥用于服务器之间的通信。它识别整个调用应用程序。它们可以在 CRM 管理员中生成(/api/api-tokens-admin/),并且每个 API 密钥都必须列入白名单才能访问特定的 API 端点。默认情况下,API 密钥没有任何端点的访问权限。
  • 用户令牌。 在登录过程中为每个用户生成,令牌在系统不同部分之间通信时标识单个用户。令牌可以从以下位置读取:
    • n_token cookie 中读取,如果用户通过 CRM 登录。
    • /api/v1/users/login 端点的响应 中读取 - 您可以将响应存储到自己的 cookie/local storage/session 中。

API 响应可以包含以下 HTTP 状态码

如果可能,响应包括 application/json 编码的有效负载,其中包含进一步解释错误的消息。

GET /api/v1/user/info

API 调用根据提供的用户令牌返回基本用户信息和元信息。

头部
示例
curl -v –X GET http://crm.press/api/v1/user/info \
-H "Content-Type:application/json" \
-H "Authorization: Bearer XXX"

响应

{
    "status": "ok",
    "user": {
        "id": 1,
        "uuid": "35e6b53c-340c-4dc3-ad36-f81b2b1f00a8",
        "email": "admin@example.com",
        "confirmed_at": "2021-01-01T10:00:00+01:00", // RFC3339 date or NULL; user confirmation date
        "first_name": "Test",
        "last_name": "Admin"
    },
    "user_meta": {
        "newsletter_subscribed": "1"
    }
}

这是默认的 UserAuthenticator 的响应。如果您的应用程序使用某些自定义的认证器实现(例如 FooAuthenticator),则认证器可以添加额外的参数到响应中

{
    "status": "ok",
    "user": {
        // ...
    },
    "foo": {
        "external_id": "baz",
        "custom_flag": true
    }
}

POST /api/v1/users/login

API 调用验证提供的凭据并返回用户令牌。

参数
示例
curl 'http://crm.press/api/v1/users/login/' \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data 'email=admin%40admin.sk&password=password'

成功响应

{
    "status": "ok",
    "user": {
        "id": 9,
        "uuid": "35e6b53c-340c-4dc3-ad36-f81b2b1f00a8",
        "email": "admin@crm.press",
        "confirmed_at": "2021-01-01T10:00:00+01:00", // RFC3339 date or NULL; user confirmation date
        "first_name": "Test",
        "last_name": "Admin",
        "roles": ["redaktor", "superadmin"] // admin roles
    },
    "user_meta": {
        "key": "value" // string
    },
    "access": {
        "token": "762eec3fe9f20d87cf865cb40cf6458b" // user token
    }
}

无效凭据响应

{
    "status": "error",
    "error": "auth_failed",
    "message": "Zadané heslo sa nezhoduje s našimi záznamami. Prihláste sa, prosím, tak, ako na webe Denníka N."
}

POST /api/v1/users/logout

API 调用用于注销已认证的用户。如果用户使用设备令牌进行认证,则也会移除所有关联的访问令牌。

头部
示例
curl 'http://crm.press/api/v1/users/logout' \
  -H 'Authorization: Bearer 7973a4b16be01e25d9f0759c180911af' \
  -H 'Accept: application/json'

成功响应

{
    "status": "ok"
}

POST /api/v1/users/email (已弃用:请使用 /api/v2/users/email 代替。)

API 调用检查提供的电子邮件地址是否有效并可使用(用于可能的注册)。

此外,它还会检查提供的密码是否适用于给定的电子邮件地址。它不会将用户登录到系统中,也不会返回任何用户令牌,它只会验证如果提供了密码。

参数
示例
curl -v –X GET http://crm.press/api/v1/users/email \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data 'email=admin%40admin.sk'

当电子邮件已被占用时的响应

{
    "email": "admin@crm.press", // String; requested email
    "status": "taken", // String; allowed values ["available", "taken"]
    "id": 9, // Integer; ID of user if email is taken
    "password": null // Boolean; set only if password was provided in request
}

当电子邮件可用时的响应

{
    "email": "admin@admin.cz",
    "status": "available",
    "id": null,
    "password": null
}

POST /api/v2/users/email

API 调用检查提供的电子邮件地址是否有效并可使用(用于可能的注册)。

此外,它还会检查提供的密码是否适用于给定的电子邮件地址。它不会将用户登录到系统中,也不会返回任何用户令牌,它只会验证如果提供了密码。

参数
示例
curl -v –X GET http://crm.press/api/v2/users/email \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data 'email=admin%40admin.sk'

当电子邮件已被占用时的响应

{
    "email": "admin@crm.press", // String; requested email
    "status": "taken", // String; allowed values ["available", "taken"]
    "id": 9, // Integer; ID of user if email is taken
    "password": null // Boolean; set only if password was provided in request
}

当电子邮件可用时的响应

{
    "email": "admin@admin.cz",
    "status": "available",
    "id": null,
    "password": null
}

POST /api/v1/users/email-check

API 调用检查提供的电子邮件地址是否有效并可使用(用于可能的注册)。

头部
参数
示例
curl -v –X GET http://crm.press/api/v1/users/email-check \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data 'email=admin%40admin.sk'

当电子邮件已被占用时的响应

{
    "email": "admin@admin.sk", // String; requested email
    "id": 9, // Integer; ID of user if email is taken
    "status": "taken", // String; allowed values ["available", "taken"]
}

当电子邮件可用时的响应

{
    "email": "admin@admin.cz",
    "status": "available",
}

POST /api/v1/users/create

API 用于将用户注册到系统中。系统将自动生成密码并将其通过电子邮件发送给用户。

当用户注册时,他们会自动登录,并返回用户令牌。

头部
参数
示例
curl -v –X GET http://crm.press/api/v1/users/create \
  -H 'Authorization: Bearer XXX' \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data 'email=user%40user.sk'

成功响应

{
    "status": "ok",
    "user": {
        "id": 101,
        "uuid": "35e6b53c-340c-4dc3-ad36-f81b2b1f00a8",
        "email": "user@crm.press",
        "confirmed_at": "2021-01-01T10:00:00+01:00", // RFC3339 date or NULL; user confirmation date
        "first_name": null,
        "last_name": null,
        "roles": [] // admin roles
    },
    "access": {
        "token": "762eec3fe9f20d87cf865cb40cf6458c" // user token
    }
}

POST /api/v1/users/update

API 用于更新用户信息。

头部
参数
示例
curl -v –X GET http://crm.press/api/v1/users/update \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data 'user_id=42&email=user%40user.sk'

成功响应

{
    "status": "ok",
    "user": {
        "id": 101,
        "email": "user@crm.press",
        "confirmed_at": "2021-01-01T10:00:00+01:00" // RFC3339 date or NULL; user confirmation date
    }
}

GET /api/v1/users/add-to-group

将用户添加到提供的组中。组根据您的任意标准进行人工用户分组。

您可以在 CRM 管理员中列出可用的组,地址为 /users/groups-admin/

头部
参数
示例
curl -X POST http://crm.press/api/v1/users/add-to-group \
  -H 'Authorization: Bearer XXX' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'email=user%40user.sk&group_id=1'

响应

{
    "status": "ok"
}

GET /api/v1/users/remove-from-group

从所选组中删除用户。组根据您的任意标准进行人工用户分组。

您可以在 CRM 管理员中列出可用的组,地址为 /users/groups-admin/

头部
参数
示例
curl -X POST http://crm.press/api/v1/users/remove-from-group \
  -H 'Authorization: Bearer XXX' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'email=user%40user.sk&group_id=1'

响应

{
    "status": "ok"
}

GET /api/v1/users/addresses

列出所有用户地址。用户通过电子邮件地址进行识别。

头部
参数
示例
curl -X GET \
  'http://crm.press/api/v1/users/addresses?email=user@crm.press' \
  -H 'Authorization: Bearer XXX' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'email=user%40user.sk'

响应

{
    "status": "ok",
    "addresses": [
        {
            "user_id": 10, // Integer; ID of user
            "type": "print", // String; type of address
            "created_at": "2019-03-08T11:37:45+01:00", // RFC3339 date; address creation date
            "email": "user@crm.press", // String; email address of user
            "company_name": "", // String; company name
            "phone_number": "0800123456", // String; phone number (not validated)
            "company_id": "", // String: company ID
            "tax_id": "", // String: company tax ID
            "vat_id": "", // String: company vat ID
            "first_name": "Test", // String: first name of address (can be different from user's first name)
            "last_name": "User", // String; last name of address (can be different from user's first name)
            "address": "10th street", // String: street name
            "number": "368", // String; street number
            "zip": "81105", // String: zip code
            "city": "Bratislava", // String; city
            "country": "Slovensko" // String: user-friendly country name (internally represented by reference)
        }
    ]
}

POST /api/v1/users/address

为指定用户创建新的地址。

头部
参数
示例
curl -X POST \
  http://crm.press/api/v1/users/address \
  -H 'Authorization: Bearer XXX' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'email=user%40user.sk&type=invoice&first_name=AdrName&last_name=AdrLastName&address=11th%20str.&number=112&zip=81105&city=Bratislava'

响应

{
    "status": "ok",
    "address": {
        "id": 26929 // Integer; address ID
    }
}

GET /api/v1/user/addresses

列出用户的所有地址。用户通过提供的用户令牌进行识别。

头部
参数
示例
curl -X GET \
  'http://crm.press/api/v1/users/addresses?type=print' \
  -H 'Authorization: Bearer XXX' 

响应

{
    "status": "ok",
    "addresses": { // Object; map of addresses keyed by addressId, value is address represented by single string
        "1235": "John Smith, Václavské náměstí 123, Praha 12345, CZ"
    }
  
}

POST /api/v1/users/change-address-request

为指定类型的地址和用户创建新的地址更改请求。更改请求可能还需要批准。在调用此操作之前,您应该检查给定类型的地址是否存在 - 如果不存在,请首先通过 users/address API 调用来创建地址。

头部
参数
示例
curl -X POST \
  http://crm.press/api/v1/users/change-address-request \
  -H 'Authorization: Bearer XXX' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'email=user%40user.sk&type=print&first_name=AdrName&last_name=AdrLastName&address=11th%20str.&number=112&zip=81105&city=Bratislava'

响应

{
    "status": "ok",
    "address": {
        "id": 26929 // Integer; address ID
    }
}

如果给定类型的地址尚不存在,将返回 HTTP 400 错误,并显示以下消息

{
    "status": "error",
    "message": "Parent address not found"
}

POST /api/v1/users/list

列出请求用户的详细信息(通过用户 ID 识别)。端点需要包含分页参数,并按每 1000 个用户分页结果。

匿名用户将从列表中排除。可以通过使用 include_deactivated 标志来包含已停用的用户。

头部
参数
示例
curl -X POST \
  http://crm.press/api/v1/users/list \
  -H 'Authorization: Bearer XXX' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'user_ids=%5B9%2C10%5D&page=1'

响应

{
    "status": "ok",
    "page": 1, // Integer; requested page number
    "totalPages": 1, // Integer; total page count
    "totalCount": 2, // Integer; total record count
    "users": { // Object; map of users keyed by userId with value object containing user data
        "9": {
            "id": 9, // Integer; ID of user
            "email": "admin@crm.press" // String; email of user
        },
        "10": {
            "id": 10,
            "email": "user@crm.press"
        }
    }
}

POST /api/v1/users/confirm

根据给定的电子邮件地址确认用户。

头部
参数
示例
curl -X POST \
  http://crm.press/api/v1/users/confirm \
  -H 'Authorization: Bearer XXX' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d email=admin%40admin.sk

响应

{
    "status": "ok"
}

如果不存在具有给定电子邮件地址的用户,将返回 HTTP 404 错误,并显示以下代码

{
    "status": "error",
    "code": "user_not_found"
}

POST /api/v1/user/delete

删除个人数据并使账户匿名。如果账户无法删除,则返回 HTTP 403。

头部
示例
curl -X POST \
  http://crm.press/api/v1/user/delete \
  -H 'Authorization: Bearer XXX' \
  -H 'Cache-Control: no-cache'

响应

  • 204:当用户被删除时返回。不返回正文。

  • 403:当用户无法被删除时返回

    {
      "status": "error",
      "code": "user_delete_protected",
      "message": "Unable to delete user due to system protection configuration",
      "reason": "Account cannot be deleted automatically. Please contact customer support." // reason why the deletion wasn't executed, can be displayed to the user (it's translated)
    }

GET /api/v1/users/touch

API 调用刷新缓存的用户数据。

头部
示例
curl -v –X GET http://crm.press/api/v1/users/touch \
-H "Authorization: Bearer XXX"

响应

{
    "status": "ok",
    "message": "User touched"
}

用户元信息 API

元用户信息概念是为了提供一种方法,以存储与用户相关的数据,而无需更改数据库结构。

用户元信息存储为 - 对,并遵循以下两个规则

  • 一个值对应一个键
  • 一个用户有更多唯一的键

公共属性 (is_public) 定义了元信息对于 CRM 管理的可视组件的可用性以及数据提供者对其他模块的可用性。

POST /api/v1/user-meta/upsert

为给定用户创建或更新元信息。

头部
参数
示例
curl -X POST \
  http://crm.press/api/v1/user-meta/upsert \
  -H 'Authorization: Bearer XXX' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{
    "user_id": 12345,
    "key": "foo",
    "value": "bar",
    "is_public": false
  }'

响应

{
    "key": "foo",
    "value": "bar",
    "is_public": false
}

POST /api/v1/user-meta/list

返回指定用户的全部公开元信息。您可以使用元信息键指定元信息。

头部
参数
示例
curl -X GET \
  http://crm.press/api/v1/user-meta/list?user_id=12345 \
  -H 'Authorization: Bearer XXX' \
  -H 'Accept: application/json'

响应

[
    {
        "user_id": 123,
        "key" : "foo",
        "value" : "bar"
    },
    {
        "user_id": 123,
        "key" : "fooz",
        "value" : "1"
    }
]

POST /api/v1/user-meta/key-users

返回具有指定元信息键和值的全部用户。

头部
参数
示例
curl -X POST \
  http://crm.press/api/v1/user-meta/key-users \
  -H 'Authorization: Bearer XXX' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{
    "key": "foo"
  }'

响应

[
    {
        "user_id" : 1,
        "value" : "bar"
    },
    {
        "user_id" : 2,
        "value" : "friend"
    }
]

POST /api/v1/user-meta/delete

通过键删除用户的元信息。您也可以仅通过特定值删除用户的元信息。

头部
参数
示例
curl -X POST \
  http://crm.press/api/v1/user-meta/delete \
  -H 'Authorization: Bearer XXX' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{
    "user_id": 12345,
    "key": "gdpr"
  }'

POST /api/v1/users/autologin-token-login

API 调用验证提供的自动登录令牌,并返回用户身份和令牌。

参数
示例
curl -X POST \
  http://crm.press/api/v1/users/autologin-token-login \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data 'autologin_token=f8fb5c8d41e454852c0049cfe1031ac1&source=ios_app'

成功响应

{
    "status": "ok",
    "user": {
        "id": 9,
        "uuid": "35e6b53c-340c-4dc3-ad36-f81b2b1f00a8",
        "email": "user@crm.press",
        "confirmed_at": "2021-01-01T10:00:00+01:00", // RFC3339 date or NULL; user confirmation date
        "public_name": "user@crm.press",
        "first_name": "Test",
        "last_name": "User"
    },
    "access": {
        "token": "762eec3fe9f20d87cf865cb40cf6458b" // user token
    }
}

无效令牌响应

{
    "status": "error",
    "message": "Invalid token"
}

POST /api/v1/users/get-device-token

API 调用基于发送的 device_id 生成并返回新的设备令牌。

参数
示例
curl --location --request POST 'http://crm.press:8080/api/v1/users/get-device-token' --form 'device_id=cosijak2'

成功响应

{
    "device_token": "bfc6191c1837ec3600c23036edf35590"
}

POST /api/v1/users/set-email-validated

API 调用验证用户电子邮件地址,如果用户存在。

参数
示例
curl 'http://crm.press/api/v1/users/set-email-validated' \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data 'email=admin%40admin.sk'

成功响应

{
    "status": "ok",
    "message": "Email has been validated",
    "code": "success"
}

无效请求响应

{
    "status": "error",
    "message": "Details about problem",
    "code": "invalid_request"
}

无效电子邮件响应

{
    "status": "error",
    "message": "Email not valid",
    "code": "invalid_param"
}

未分配电子邮件响应

{
    "status": "error",
    "message": "Email isn't assigned to any user",
    "code": "email_not_found",
}

POST /api/v1/users/set-email-invalidated

API 调用验证用户电子邮件地址,如果用户存在。

参数
示例
curl 'http://crm.press/api/v1/users/set-email-invalidated' \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data 'email=admin%40admin.sk'

成功响应

{
    "status": "ok",
    "message": "Email has been invalidated",
    "code": "success"
}

所有其他响应与上述 /validateMail 方法相同

POST /api/v2/users/set-email-validated

API 调用验证存在用户的电子邮件地址。

参数
示例
curl 'http://crm.press/api/v2/users/set-email-validated \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data '{
    "emails": ["john+doe@gmail.com", "name@example.com"]
  }'

成功响应

{
    "status": "ok",
}

POST /api/v2/users/set-email-invalidated

API 调用验证存在用户的电子邮件地址。

参数
示例
curl 'http://crm.press/api/v2/users/set-email-invalidated \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data '{
    "emails": ["john+doe@gmail.com", "name@example.com"]
  }'

成功响应

{
  "status": "ok",
}

POST /api/v1/users/google-token-sign-in

API,用于使用 Google Sign-In ID 令牌进行用户身份验证,如https://developers.google.com/identity/sign-in/web/backend-auth 中所述。端点尝试通过电子邮件地址将 Google 用户与现有用户匹配。如果不存在此类用户,则创建新账户。

参数
示例
curl -v –X POST http://crm.press/users/google-token-sign-in \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data 'id_token=ID_TOKEN_CONTENT&create_access_token=true'

成功响应

{
    "status": "ok",
    "user": {
        "id": 101,
        "uuid": "35e6b53c-340c-4dc3-ad36-f81b2b1f00a8",
        "email": "example_user@gmail.com",
        "created_at": "2021-01-01T10:00:00+01:00", // RFC3339 date; user creation date
        "confirmed_at": "2021-01-01T10:00:00+01:00", // RFC3339 date or NULL; user confirmation date
    },
    "user_meta": {
        "key": "value" // String
    },
    "access": {
        "token": "762eec3fe9f20d87cf865cb40cf6458c" // user token
    }
}

POST /api/v1/users/apple-token-sign-in

使用ID令牌通过Apple Sign-In进行用户身份验证的API。端点尝试使用电子邮件地址将Google用户与现有用户匹配。如果不存在此类用户,则创建新账户。

参数
示例
curl -v –X POST http://crm.press/users/apple-token-sign-in \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Accept: application/json' \
  --data 'id_token=ID_TOKEN_CONTENT&create_access_token=true'

成功响应

{
    "status": "ok",
    "user": {
        "id": 101,
        "uuid": "35e6b53c-340c-4dc3-ad36-f81b2b1f00a8",
        "email": "example_user@gmail.com",
        "created_at": "2021-01-01T10:00:00+01:00", // RFC3339 date; user creation date
        "confirmed_at": "2021-01-01T10:00:00+01:00", // RFC3339 date or NULL; user confirmation date
    },
    "user_meta": {
        "key": "value" // String
    },
    "access": {
        "token": "762eec3fe9f20d87cf865cb40cf6458c" // user token
    }
}

组件

AddressWidget

管理员用户详情地址小部件。

alt text

源代码

如何使用

AutologinTokens

管理员用户详情令牌小部件。

alt text

源代码

如何使用

MonthToDateUsersStatWidget

管理员仪表板单统计小部件。

alt text

源代码

如何使用

MonthUsersSmallBarGraphWidget

管理员用户头部小部件。

alt text

源代码

如何使用

MonthUsersStatWidget

管理员仪表板单统计小部件。

alt text

源代码

如何使用

ActiveRegisteredUsersStatWidget

管理员仪表板单统计小部件。

alt text

源代码

如何使用

TodayUsersStatWidget

管理员仪表板单统计小部件。

alt text

源代码

如何使用

UserActionsLog

管理员用户详情列表组件。

alt text

源代码

如何使用

UserLoginAttempts

管理员用户详情列表组件。

alt text

源代码

如何使用

UserMeta

管理员用户详情列表组件。

alt text

源代码

如何使用

UserPasswordChanges

管理员用户详情列表组件。

alt text

源代码

如何使用

UserSourceAccesses

管理员用户详情列表组件。

alt text

源代码

如何使用

UserTokens

管理员用户详情列表组件。

alt text

源代码

如何使用

DetailWidget

管理员用户详情元数据小部件。

alt text

源代码

如何使用