2019-08-03 16:47:52 +00:00
|
|
|
use num_traits::FromPrimitive;
|
2018-12-16 19:00:16 +00:00
|
|
|
use rocket::request::{Form, FormItems, FromForm};
|
2018-10-17 20:25:28 +00:00
|
|
|
use rocket::Route;
|
2018-10-10 18:40:39 +00:00
|
|
|
use rocket_contrib::json::Json;
|
|
|
|
use serde_json::Value;
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-12-07 01:05:45 +00:00
|
|
|
use crate::api::{ApiResult, EmptyResult, JsonResult};
|
2019-08-03 16:47:52 +00:00
|
|
|
use crate::api::core::two_factor::{duo, email, yubikey};
|
|
|
|
use crate::api::core::two_factor::email::EmailTokenData;
|
2018-12-09 16:58:38 +00:00
|
|
|
use crate::auth::ClientIp;
|
2018-12-07 01:05:45 +00:00
|
|
|
use crate::CONFIG;
|
2019-08-03 16:47:52 +00:00
|
|
|
use crate::db::DbConn;
|
|
|
|
use crate::db::models::*;
|
|
|
|
use crate::mail;
|
|
|
|
use crate::util;
|
2018-07-13 13:58:50 +00:00
|
|
|
|
2018-02-10 00:00:55 +00:00
|
|
|
pub fn routes() -> Vec<Route> {
|
2018-07-12 19:46:50 +00:00
|
|
|
routes![login]
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 18:40:39 +00:00
|
|
|
#[post("/connect/token", data = "<data>")]
|
2018-12-16 19:00:16 +00:00
|
|
|
fn login(data: Form<ConnectData>, conn: DbConn, ip: ClientIp) -> JsonResult {
|
2018-10-10 18:40:39 +00:00
|
|
|
let data: ConnectData = data.into_inner();
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-12-16 19:00:16 +00:00
|
|
|
match data.grant_type.as_ref() {
|
|
|
|
"refresh_token" => {
|
|
|
|
_check_is_some(&data.refresh_token, "refresh_token cannot be blank")?;
|
|
|
|
_refresh_login(data, conn)
|
|
|
|
}
|
|
|
|
"password" => {
|
|
|
|
_check_is_some(&data.client_id, "client_id cannot be blank")?;
|
|
|
|
_check_is_some(&data.password, "password cannot be blank")?;
|
|
|
|
_check_is_some(&data.scope, "scope cannot be blank")?;
|
|
|
|
_check_is_some(&data.username, "username cannot be blank")?;
|
|
|
|
|
|
|
|
_check_is_some(&data.device_identifier, "device_identifier cannot be blank")?;
|
|
|
|
_check_is_some(&data.device_name, "device_name cannot be blank")?;
|
|
|
|
_check_is_some(&data.device_type, "device_type cannot be blank")?;
|
|
|
|
|
|
|
|
_password_login(data, conn, ip)
|
|
|
|
}
|
|
|
|
t => err!("Invalid type", t),
|
2018-06-01 13:08:03 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-10-17 20:25:28 +00:00
|
|
|
fn _refresh_login(data: ConnectData, conn: DbConn) -> JsonResult {
|
2018-06-01 13:08:03 +00:00
|
|
|
// Extract token
|
2018-10-17 20:25:28 +00:00
|
|
|
let token = data.refresh_token.unwrap();
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-06-01 13:08:03 +00:00
|
|
|
// Get device by refresh token
|
2018-10-17 20:25:28 +00:00
|
|
|
let mut device = match Device::find_by_refresh_token(&token, &conn) {
|
2018-06-01 13:08:03 +00:00
|
|
|
Some(device) => device,
|
2018-07-12 19:46:50 +00:00
|
|
|
None => err!("Invalid refresh token"),
|
2018-06-01 13:08:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// COMMON
|
|
|
|
let user = User::find_by_uuid(&device.user_uuid, &conn).unwrap();
|
|
|
|
let orgs = UserOrganization::find_by_user(&user.uuid, &conn);
|
|
|
|
|
|
|
|
let (access_token, expires_in) = device.refresh_tokens(&user, orgs);
|
2018-12-19 20:52:53 +00:00
|
|
|
|
|
|
|
device.save(&conn)?;
|
|
|
|
Ok(Json(json!({
|
|
|
|
"access_token": access_token,
|
|
|
|
"expires_in": expires_in,
|
|
|
|
"token_type": "Bearer",
|
|
|
|
"refresh_token": device.refresh_token,
|
2019-05-20 19:24:29 +00:00
|
|
|
"Key": user.akey,
|
2018-12-19 20:52:53 +00:00
|
|
|
"PrivateKey": user.private_key,
|
|
|
|
})))
|
2018-06-01 13:08:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-09 16:58:38 +00:00
|
|
|
fn _password_login(data: ConnectData, conn: DbConn, ip: ClientIp) -> JsonResult {
|
2018-06-01 13:08:03 +00:00
|
|
|
// Validate scope
|
2018-10-17 20:25:28 +00:00
|
|
|
let scope = data.scope.as_ref().unwrap();
|
2018-06-01 13:08:03 +00:00
|
|
|
if scope != "api offline_access" {
|
|
|
|
err!("Scope not supported")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the user
|
2018-10-17 20:25:28 +00:00
|
|
|
let username = data.username.as_ref().unwrap();
|
2018-06-01 13:08:03 +00:00
|
|
|
let user = match User::find_by_mail(username, &conn) {
|
|
|
|
Some(user) => user,
|
2018-12-19 20:52:53 +00:00
|
|
|
None => err!(
|
|
|
|
"Username or password is incorrect. Try again",
|
|
|
|
format!("IP: {}. Username: {}.", ip.ip, username)
|
|
|
|
),
|
2018-06-01 13:08:03 +00:00
|
|
|
};
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-06-01 13:08:03 +00:00
|
|
|
// Check password
|
2018-10-17 20:25:28 +00:00
|
|
|
let password = data.password.as_ref().unwrap();
|
2018-06-01 13:08:03 +00:00
|
|
|
if !user.check_valid_password(password) {
|
2018-12-19 20:52:53 +00:00
|
|
|
err!(
|
|
|
|
"Username or password is incorrect. Try again",
|
|
|
|
format!("IP: {}. Username: {}.", ip.ip, username)
|
|
|
|
)
|
2018-06-01 13:08:03 +00:00
|
|
|
}
|
2018-07-12 19:46:50 +00:00
|
|
|
|
2019-07-25 18:47:58 +00:00
|
|
|
let (mut device, new_device) = get_device(&data, &conn, &user);
|
2019-07-22 06:26:24 +00:00
|
|
|
|
2019-02-20 16:54:18 +00:00
|
|
|
let twofactor_token = twofactor_auth(&user.uuid, &data, &mut device, &conn)?;
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2019-07-25 18:47:58 +00:00
|
|
|
if CONFIG.mail_enabled() && new_device {
|
|
|
|
mail::send_new_device_logged_in(&user.email, &ip.ip.to_string(), &device.updated_at, &device.name)?
|
|
|
|
}
|
|
|
|
|
2018-06-01 13:08:03 +00:00
|
|
|
// Common
|
2018-02-10 00:00:55 +00:00
|
|
|
let user = User::find_by_uuid(&device.user_uuid, &conn).unwrap();
|
2018-04-24 20:01:55 +00:00
|
|
|
let orgs = UserOrganization::find_by_user(&user.uuid, &conn);
|
|
|
|
|
|
|
|
let (access_token, expires_in) = device.refresh_tokens(&user, orgs);
|
2018-12-19 20:52:53 +00:00
|
|
|
device.save(&conn)?;
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-06-01 13:08:03 +00:00
|
|
|
let mut result = json!({
|
2018-02-10 00:00:55 +00:00
|
|
|
"access_token": access_token,
|
|
|
|
"expires_in": expires_in,
|
|
|
|
"token_type": "Bearer",
|
|
|
|
"refresh_token": device.refresh_token,
|
2019-05-20 19:24:29 +00:00
|
|
|
"Key": user.akey,
|
2018-06-01 13:08:03 +00:00
|
|
|
"PrivateKey": user.private_key,
|
2019-08-04 14:56:39 +00:00
|
|
|
//"TwoFactorToken": "11122233333444555666777888999"
|
2018-06-01 13:08:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if let Some(token) = twofactor_token {
|
|
|
|
result["TwoFactorToken"] = Value::String(token);
|
|
|
|
}
|
|
|
|
|
2018-12-11 20:20:06 +00:00
|
|
|
info!("User {} logged in successfully. IP: {}", username, ip.ip);
|
2018-06-01 13:08:03 +00:00
|
|
|
Ok(Json(result))
|
|
|
|
}
|
|
|
|
|
2019-07-25 18:47:58 +00:00
|
|
|
/// Retrieves an existing device or creates a new device from ConnectData and the User
|
|
|
|
fn get_device(data: &ConnectData, conn: &DbConn, user: &User) -> (Device, bool) {
|
2019-07-22 06:24:19 +00:00
|
|
|
// On iOS, device_type sends "iOS", on others it sends a number
|
|
|
|
let device_type = util::try_parse_string(data.device_type.as_ref()).unwrap_or(0);
|
|
|
|
let device_id = data.device_identifier.clone().expect("No device id provided");
|
|
|
|
let device_name = data.device_name.clone().expect("No device name provided");
|
|
|
|
|
|
|
|
let mut new_device = false;
|
|
|
|
// Find device or create new
|
|
|
|
let device = match Device::find_by_uuid(&device_id, &conn) {
|
|
|
|
Some(device) => {
|
|
|
|
// Check if owned device, and recreate if not
|
|
|
|
if device.user_uuid != user.uuid {
|
|
|
|
info!("Device exists but is owned by another user. The old device will be discarded");
|
|
|
|
new_device = true;
|
|
|
|
Device::new(device_id, user.uuid.clone(), device_name, device_type)
|
|
|
|
} else {
|
|
|
|
device
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
new_device = true;
|
|
|
|
Device::new(device_id, user.uuid.clone(), device_name, device_type)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-25 18:47:58 +00:00
|
|
|
(device, new_device)
|
2019-07-22 06:24:19 +00:00
|
|
|
}
|
|
|
|
|
2018-12-30 22:34:31 +00:00
|
|
|
fn twofactor_auth(
|
|
|
|
user_uuid: &str,
|
|
|
|
data: &ConnectData,
|
|
|
|
device: &mut Device,
|
|
|
|
conn: &DbConn,
|
|
|
|
) -> ApiResult<Option<String>> {
|
2019-01-25 17:50:57 +00:00
|
|
|
let twofactors = TwoFactor::find_by_user(user_uuid, conn);
|
2018-07-12 19:46:50 +00:00
|
|
|
|
|
|
|
// No twofactor token if twofactor is disabled
|
2018-09-13 19:55:23 +00:00
|
|
|
if twofactors.is_empty() {
|
2018-07-12 19:46:50 +00:00
|
|
|
return Ok(None);
|
|
|
|
}
|
|
|
|
|
2019-05-20 19:24:29 +00:00
|
|
|
let twofactor_ids: Vec<_> = twofactors.iter().map(|tf| tf.atype).collect();
|
2019-03-03 15:09:15 +00:00
|
|
|
let selected_id = data.two_factor_provider.unwrap_or(twofactor_ids[0]); // If we aren't given a two factor provider, asume the first one
|
2018-07-12 19:46:50 +00:00
|
|
|
|
2018-10-17 20:25:28 +00:00
|
|
|
let twofactor_code = match data.two_factor_token {
|
|
|
|
Some(ref code) => code,
|
2019-03-03 15:09:15 +00:00
|
|
|
None => err_json!(_json_err_twofactor(&twofactor_ids, user_uuid, conn)?),
|
2018-07-12 19:46:50 +00:00
|
|
|
};
|
|
|
|
|
2019-08-04 14:56:39 +00:00
|
|
|
let selected_twofactor = twofactors.into_iter().filter(|tf| tf.atype == selected_id && tf.enabled).nth(0);
|
2018-07-12 19:46:50 +00:00
|
|
|
|
2019-03-03 15:09:15 +00:00
|
|
|
use crate::api::core::two_factor as _tf;
|
|
|
|
use crate::crypto::ct_eq;
|
2018-07-12 19:46:50 +00:00
|
|
|
|
2019-03-03 15:09:15 +00:00
|
|
|
let selected_data = _selected_data(selected_twofactor);
|
|
|
|
let mut remember = data.two_factor_remember.unwrap_or(0);
|
2018-07-12 19:46:50 +00:00
|
|
|
|
2019-03-03 15:09:15 +00:00
|
|
|
match TwoFactorType::from_i32(selected_id) {
|
2019-08-03 16:47:52 +00:00
|
|
|
Some(TwoFactorType::Authenticator) => _tf::totp::validate_totp_code_str(twofactor_code, &selected_data?)?,
|
|
|
|
Some(TwoFactorType::U2f) => _tf::u2f::validate_u2f_login(user_uuid, twofactor_code, conn)?,
|
|
|
|
Some(TwoFactorType::YubiKey) => _tf::yubikey::validate_yubikey_login(twofactor_code, &selected_data?)?,
|
|
|
|
Some(TwoFactorType::Duo) => _tf::duo::validate_duo_login(data.username.as_ref().unwrap(), twofactor_code, conn)?,
|
|
|
|
Some(TwoFactorType::Email) => _tf::email::validate_email_code_str(twofactor_code, &selected_data?)?,
|
2018-07-12 19:46:50 +00:00
|
|
|
|
2019-03-03 15:09:15 +00:00
|
|
|
Some(TwoFactorType::Remember) => {
|
|
|
|
match device.twofactor_remember {
|
|
|
|
Some(ref code) if !CONFIG.disable_2fa_remember() && ct_eq(code, twofactor_code) => {
|
|
|
|
remember = 1; // Make sure we also return the token here, otherwise it will only remember the first time
|
|
|
|
}
|
|
|
|
_ => err_json!(_json_err_twofactor(&twofactor_ids, user_uuid, conn)?),
|
2018-07-12 19:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => err!("Invalid two factor provider"),
|
|
|
|
}
|
|
|
|
|
2019-03-03 15:09:15 +00:00
|
|
|
if !CONFIG.disable_2fa_remember() && remember == 1 {
|
2018-07-12 19:46:50 +00:00
|
|
|
Ok(Some(device.refresh_twofactor_remember()))
|
|
|
|
} else {
|
|
|
|
device.delete_twofactor_remember();
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 15:09:15 +00:00
|
|
|
fn _selected_data(tf: Option<TwoFactor>) -> ApiResult<String> {
|
|
|
|
match tf {
|
|
|
|
Some(tf) => Ok(tf.data),
|
|
|
|
None => err!("Two factor doesn't exist"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 19:46:50 +00:00
|
|
|
fn _json_err_twofactor(providers: &[i32], user_uuid: &str, conn: &DbConn) -> ApiResult<Value> {
|
2018-12-07 01:05:45 +00:00
|
|
|
use crate::api::core::two_factor;
|
2018-07-12 19:46:50 +00:00
|
|
|
|
|
|
|
let mut result = json!({
|
2018-06-01 13:08:03 +00:00
|
|
|
"error" : "invalid_grant",
|
|
|
|
"error_description" : "Two factor required.",
|
2018-07-12 19:46:50 +00:00
|
|
|
"TwoFactorProviders" : providers,
|
|
|
|
"TwoFactorProviders2" : {} // { "0" : null }
|
|
|
|
});
|
|
|
|
|
|
|
|
for provider in providers {
|
|
|
|
result["TwoFactorProviders2"][provider.to_string()] = Value::Null;
|
|
|
|
|
|
|
|
match TwoFactorType::from_i32(*provider) {
|
|
|
|
Some(TwoFactorType::Authenticator) => { /* Nothing to do for TOTP */ }
|
|
|
|
|
2019-01-25 17:23:51 +00:00
|
|
|
Some(TwoFactorType::U2f) if CONFIG.domain_set() => {
|
2019-08-03 16:47:52 +00:00
|
|
|
let request = two_factor::u2f::generate_u2f_login(user_uuid, conn)?;
|
2018-07-12 19:46:50 +00:00
|
|
|
let mut challenge_list = Vec::new();
|
|
|
|
|
|
|
|
for key in request.registered_keys {
|
2019-04-07 16:58:15 +00:00
|
|
|
challenge_list.push(json!({
|
|
|
|
"appId": request.app_id,
|
|
|
|
"challenge": request.challenge,
|
|
|
|
"version": key.version,
|
|
|
|
"keyHandle": key.key_handle,
|
|
|
|
}));
|
2018-07-12 19:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let challenge_list_str = serde_json::to_string(&challenge_list).unwrap();
|
|
|
|
|
2019-04-07 16:58:15 +00:00
|
|
|
result["TwoFactorProviders2"][provider.to_string()] = json!({
|
|
|
|
"Challenges": challenge_list_str,
|
|
|
|
});
|
2018-07-12 19:46:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-07 16:58:15 +00:00
|
|
|
Some(TwoFactorType::Duo) => {
|
2019-04-05 20:09:53 +00:00
|
|
|
let email = match User::find_by_uuid(user_uuid, &conn) {
|
|
|
|
Some(u) => u.email,
|
2019-04-07 16:58:15 +00:00
|
|
|
None => err!("User does not exist"),
|
2019-04-05 20:09:53 +00:00
|
|
|
};
|
|
|
|
|
2019-08-03 16:47:52 +00:00
|
|
|
let (signature, host) = duo::generate_duo_signature(&email, conn)?;
|
2019-04-05 20:09:53 +00:00
|
|
|
|
2019-04-07 16:58:15 +00:00
|
|
|
result["TwoFactorProviders2"][provider.to_string()] = json!({
|
2019-04-15 11:06:42 +00:00
|
|
|
"Host": host,
|
2019-04-07 16:58:15 +00:00
|
|
|
"Signature": signature,
|
|
|
|
});
|
2019-04-05 20:09:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-30 22:34:31 +00:00
|
|
|
Some(tf_type @ TwoFactorType::YubiKey) => {
|
|
|
|
let twofactor = match TwoFactor::find_by_user_and_type(user_uuid, tf_type as i32, &conn) {
|
2018-11-17 08:25:07 +00:00
|
|
|
Some(tf) => tf,
|
|
|
|
None => err!("No YubiKey devices registered"),
|
|
|
|
};
|
|
|
|
|
2019-08-03 16:47:52 +00:00
|
|
|
let yubikey_metadata: yubikey::YubikeyMetadata = serde_json::from_str(&twofactor.data)?;
|
2018-11-17 08:25:07 +00:00
|
|
|
|
2019-04-07 16:58:15 +00:00
|
|
|
result["TwoFactorProviders2"][provider.to_string()] = json!({
|
|
|
|
"Nfc": yubikey_metadata.Nfc,
|
|
|
|
})
|
2018-07-12 19:46:50 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 14:56:39 +00:00
|
|
|
Some(tf_type @ TwoFactorType::Email) => {
|
|
|
|
let twofactor = match TwoFactor::find_by_user_and_type(user_uuid, tf_type as i32, &conn) {
|
|
|
|
Some(tf) => tf,
|
|
|
|
None => err!("No twofactor email registered"),
|
|
|
|
};
|
2019-08-03 16:47:52 +00:00
|
|
|
|
|
|
|
let email_data = EmailTokenData::from_json(&twofactor.data)?;
|
|
|
|
|
|
|
|
result["TwoFactorProviders2"][provider.to_string()] = json!({
|
|
|
|
"Email": email::obscure_email(&email_data.Email),
|
|
|
|
})
|
2019-08-04 14:56:39 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 19:46:50 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(result)
|
2018-06-01 13:08:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 19:00:16 +00:00
|
|
|
#[derive(Debug, Clone, Default)]
|
2018-10-17 20:25:28 +00:00
|
|
|
#[allow(non_snake_case)]
|
2018-02-10 00:00:55 +00:00
|
|
|
struct ConnectData {
|
2018-12-16 19:00:16 +00:00
|
|
|
grant_type: String, // refresh_token, password
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-10-17 20:25:28 +00:00
|
|
|
// Needed for grant_type="refresh_token"
|
|
|
|
refresh_token: Option<String>,
|
|
|
|
|
|
|
|
// Needed for grant_type="password"
|
|
|
|
client_id: Option<String>, // web, cli, desktop, browser, mobile
|
|
|
|
password: Option<String>,
|
|
|
|
scope: Option<String>,
|
|
|
|
username: Option<String>,
|
|
|
|
|
|
|
|
device_identifier: Option<String>,
|
|
|
|
device_name: Option<String>,
|
|
|
|
device_type: Option<String>,
|
|
|
|
|
|
|
|
// Needed for two-factor auth
|
|
|
|
two_factor_provider: Option<i32>,
|
|
|
|
two_factor_token: Option<String>,
|
|
|
|
two_factor_remember: Option<i32>,
|
2018-07-12 19:46:50 +00:00
|
|
|
}
|
2018-02-15 18:05:57 +00:00
|
|
|
|
2018-12-16 19:00:16 +00:00
|
|
|
impl<'f> FromForm<'f> for ConnectData {
|
|
|
|
type Error = String;
|
|
|
|
|
|
|
|
fn from_form(items: &mut FormItems<'f>, _strict: bool) -> Result<Self, Self::Error> {
|
|
|
|
let mut form = Self::default();
|
|
|
|
for item in items {
|
|
|
|
let (key, value) = item.key_value_decoded();
|
|
|
|
let mut normalized_key = key.to_lowercase();
|
|
|
|
normalized_key.retain(|c| c != '_'); // Remove '_'
|
|
|
|
|
|
|
|
match normalized_key.as_ref() {
|
|
|
|
"granttype" => form.grant_type = value,
|
|
|
|
"refreshtoken" => form.refresh_token = Some(value),
|
|
|
|
"clientid" => form.client_id = Some(value),
|
|
|
|
"password" => form.password = Some(value),
|
|
|
|
"scope" => form.scope = Some(value),
|
|
|
|
"username" => form.username = Some(value),
|
|
|
|
"deviceidentifier" => form.device_identifier = Some(value),
|
|
|
|
"devicename" => form.device_name = Some(value),
|
|
|
|
"devicetype" => form.device_type = Some(value),
|
|
|
|
"twofactorprovider" => form.two_factor_provider = value.parse().ok(),
|
|
|
|
"twofactortoken" => form.two_factor_token = Some(value),
|
|
|
|
"twofactorremember" => form.two_factor_remember = value.parse().ok(),
|
|
|
|
key => warn!("Detected unexpected parameter during login: {}", key),
|
|
|
|
}
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
2018-12-16 19:00:16 +00:00
|
|
|
|
|
|
|
Ok(form)
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-17 20:25:28 +00:00
|
|
|
fn _check_is_some<T>(value: &Option<T>, msg: &str) -> EmptyResult {
|
|
|
|
if value.is_none() {
|
|
|
|
err!(msg)
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
2018-10-17 20:25:28 +00:00
|
|
|
Ok(())
|
2018-02-17 19:47:13 +00:00
|
|
|
}
|