fix: use configured DN

This commit is contained in:
Philipp Matthias Schaefer 2021-02-27 20:26:16 +01:00
parent 10d5a1c515
commit c824c62929
2 changed files with 13 additions and 4 deletions

View File

@ -14,6 +14,7 @@
//
// You should have received a copy of the GNU General Affero Public License
// along with the WebLDAPPasswd. If not, see <https://www.gnu.org/licenses/>.
use handlebars::Handlebars;
use ldap3::LdapConn;
use ldap3::exop::PasswordModify;
use ldap3::result::{LdapError, Result};
@ -21,6 +22,7 @@ use rocket_contrib::json::Json;
use rocket::post;
use serde_derive::{Deserialize, Serialize};
use serde_json::json;
use crate::context::Context;
@ -45,7 +47,10 @@ pub struct Response {
fn change_password(data: Json<PasswordData>,
context: rocket::State<Context>) -> Result<()> {
let dn = format!("uid={},ou=People,dc=fiveop,dc=de", &data.username);
let dn = Handlebars::new()
.render_template(&context.dn, &json!({"username" : &data.username}))
.expect("Unexpected DN template error. Was tested in config.rs");
let mut ldap = LdapConn::new(&context.ldap_url)?;
ldap

View File

@ -5,8 +5,9 @@ use serde_json::json;
use crate::config::Config;
pub struct Context {
pub ldap_url: String,
pub dn: String,
pub index_html: String,
pub ldap_url: String,
}
impl Context {
@ -19,7 +20,10 @@ impl Context {
config.headline
))?;
Ok(Context{ldap_url: config.ldap_url.clone(),
index_html})
Ok(Context{
dn: config.dn.clone(),
index_html,
ldap_url: config.ldap_url.clone(),
})
}
}