Add password changing functionality
This commit is contained in:
parent
e7c1dd010d
commit
dfff8fca0a
1
doc/TODO
1
doc/TODO
@ -3,6 +3,7 @@ general/other:
|
||||
1:use libmagic to determine file types for uploading?
|
||||
|
||||
matrix:
|
||||
4:string constant lookup tables
|
||||
session:
|
||||
7:server level queries in matrix::session
|
||||
2:capability query
|
||||
|
||||
@ -68,6 +68,7 @@ namespace matrix{
|
||||
void set_useragent(const raii::string_base&);
|
||||
void set_useragent(raii::string&&);
|
||||
|
||||
|
||||
/*
|
||||
* NOT thread safe.
|
||||
* Set the access token for the session and all spawned clients and syncers.
|
||||
@ -109,6 +110,8 @@ namespace matrix{
|
||||
*/
|
||||
bool valid(void)const;
|
||||
|
||||
|
||||
netreturn<void> change_password(const raii::string_base& oldpass, const raii::string_base& newpass);
|
||||
/*
|
||||
* Create a matrix::client which shares login details with this session.
|
||||
* Note the client and session will share memory for generated urls, homeserver, access_token, and
|
||||
|
||||
@ -69,6 +69,21 @@ namespace matrix{
|
||||
bool session::valid(void)const{
|
||||
return m_valid;
|
||||
}
|
||||
netreturn<void> session::change_password(const raii::string_base& oldpass, const raii::string_base& newpass){
|
||||
raii::string reply = _post_curl(raii::string("{}"), m_ses->urls.password(m_ses->homeserver, m_ses->access_token), raii::curl_llist());
|
||||
if(!reply)
|
||||
return _create_netreturn(reply, http_status());
|
||||
raii::rjp_ptr root(rjp_parse(reply));
|
||||
netreturn<void> retval = _create_netreturn(root, http_status());
|
||||
if(!root)
|
||||
return retvl;
|
||||
|
||||
//attempt to change password via username/password login
|
||||
RJP_search_res res = rjp_search_member(root.get(), "session", 0);
|
||||
raii::string request = "{\"new_password\": \"" + raii::json_escape(newpass) + "\",\"auth\":{\"type\":\"m.login.password\",\"session\":\"" + raii::rjp_string(res.value) +"\",\"user\": \"" + raii::json_escape(m_ses->userid) + "\",\"password\":\"" + raii::json_escape(oldpass) + "\"}}";
|
||||
reply = _post_curl(request, m_ses->urls.password(m_ses->homeserver, m_ses->access_token), raii::curl_llist());
|
||||
return _create_netreturn(reply, http_status());
|
||||
}
|
||||
client session::spawn_client(void)const{
|
||||
return client(m_ses);
|
||||
}
|
||||
@ -124,7 +139,7 @@ namespace matrix{
|
||||
_do_login(a.name, a.pass);
|
||||
}
|
||||
raii::string session::_request_access_token(const raii::string_base& name, const raii::string_base& pass, const raii::string_base& loginurl)const{
|
||||
raii::string postdata("{\"type\":\"m.login.password\", \"user\":\"" + raii::json_escape(name) + "\", \"password\":\"" + raii::json_escape(pass) + "\"}");
|
||||
raii::string postdata("{\"type\":\"m.login.password\", \"identifier\":{\"type\":\"m.id.user\",\"user\":\"" + raii::json_escape(name) + "\"}, \"password\":\"" + raii::json_escape(pass) + "\"}");
|
||||
raii::string reply = _post_curl(postdata, loginurl, raii::curl_llist{});
|
||||
return reply;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user