public Claim[] AuthenticateUser(LoginInfo login) { IManagerCredential crd = new ManagerCredential(); ILayoutManager layoutManager = new LayoutManager(); IManagerRole roleManager = new ManagerRole(); if (string.IsNullOrEmpty(login.TenantCode) || string.IsNullOrEmpty(login.UserName) || string.IsNullOrEmpty(login.Password)) { return(null); } //Get tenant id with code Guid tenantId = layoutManager.GetTenantId(InfoType.Tenant, login.TenantCode); if (tenantId == Guid.Empty) { return(null); } //Validate UserName var userId = crd.GetUserName(tenantId, login.UserName); if (userId == Guid.Empty) { return(null); } //Validate UserName var passwordSaved = crd.GetPassword(tenantId, login.UserName); if (passwordSaved == null) { return(null); } // check if password is correct if (!VerifyPasswordHash(login.Password, Convert.FromBase64String(passwordSaved.PasswordHash), Convert.FromBase64String(passwordSaved.PasswordSalt))) { return(null); } //Get user detail var userDetails = roleManager.GetUserDetails(tenantId, userId); if (userDetails != null) { var claims = new[] { new Claim("UserId", userDetails.Id.ToString()), new Claim("UserName", userDetails.Name), new Claim("TenantId", tenantId.ToString()), new Claim("IsSuperAdmin", userDetails.IsSuperadmin.ToString()), new Claim("IsSystemAdmin", userDetails.IsSystemAdmin.ToString()), new Claim("Jti", Guid.NewGuid().ToString()) }; return(claims); } return(null); }
public Claim[] RevokeAuthorization(Guid tenantId, Guid userId) { IManagerRole roleManager = new ManagerRole(); var userDetails = roleManager.GetUserDetails(tenantId, userId); if (userDetails != null) { var claims = new[] { new Claim("UserId", userDetails.Id.ToString()), new Claim("UserName", userDetails.Name), new Claim("TenantId", tenantId.ToString()), new Claim("IsSuperAdmin", userDetails.IsSuperadmin.ToString()), new Claim("IsSystemAdmin", userDetails.IsSystemAdmin.ToString()), new Claim("Jti", Guid.NewGuid().ToString()) }; return(claims); } return(null); }
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); }