2021-11-29 22:25:35 +00:00
|
|
|
use std::fmt::Debug;
|
|
|
|
|
|
|
|
use epp_client_macros::ElementName;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
use crate::{
|
2021-11-26 22:21:38 +00:00
|
|
|
common::{ElementName, NoExtension, Options, ServiceExtension, Services, StringValue},
|
2021-12-02 10:00:33 +00:00
|
|
|
contact, domain, host,
|
2021-12-06 15:25:11 +00:00
|
|
|
request::{EppExtension, Transaction, EPP_LANG, EPP_VERSION},
|
2021-12-02 13:16:03 +00:00
|
|
|
response::ResponseStatus,
|
2021-11-29 22:25:35 +00:00
|
|
|
};
|
|
|
|
|
2021-11-26 22:21:38 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Login<E> {
|
|
|
|
request: LoginRequest,
|
|
|
|
extension: Option<E>,
|
|
|
|
}
|
|
|
|
|
2021-12-06 15:25:11 +00:00
|
|
|
impl<E: EppExtension> Transaction<E> for Login<E> {
|
2021-11-26 22:21:38 +00:00
|
|
|
type Input = LoginRequest;
|
2021-12-02 13:16:03 +00:00
|
|
|
type Output = ResponseStatus;
|
2021-11-26 22:21:38 +00:00
|
|
|
|
|
|
|
fn into_parts(self) -> (Self::Input, Option<E>) {
|
|
|
|
(self.request, self.extension)
|
|
|
|
}
|
|
|
|
}
|
2021-11-29 22:25:35 +00:00
|
|
|
|
2021-11-26 22:21:38 +00:00
|
|
|
impl<E: EppExtension> Login<E> {
|
2021-11-29 22:25:35 +00:00
|
|
|
pub fn new(
|
|
|
|
username: &str,
|
|
|
|
password: &str,
|
2021-12-03 18:07:36 +00:00
|
|
|
ext_uris: Option<Vec<String>>,
|
2021-11-26 22:21:38 +00:00
|
|
|
) -> Login<NoExtension> {
|
2021-12-03 18:07:36 +00:00
|
|
|
let ext_uris = ext_uris.map(|uris| uris.iter().map(|u| u.as_str().into()).collect());
|
2021-11-29 22:25:35 +00:00
|
|
|
|
2021-11-26 22:21:38 +00:00
|
|
|
Login {
|
|
|
|
request: LoginRequest {
|
|
|
|
username: username.into(),
|
|
|
|
password: password.into(),
|
|
|
|
options: Options {
|
|
|
|
version: EPP_VERSION.into(),
|
|
|
|
lang: EPP_LANG.into(),
|
|
|
|
},
|
|
|
|
services: Services {
|
|
|
|
obj_uris: vec![
|
2021-12-02 10:00:33 +00:00
|
|
|
host::XMLNS.into(),
|
|
|
|
contact::XMLNS.into(),
|
|
|
|
domain::XMLNS.into(),
|
2021-11-26 22:21:38 +00:00
|
|
|
],
|
|
|
|
svc_ext: Some(ServiceExtension { ext_uris }),
|
|
|
|
},
|
2021-11-29 22:25:35 +00:00
|
|
|
},
|
|
|
|
extension: None,
|
2021-11-26 22:21:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_extension<F: EppExtension>(self, extension: F) -> Login<F> {
|
|
|
|
Login {
|
|
|
|
request: self.request,
|
|
|
|
extension: Some(extension),
|
|
|
|
}
|
2021-11-29 22:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets the <options> tag data
|
|
|
|
pub fn options(&mut self, options: Options) {
|
2021-11-26 22:21:38 +00:00
|
|
|
self.request.options = options;
|
2021-11-29 22:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets the <svcs> tag data
|
|
|
|
pub fn services(&mut self, services: Services) {
|
2021-11-26 22:21:38 +00:00
|
|
|
self.request.services = services;
|
2021-11-29 22:25:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)]
|
|
|
|
#[element_name(name = "login")]
|
|
|
|
/// Type corresponding to the <login> tag in an EPP XML login request
|
2021-11-26 22:21:38 +00:00
|
|
|
pub struct LoginRequest {
|
2021-11-29 22:25:35 +00:00
|
|
|
/// The username to use for the login
|
|
|
|
#[serde(rename(serialize = "clID", deserialize = "clID"))]
|
|
|
|
username: StringValue,
|
|
|
|
/// The password to use for the login
|
|
|
|
#[serde(rename = "pw", default)]
|
|
|
|
password: StringValue,
|
|
|
|
/// Data under the <options> tag
|
|
|
|
options: Options,
|
|
|
|
/// Data under the <svcs> tag
|
|
|
|
#[serde(rename = "svcs")]
|
|
|
|
services: Services,
|
|
|
|
}
|