Add API method for email based account registration

This commit is contained in:
Gergely Polonkai 2018-02-28 11:05:12 +01:00
parent 870ee67ab6
commit c218f60ab1
6 changed files with 85 additions and 0 deletions

View File

@ -15,6 +15,7 @@ matrix_api_set_avatar_url
matrix_api_get_display_name matrix_api_get_display_name
matrix_api_set_display_name matrix_api_set_display_name
matrix_api_register_account matrix_api_register_account
matrix_api_register_account_email
matrix_api_set_account_data matrix_api_set_account_data
matrix_api_get_room_tags matrix_api_get_room_tags
matrix_api_delete_room_tag matrix_api_delete_room_tag

View File

@ -45,6 +45,7 @@
* @get_display_name: the virtual function pointer to matrix_api_get_display_name() * @get_display_name: the virtual function pointer to matrix_api_get_display_name()
* @set_display_name: the virtual function pointer to matrix_api_set_display_name() * @set_display_name: the virtual function pointer to matrix_api_set_display_name()
* @register_account: the virtual function pointer to matrix_api_register_account() * @register_account: the virtual function pointer to matrix_api_register_account()
* @register_account_email: the virtual function pointer to matrix_api_register_account_email()
* @set_account_data: the virtual function pointer to matrix_api_set_account_data() * @set_account_data: the virtual function pointer to matrix_api_set_account_data()
* @get_room_tags: the virtual function pointer to matrix_api_get_room_tags() * @get_room_tags: the virtual function pointer to matrix_api_get_room_tags()
* @delete_room_tag: the virtual function pointer to matrix_api_delete_room_tag() * @delete_room_tag: the virtual function pointer to matrix_api_delete_room_tag()
@ -404,6 +405,28 @@ matrix_api_register_account(MatrixAPI *matrix_api,
MATRIX_API_GET_IFACE(matrix_api)->register_account(matrix_api, callback, user_data, account_kind, bind_email, username, password, error); MATRIX_API_GET_IFACE(matrix_api)->register_account(matrix_api, callback, user_data, account_kind, bind_email, username, password, error);
} }
/**
* matrix_api_register_account_email:
* @callback: (scope async): the function to call when the request is finished
*/
void
matrix_api_register_account_email(MatrixAPI *api,
const gchar *id_server,
const gchar *client_secret,
const gchar *email,
guint send_attempt,
MatrixAPICallback callback,
gpointer user_data,
GError **error)
{
g_return_if_fail(api != NULL);
g_return_if_fail(id_server);
g_return_if_fail(client_secret);
g_return_if_fail(email);
MATRIX_API_GET_IFACE(api)->register_account_email(api, callback, user_data, id_server, client_secret, email, send_attempt, error);
}
/** /**
* matrix_api_set_account_data: * matrix_api_set_account_data:
* @api: a #MatrixAPI * @api: a #MatrixAPI

View File

@ -105,6 +105,14 @@ struct _MatrixAPIInterface {
const gchar *username, const gchar *username,
const gchar *password, const gchar *password,
GError **error); GError **error);
void (*register_account_email)(MatrixAPI *api,
MatrixAPICallback callback,
gpointer user_data,
const gchar *id_server,
const gchar *client_secret,
const gchar *email,
guint send_attempt,
GError **error);
void (*set_account_data)(MatrixAPI *api, void (*set_account_data)(MatrixAPI *api,
MatrixAPICallback callback, MatrixAPICallback callback,
gpointer user_data, gpointer user_data,
@ -526,6 +534,14 @@ void matrix_api_register_account(MatrixAPI *api,
MatrixAPICallback callback, MatrixAPICallback callback,
gpointer user_data, gpointer user_data,
GError **error); GError **error);
void matrix_api_register_account_email(MatrixAPI *api,
const gchar *id_server,
const gchar *client_secret,
const gchar *email,
guint send_attempt,
MatrixAPICallback callback,
gpointer user_data,
GError **error);
void matrix_api_set_account_data(MatrixAPI *api, void matrix_api_set_account_data(MatrixAPI *api,
const gchar *user_id, const gchar *user_id,
const gchar *room_id, const gchar *room_id,

View File

@ -2006,6 +2006,48 @@ matrix_http_api_register_account(MatrixAPI *matrix_api, MatrixAPICallback cb, vo
g_hash_table_unref(parms); g_hash_table_unref(parms);
} }
static void
register_account_email(MatrixAPI *api,
MatrixAPICallback callback,
gpointer user_data,
const gchar *id_server,
const gchar *client_secret,
const gchar *email,
guint send_attempt,
GError **error)
{
JsonBuilder *builder;
JsonNode *root_node;
builder = json_builder_new();
json_builder_begin_object(builder);
json_builder_set_member_name(builder, "id_server");
json_builder_add_string_value(builder, id_server);
json_builder_set_member_name(builder, "client_secret");
json_builder_add_string_value(builder, client_secret);
json_builder_set_member_name(builder, "email");
json_builder_add_string_value(builder, email);
json_builder_set_member_name(builder, "send_attempt");
json_builder_add_int_value(builder, send_attempt);
json_builder_end_object(builder);
root_node = json_builder_get_root(builder);
_matrix_http_api_send(MATRIX_HTTP_API(api),
callback, user_data,
CALL_TYPE_API, "POST", "register/email/requestToken",
NULL, NULL, root_node, NULL, FALSE, error);
json_node_unref(root_node);
g_object_unref(builder);
}
static void static void
matrix_http_api_set_account_data(MatrixAPI *matrix_api, MatrixAPICallback cb, void *cb_target, const gchar *user_id, const gchar *room_id, const gchar *event_type, JsonNode *content, GError **error) matrix_http_api_set_account_data(MatrixAPI *matrix_api, MatrixAPICallback cb, void *cb_target, const gchar *user_id, const gchar *room_id, const gchar *event_type, JsonNode *content, GError **error)
{ {
@ -2522,6 +2564,7 @@ matrix_http_api_matrix_api_interface_init(MatrixAPIInterface * iface)
iface->get_display_name = matrix_http_api_get_display_name; iface->get_display_name = matrix_http_api_get_display_name;
iface->set_display_name = matrix_http_api_set_display_name; iface->set_display_name = matrix_http_api_set_display_name;
iface->register_account = matrix_http_api_register_account; iface->register_account = matrix_http_api_register_account;
iface->register_account_email = register_account_email;
iface->set_account_data = matrix_http_api_set_account_data; iface->set_account_data = matrix_http_api_set_account_data;
iface->get_room_tags = matrix_http_api_get_room_tags; iface->get_room_tags = matrix_http_api_get_room_tags;
iface->delete_room_tag = matrix_http_api_delete_room_tag; iface->delete_room_tag = matrix_http_api_delete_room_tag;

View File

@ -70,6 +70,7 @@
* @MATRIX_ERROR_M_THREEPID_AUTH_FAILED: 3rd party authentication failed * @MATRIX_ERROR_M_THREEPID_AUTH_FAILED: 3rd party authentication failed
* @MATRIX_ERROR_M_THREEPID_IN_USE: the provided 3rd party ID is already in use * @MATRIX_ERROR_M_THREEPID_IN_USE: the provided 3rd party ID is already in use
* @MATRIX_ERROR_M_INVALID_USERNAME: the given username is invalid * @MATRIX_ERROR_M_INVALID_USERNAME: the given username is invalid
* @MATRIX_ERROR_M_THREEPID_NOT_FOUND: the provided 3rd party ID is not found
* @MATRIX_ERROR_UNSPECIFIED: no error code was sent by the homeserver. If you see this error, * @MATRIX_ERROR_UNSPECIFIED: no error code was sent by the homeserver. If you see this error,
* that usually indicates a homeserver bug * that usually indicates a homeserver bug
* @MATRIX_ERROR_UNKNOWN_ERROR: an error unknown to this library * @MATRIX_ERROR_UNKNOWN_ERROR: an error unknown to this library

View File

@ -64,6 +64,7 @@ typedef enum {
MATRIX_ERROR_M_THREEPID_AUTH_FAILED, MATRIX_ERROR_M_THREEPID_AUTH_FAILED,
MATRIX_ERROR_M_THREEPID_IN_USE, MATRIX_ERROR_M_THREEPID_IN_USE,
MATRIX_ERROR_M_INVALID_USERNAME, MATRIX_ERROR_M_INVALID_USERNAME,
MATRIX_ERROR_M_THREEPID_NOT_FOUND,
/* Allow for a lot of Matrix.org defined codes. Do not define /* Allow for a lot of Matrix.org defined codes. Do not define
* Matrix-specific error codes after this! */ * Matrix-specific error codes after this! */