public ActionResult Edit(long id, Roles roleId) { var currentSession = _sessionContext.UserSession.CurrentOrganizationRole; if (currentSession.UserId == id && currentSession.RoleId == (long)roleId) { var profileEditModel = _userProfileService.GetProfileEditModel(id); if (string.IsNullOrEmpty(profileEditModel.Secret)) { string secret = "", enc = ""; secret = TimeBasedOneTimePassword.GenerateSecret(out enc); TempData["EncodedSecret"] = secret; profileEditModel.EncodedSecret = enc; } else { TempData["EncodedSecret"] = profileEditModel.Secret; profileEditModel.EncodedSecret = TimeBasedOneTimePassword.EncodeSecret(profileEditModel.Secret); } if (roleId == Roles.Technician) { var technicianProfile = _technicianRepository.GetTechnician(currentSession.OrganizationRoleUserId); profileEditModel.TechnicianPin = technicianProfile != null ? technicianProfile.Pin : "0000"; } return(View(profileEditModel)); } Response.RedirectUser("/Home/UnauthorizeAccess"); return(null); }
public MobileResponseModel Post([FromBody] UserLoginModel model) { var authenticationModel = new MobileResponseModel { IsSuccess = false }; if (string.IsNullOrEmpty(model.Password) || string.IsNullOrEmpty(model.UserName) || string.IsNullOrEmpty(model.DeviceKey)) { authenticationModel.Message = "UserName or Password can not be empty"; return(authenticationModel); } var isValid = _userLoginRepository.ValidateUser(model.UserName, model.Password); if (isValid) { try { var userSession = _userLoginService.GetUserSessionModel(model.UserName); if (userSession.CurrentOrganizationRole == null) { authenticationModel.Message = "Your default role has been removed. Please contact your administrator."; return(authenticationModel); } if (!userSession.CurrentOrganizationRole.CheckRole((long)Roles.Technician) && !userSession.CurrentOrganizationRole.CheckRole((long)Roles.NursePractitioner)) { authenticationModel.Message = "Your default role must be Technician or Nurse Practitioner. Please contact your administrator."; return(authenticationModel); } int pinExpirationDays = 0; Int32.TryParse(_configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.PinExpirationDays), out pinExpirationDays); int daysBeforAlert = 0; Int32.TryParse(_configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.AlertBeforePinExpirationInDays), out daysBeforAlert); var pinExpireInDays = _technicianRepository.GetPinExpireInDays(userSession.CurrentOrganizationRole.OrganizationRoleUserId, pinExpirationDays); if (pinExpireInDays <= daysBeforAlert) { pinExpireInDays = pinExpireInDays <= 0 ? 0 : pinExpireInDays; } _sessionContext.UserSession = userSession; var loggedInUser = _userRepository.GetUser(userSession.UserId); _sessionContext.LastLoggedInTime = loggedInUser.UserLogin.LastLogged.ToString(); _userLoginRepository.UpdateLoginStatus(_sessionContext.UserSession.UserId, true); var sessionId = Guid.NewGuid().ToString(); var userLoginLog = SaveLoginInfo(userSession.UserId, sessionId, model.DeviceKey); _sessionContext.UserSession.UserLoginLogId = userLoginLog.Id; var technicianProfile = new Technician(); if (_sessionContext.UserSession.AvailableOrganizationRoles.Any(x => x.RoleId == (long)Roles.Technician)) { var technicianOrgRoleUserId = _sessionContext.UserSession.AvailableOrganizationRoles.First(x => x.RoleId == (long)Roles.Technician).OrganizationRoleUserId; technicianProfile = _technicianRepository.GetTechnician(technicianOrgRoleUserId); } authenticationModel = new MobileResponseModel { IsSuccess = true, Message = "Successfully Logged In", StatusCode = 200, Data = new AuthenticationModel { UserId = userSession.UserId,//Todo: need to check if OrgRoleUserID Can be Sent Token = (sessionId + "_" + userLoginLog.UserId).Encrypt(), Name = userSession.FullName, Role = userSession.CurrentOrganizationRole.RoleDisplayName, Pin = !string.IsNullOrWhiteSpace(technicianProfile.Pin) ? technicianProfile.Pin.Encrypt() : string.Empty, ShowAlertBeforePinExpirationInDays = daysBeforAlert, RemainingDays = pinExpireInDays, } }; } catch (Exception exception) { _logger.Error("while loging user" + exception.StackTrace); authenticationModel.Message = "UserName or Password is not valid"; return(authenticationModel); } } else { _logger.Warn("Tried to access with invalid cridential"); authenticationModel.Message = "UserName or Password is not valid"; return(authenticationModel); } return(authenticationModel); }
public UserEditModel Get(long id) { var user = _userRepository.GetUser(id); var orgRoles = _orgRoleUserRepository.GetOrganizationRoleUserCollectionforaUser(user.Id); var orgs = _organizationRepository.GetAllOrganizationsforUser(user.Id); var roles = _roleRepository.GetAll(); var userEditModel = Mapper.Map <User, UserEditModel>(user); userEditModel.UsersRoles = _organizationRoleUserModelFactory.CreateMulti(user, orgRoles, orgs, roles, null, null); var defaultRole = userEditModel.UsersRoles.FirstOrDefault(x => x.IsDefault); if (defaultRole != null) { var role = _roleRepository.GetByRoleId(defaultRole.RoleId); if (user.UserLogin.IsTwoFactorAuthrequired == null) { userEditModel.IsTwoFactorAuthrequired = role.IsTwoFactorAuthrequired; userEditModel.OverRideTwoFactorAuthrequired = false; } else { userEditModel.IsTwoFactorAuthrequired = user.UserLogin.IsTwoFactorAuthrequired.Value; if (user.UserLogin.IsTwoFactorAuthrequired.Value) { userEditModel.OverRideTwoFactorAuthrequired = true; } else { userEditModel.OverRideTwoFactorAuthrequired = role.IsTwoFactorAuthrequired; } } } foreach (var organizationRoleUser in orgRoles) { var roleId = GetParentRoleIdByRoleId(organizationRoleUser.RoleId); switch (roleId) { case (long)Roles.Technician: var technician = _technicianRepository.GetTechnician(organizationRoleUser.Id); userEditModel.TechnicianProfile = Mapper.Map <Technician, TechnicianModel>(technician); break; case (long)Roles.MedicalVendorUser: var states = _stateRepository.GetAllStates(); var physician = _physicianRepository.GetPhysician(organizationRoleUser.Id); userEditModel.PhysicianProfile = Mapper.Map <Physician, PhysicianModel>(physician); if (physician.AuthorizedStateLicenses != null && physician.AuthorizedStateLicenses.Count() > 0) { userEditModel.PhysicianProfile.Licenses = _physicianLicenseModelFactory.CreateMultiple(physician.AuthorizedStateLicenses, states); } break; case (long)Roles.CorporateAccountCoordinator: var accountCoordinator = _accountCoordinatorProfileRepository.GetAccountCoordinatorProfile(organizationRoleUser.Id); userEditModel.AccountCoordinatorProfile = Mapper.Map <AccountCoordinatorProfile, AccountCoordinatorProfileModel>(accountCoordinator); break; /*case (long)Roles.CallCenterRep: * var callCenterRepProfile = _callCenterRepProfileRepository.Get(organizationRoleUser.Id); * userEditModel.CallCenterAgentProfile = new CallCenterAgentProfileModel { DialerUrl = callCenterRepProfile != null ? callCenterRepProfile.DialerUrl : "" }; * break;*/ } } foreach (var usersRole in userEditModel.UsersRoles) { if (usersRole.CheckRole(usersRole.RoleId)) { var callCenterRepProfile = _callCenterRepProfileRepository.Get(usersRole.OrganizationRoleUserId); usersRole.DialerUrl = callCenterRepProfile != null && !string.IsNullOrEmpty(callCenterRepProfile.DialerUrl) ? callCenterRepProfile.DialerUrl : string.Empty; } } var userNpiInfo = _userNpiInfoRepository.Get(id); if (userNpiInfo != null) { userEditModel.Npi = userNpiInfo.Npi ?? string.Empty; userEditModel.Credential = userNpiInfo.Credential ?? string.Empty; } else { userEditModel.Npi = string.Empty; userEditModel.Credential = string.Empty; } var systemUserInfo = _systemUserInfoRepository.Get(id); if (systemUserInfo != null) { userEditModel.EmployeeId = systemUserInfo.EmployeeId; } return(userEditModel); }