mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Add command to change password of logged in user
This commit is contained in:
parent
71236a0d5a
commit
b0aea2bcff
@ -2564,6 +2564,19 @@ static struct cmd_t command_defs[] = {
|
||||
CMD_NOEXAMPLES
|
||||
},
|
||||
|
||||
{ "/changepassword",
|
||||
parse_args, 0, 0, NULL,
|
||||
CMD_NOSUBFUNCS
|
||||
CMD_MAINFUNC(cmd_change_password)
|
||||
CMD_NOTAGS
|
||||
CMD_SYN(
|
||||
"/changepassword")
|
||||
CMD_DESC(
|
||||
"Change password of logged in account")
|
||||
CMD_NOARGS
|
||||
CMD_NOEXAMPLES
|
||||
},
|
||||
|
||||
// NEXT-COMMAND (search helper)
|
||||
};
|
||||
|
||||
|
@ -9298,3 +9298,30 @@ cmd_mam(ProfWin* window, const char* const command, gchar** args)
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_change_password(ProfWin* window, const char* const command, gchar** args)
|
||||
{
|
||||
jabber_conn_status_t conn_status = connection_get_status();
|
||||
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are not currently connected.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char* user = connection_get_user();
|
||||
char* passwd = ui_ask_password(false);
|
||||
char* confirm_passwd = ui_ask_password(true);
|
||||
|
||||
if (g_strcmp0(passwd, confirm_passwd) == 0) {
|
||||
iq_register_change_password(user, passwd);
|
||||
} else {
|
||||
cons_show("Aborted! The new password and the confirmed password do not match.");
|
||||
}
|
||||
|
||||
free(user);
|
||||
free(passwd);
|
||||
free(confirm_passwd);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -159,6 +159,7 @@ gboolean cmd_charset(ProfWin* window, const char* const command, gchar** args);
|
||||
gboolean cmd_console(ProfWin* window, const char* const command, gchar** args);
|
||||
gboolean cmd_command_list(ProfWin* window, const char* const command, gchar** args);
|
||||
gboolean cmd_command_exec(ProfWin* window, const char* const command, gchar** args);
|
||||
gboolean cmd_change_password(ProfWin* window, const char* const command, gchar** args);
|
||||
|
||||
gboolean cmd_plugins(ProfWin* window, const char* const command, gchar** args);
|
||||
gboolean cmd_plugins_sourcepath(ProfWin* window, const char* const command, gchar** args);
|
||||
|
@ -451,6 +451,19 @@ connection_get_barejid(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
char*
|
||||
connection_get_user(void)
|
||||
{
|
||||
const char* jid = connection_get_fulljid();
|
||||
char* result;
|
||||
result = strdup(jid);
|
||||
|
||||
char* split = strchr(result, '@');
|
||||
*split = '\0';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
connection_features_received(const char* const jid)
|
||||
{
|
||||
|
@ -149,6 +149,7 @@ static int _room_list_id_handler(xmpp_stanza_t* const stanza, void* const userda
|
||||
static int _command_list_result_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _command_exec_response_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _register_change_password_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
|
||||
static void _iq_free_room_data(ProfRoomInfoData* roominfo);
|
||||
static void _iq_free_affiliation_set(ProfPrivilegeSet* affiliation_set);
|
||||
@ -2616,3 +2617,32 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
iq_register_change_password(const char* const user, const char* const password)
|
||||
{
|
||||
xmpp_ctx_t* const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t* iq = stanza_change_password(ctx, user, password);
|
||||
|
||||
const char* id = xmpp_stanza_get_id(iq);
|
||||
iq_id_handler_add(id, _register_change_password_result_id_handler, NULL, NULL);
|
||||
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
static int
|
||||
_register_change_password_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
{
|
||||
const char* type = xmpp_stanza_get_type(stanza);
|
||||
if (g_strcmp0(type, "error") == 0) {
|
||||
char* error_message = stanza_get_error_message(stanza);
|
||||
cons_show_error("Server error: %s", error_message);
|
||||
log_debug("Password change error: %s", error_message);
|
||||
free(error_message);
|
||||
} else {
|
||||
cons_show("Password successfully changed.");
|
||||
log_debug("Password successfully changed.");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -2739,3 +2739,40 @@ stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const s
|
||||
|
||||
return iq;
|
||||
}
|
||||
|
||||
xmpp_stanza_t*
|
||||
stanza_change_password(xmpp_ctx_t* ctx, const char* const user, const char* const password)
|
||||
{
|
||||
char* id = connection_create_stanza_id();
|
||||
xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
|
||||
free(id);
|
||||
|
||||
xmpp_stanza_t* change_password = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(change_password, STANZA_NAME_QUERY);
|
||||
xmpp_stanza_set_ns(change_password, STANZA_NS_REGISTER);
|
||||
|
||||
xmpp_stanza_t* username_st = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(username_st, STANZA_NAME_USERNAME);
|
||||
xmpp_stanza_t* username_text = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(username_text, user);
|
||||
xmpp_stanza_add_child(username_st, username_text);
|
||||
xmpp_stanza_release(username_text);
|
||||
|
||||
xmpp_stanza_t* password_st = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(password_st, STANZA_NAME_PASSWORD);
|
||||
xmpp_stanza_t* password_text = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(password_text, password);
|
||||
xmpp_stanza_add_child(password_st, password_text);
|
||||
xmpp_stanza_release(password_text);
|
||||
|
||||
xmpp_stanza_add_child(change_password, username_st);
|
||||
xmpp_stanza_release(username_st);
|
||||
|
||||
xmpp_stanza_add_child(change_password, password_st);
|
||||
xmpp_stanza_release(password_st);
|
||||
|
||||
xmpp_stanza_add_child(iq, change_password);
|
||||
xmpp_stanza_release(change_password);
|
||||
|
||||
return iq;
|
||||
}
|
||||
|
@ -116,6 +116,7 @@
|
||||
#define STANZA_NAME_FIN "fin"
|
||||
#define STANZA_NAME_LAST "last"
|
||||
#define STANZA_NAME_AFTER "after"
|
||||
#define STANZA_NAME_USERNAME "username"
|
||||
|
||||
// error conditions
|
||||
#define STANZA_NAME_BAD_REQUEST "bad-request"
|
||||
@ -224,6 +225,7 @@
|
||||
#define STANZA_NS_MAM2 "urn:xmpp:mam:2"
|
||||
#define STANZA_NS_EXT_GAJIM_BOOKMARKS "xmpp:gajim.org/bookmarks"
|
||||
#define STANZA_NS_RSM "http://jabber.org/protocol/rsm"
|
||||
#define STANZA_NS_REGISTER "jabber:iq:register"
|
||||
|
||||
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
|
||||
|
||||
@ -383,6 +385,8 @@ void stanza_free_caps(XMPPCaps* caps);
|
||||
|
||||
xmpp_stanza_t* stanza_create_avatar_retrieve_data_request(xmpp_ctx_t* ctx, const char* stanza_id, const char* const item_id, const char* const jid);
|
||||
|
||||
xmpp_stanza_t* stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const startdate, const char *const lastid);
|
||||
xmpp_stanza_t* stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const startdate, const char* const lastid);
|
||||
|
||||
xmpp_stanza_t* stanza_change_password(xmpp_ctx_t* ctx, const char* const user, const char* const password);
|
||||
|
||||
#endif
|
||||
|
@ -186,6 +186,7 @@ char* connection_get_presence_msg(void);
|
||||
void connection_set_presence_msg(const char* const message);
|
||||
const char* connection_get_fulljid(void);
|
||||
char* connection_get_barejid(void);
|
||||
char* connection_get_user(void);
|
||||
char* connection_create_uuid(void);
|
||||
void connection_free_uuid(char* uuid);
|
||||
#ifdef HAVE_LIBMESODE
|
||||
@ -256,6 +257,7 @@ void iq_http_upload_request(HTTPUpload* upload);
|
||||
void iq_command_list(const char* const target);
|
||||
void iq_command_exec(const char* const target, const char* const command);
|
||||
void iq_mam_request(ProfChatWin* win);
|
||||
void iq_register_change_password(const char* const user, const char* const password);
|
||||
|
||||
EntityCapabilities* caps_lookup(const char* const jid);
|
||||
void caps_close(void);
|
||||
|
@ -62,6 +62,12 @@ connection_get_barejid(void)
|
||||
return mock_ptr_type(char*);
|
||||
}
|
||||
|
||||
char*
|
||||
connection_get_user(void)
|
||||
{
|
||||
return mock_ptr_type(char*);
|
||||
}
|
||||
|
||||
const char*
|
||||
connection_get_domain(void)
|
||||
{
|
||||
@ -393,6 +399,10 @@ void
|
||||
iq_command_exec(const char* const target, const char* const command)
|
||||
{
|
||||
}
|
||||
void
|
||||
iq_register_change_password(const char* const user, const char* const password)
|
||||
{
|
||||
}
|
||||
|
||||
// caps functions
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user