WorkFlowProcessMessage IOperation.Execute(dynamic obj) { IMetadataManager iMetadataManager = new MetadataManager.Contracts.MetadataManager(); IEntityQueryManager _queryManager = new EntityQueryManager(); IEntityResourceManager _iEntityResourceManager = new VPC.Framework.Business.EntityResourceManager.Contracts.EntityResourceManager(); var objWorkFlowProcessMessage = new WorkFlowProcessMessage(); try { objWorkFlowProcessMessage = new WorkFlowProcessMessage { Success = true }; var workFlowProcessProperties = (WorkFlowProcessProperties)obj[0]; var jObject = (JObject)obj[1]; var tenantId = (Guid)obj[2]; var userObj = jObject.Children().FirstOrDefault(t => t.Path.ToLower().Equals("user")); var userJObject = userObj.First().ToObject <JObject> (); var userInfo = EntityMapper <VPC.Entities.EntityCore.Metadata.User> .MapperJObject(userJObject); var tenantCode = _queryManager.GetSpecificIdByQuery(tenantId, workFlowProcessProperties.EntityName, workFlowProcessProperties.resultId, "Code"); userJObject.Add(new JProperty("TenantCode", tenantCode)); var template = _iEntityResourceManager.GetWellKnownTemplate(tenantId, "Emailtemplate", "Tenant", (int)ContextTypeEnum.NewTenantCredential, userJObject); var returnVal = DataUtility.SaveEmail(tenantId, workFlowProcessProperties.UserId, template, userInfo.UserCredential.Username.Value, "NewTenantCredential", InfoType.Tenant); return(objWorkFlowProcessMessage); } catch (System.Exception ex) { _log.Error("TenantEmailPostProcess having exception message" + ex.Message); objWorkFlowProcessMessage.Success = false; objWorkFlowProcessMessage.ErrorMessage = new ErrorMessage { Code = WorkFlowMessage.ApplicationError, Description = ex.Message }; return(objWorkFlowProcessMessage); } }
public bool ForgetPasswordUpdateCredential(LoginInfo login, PasswordPolicy passwordpolicy) { IManagerCredential crd = new ManagerCredential(); ILayoutManager layoutManager = new LayoutManager(); IManagerRole roleManager = new ManagerRole(); if (string.IsNullOrEmpty(login.TenantCode) || string.IsNullOrEmpty(login.UserName)) { return(false); } //Get tenant id with code Guid tenantId = layoutManager.GetTenantId(InfoType.Tenant, login.TenantCode); if (tenantId == Guid.Empty) { return(false); } //Validate UserName var userId = crd.GetUserName(tenantId, login.UserName); if (userId == Guid.Empty) { return(false); } byte[] passwordHash, passwordSalt; Random random = new Random(); int pass = random.Next(1000000); //pass = 111; CreatePasswordHash(pass.ToString(), out passwordHash, out passwordSalt); var userDetails = roleManager.GetUserDetails(tenantId, userId); if (userDetails.Id == Guid.Empty) { return(false); } var credentialData = crd.GetCredential(tenantId, userDetails.Id); IMetadataManager iMetadataManager = new MetadataManager.Contracts.MetadataManager(); var queryFilter = new List <QueryFilter>(); queryFilter.Add(new QueryFilter { FieldName = "TenantId", Operator = "Equal", Value = tenantId.ToString() }); queryFilter.Add(new QueryFilter { FieldName = "InternalId", Operator = "Equal", Value = userDetails.Id.ToString() }); var queryContext = new QueryContext { Fields = "FirstName,LastName,MiddleName,ContactInformation.WorkEmail1", Filters = queryFilter, PageSize = 100, PageIndex = 1 }; // var queryContext = new QueryContext { Fields = "FirstName,LastName", Filters = queryFilter, PageSize = 100, PageIndex = 1 }; IEntityResourceManager _iEntityResourceManager = new VPC.Framework.Business.EntityResourceManager.Contracts.EntityResourceManager(); var dataTableUser = _iEntityResourceManager.GetResultById(tenantId, "user", userDetails.Id, queryContext); var userEntity = EntityMapper <VPC.Entities.EntityCore.Metadata.User> .Mapper(dataTableUser); var jObject = DataUtility.ConvertToJObjectList(dataTableUser); CredentialInfo usercredentialinfo = UserCredentailInfo(login); jObject[0].Add(new JProperty("UserCredential.Username", usercredentialinfo.UserName.ToString())); jObject[0].Add(new JProperty("UserCredential.Password", pass.ToString())); jObject[0].Add(new JProperty("TenantCode", login.TenantCode.ToString())); var emailTemplate = _iEntityResourceManager.GetWellKnownTemplate(tenantId, "emailtemplate", "user", (int)ContextTypeEnum.Forgotpassword, jObject[0]); if (emailTemplate != null && emailTemplate.Body != null) { var isnew = false; if (passwordpolicy != null) { isnew = passwordpolicy.ResetOnFirstLogin.Value; } crd.Update(tenantId, new CredentialInfo { CredentialId = credentialData.CredentialId, ParentId = userDetails.Id, PasswordHash = Convert.ToBase64String(passwordHash), PasswordSalt = Convert.ToBase64String(passwordSalt), IsNew = isnew }); var returnVal = DataUtility.SaveEmail(tenantId, userDetails.Id, emailTemplate, usercredentialinfo.UserName.ToString(), "ForgetPassword", InfoType.User); // SendMail(pass.ToString(),emailTemplate,jdata[0],tenantId,userDetails.Id); } else { return(false); } return(true); }