protected override bool Execute() { if (!ReCAPTCHA.Validate(DTO.Captcha)) { Response.error = Label.Get("error.authentication"); return(false); } ActiveDirectory_ADO adAdo = new ActiveDirectory_ADO(); ActiveDirectory_DTO adDto = adAdo.GetUser(Ado, DTO); dynamic adUser = adAdo.GetAdSpecificDataForEmail(DTO.CcnEmail); if (adUser?.CcnEmail != null) { DTO.CcnEmail = adUser.CcnEmail; DTO.CcnDisplayname = adUser.CcnDisplayName; DTO.CcnUsername = adUser.CcnUsername; } else { Account_ADO aAdo = new Account_ADO(); var user = aAdo.Read(Ado, new Account_DTO_Read() { CcnUsername = DTO.CcnEmail }); if (!user.hasData) { Response.data = JSONRPC.success; return(true); } if (user.data[0].CcnEmail.Equals(DBNull.Value) || user.data[0].CcnDisplayName.Equals(DBNull.Value)) { Response.data = JSONRPC.success; return(true); } DTO.CcnDisplayname = user.data[0].CcnDisplayName; DTO.CcnEmail = user.data[0].CcnEmail; DTO.CcnUsername = DTO.CcnEmail; } Login_BSO lBso = new Login_BSO(Ado); ADO_readerOutput output = lBso.ReadByToken2Fa(DTO.LgnToken2Fa, DTO.CcnUsername); if (!output.hasData) { return(false); } //create a 2fa, save it to the database, unlock the account and send the 2fa back to the client to be displayed as a QRCode string token = lBso.Update2FA(new Login_DTO_Create2FA() { LgnToken2Fa = DTO.LgnToken2Fa, CcnUsername = DTO.CcnUsername }); Response.data = token; return(true); }
/// <summary> /// Checks if a user exists in active directory - based on the the ccnUsername parameter /// </summary> /// <param name="ado"></param> /// <param name="username"></param> /// <returns></returns> internal static bool IsInActiveDirectory(ADO ado, string username) { ActiveDirectory_ADO adADO = new ActiveDirectory_ADO(); ActiveDirectory_DTO dto = new ActiveDirectory_DTO(); dto.CcnUsername = username; var result = adADO.GetUser(ado, dto); return(result.CcnUsername != null); }
/// <summary> /// Execute /// </summary> /// <returns></returns> protected override bool Execute() { //A power user may not create an Administrator if (IsPowerUser() && DTO.PrvCode.Equals(Resources.Constants.C_SECURITY_PRIVILEGE_ADMINISTRATOR)) { Log.Instance.Debug("A power user may not create an Administrator"); Response.error = Label.Get("error.privilege"); return(false); } //We need to check if the requested user is NOT in Active Directory, otherwise we refuse the request. ActiveDirectory_ADO adAdo = new ActiveDirectory_ADO(); ActiveDirectory_DTO adDto = adAdo.GetUser(Ado, DTO); if (adDto.CcnUsername != null) { Log.Instance.Debug("Account exists already"); Response.error = Label.Get("error.create"); return(false); } //Validation of parameters and user have been successful. We may now proceed to read from the database var adoAccount = new Account_ADO(); //First we must check if the Account exists already (we can't have duplicates) if (adoAccount.Exists(Ado, DTO.CcnEmail)) { //This Account exists already, we can't proceed Log.Instance.Debug("Account exists already"); Response.error = Label.Get("error.duplicate"); return(false); } //Next check if the email exists if (adoAccount.ExistsByEmail(Ado, DTO.CcnEmail)) { //This Account exists already, we can't proceed Log.Instance.Debug("Account exists already"); Response.error = Label.Get("error.duplicate"); return(false); } //make sure this email isn't an AD email - they should not become local users var aduser = adAdo.GetAdSpecificDataForEmail(DTO.CcnEmail); if (aduser != null) { //This Account exists in AD, we can't proceed Log.Instance.Debug("Account exists in AD"); Response.error = Label.Get("error.create"); return(false); } //Create the Account - and retrieve the newly created Id int newId = adoAccount.Create(Ado, new Account_DTO_Create() { CcnUsername = DTO.CcnUsername, CcnNotificationFlag = DTO.CcnNotificationFlag, LngIsoCode = DTO.LngIsoCode, PrvCode = DTO.PrvCode, CcnDisplayName = DTO.CcnDisplayName, CcnEmail = DTO.CcnEmail }, SamAccountName, false); if (newId == 0) { Log.Instance.Debug("adoAccount.Create - can't create Account"); Response.error = Label.Get("error.create"); return(false); } Login_DTO_Create lDto = new Login_DTO_Create() { CcnUsername = DTO.CcnEmail, LngIsoCode = DTO.LngIsoCode, CcnEmail = DTO.CcnEmail, CcnDisplayname = DTO.CcnDisplayName }; Login_BSO lBso = new Login_BSO(Ado); string token = Utility.GetRandomSHA256(newId.ToString()); if (lBso.CreateLogin(lDto, SamAccountName, token)) { SendEmail(lDto, token, "PxStat.Security.Login_API.Create1FA"); } else { Response.error = Label.Get("error.create"); return(false); } Response.data = JSONRPC.success; return(true); }
/// <summary> /// Execute /// </summary> /// <returns></returns> protected override bool Execute() { if (!ReCAPTCHA.Validate(DTO.Captcha)) { Response.error = Label.Get("error.authentication"); return(false); } if (DTO.CcnUsername == null) { DTO.CcnUsername = DTO.CcnEmail; } //Not allowed for AD users ActiveDirectory_ADO adAdo = new ActiveDirectory_ADO(); ActiveDirectory_DTO adDto = adAdo.GetUser(Ado, DTO); if (adDto.CcnDisplayName != null) { Response.data = JSONRPC.success; return(true); } Account_ADO ccnAdo = new Account_ADO(); var user = ccnAdo.Read(Ado, new Account_DTO_Read() { CcnUsername = DTO.CcnEmail }); if (!user.hasData) { Response.data = JSONRPC.success; return(true); } if (user.data[0].CcnEmail.Equals(DBNull.Value) || user.data[0].CcnDisplayName.Equals(DBNull.Value)) { Response.data = JSONRPC.success; return(true); } DTO.CcnEmail = user.data[0].CcnEmail; Login_BSO lBso = new Login_BSO(Ado); string loginToken = Utility.GetRandomSHA256(user.data[0].CcnId.ToString()); Login_DTO_Create ldto = new Login_DTO_Create() { CcnUsername = DTO.CcnEmail, LngIsoCode = DTO.LngIsoCode, CcnEmail = DTO.CcnEmail, CcnDisplayname = user.data[0].CcnDisplayName }; if (lBso.Update1FaTokenForUser(DTO.CcnEmail, loginToken) != null) { SendEmail(new Login_DTO_Create() { CcnUsername = user.data[0].CcnUsername, LngIsoCode = DTO.LngIsoCode, CcnEmail = user.data[0].CcnEmail, CcnDisplayname = user.data[0].CcnDisplayName }, loginToken, "PxStat.Security.Login_API.Update1FA"); Response.data = JSONRPC.success; return(true); } else { Response.error = Label.Get("error.create"); return(false); } }