public CPApiController(ILogs logs , IConfiguration configuration , CPMenuService menuService , CPUserService userService , CPRoleService roleService , CPLangService langService , Security security , ModLessonService lessonService , ModLessonPartService lessonPartService , ModLessonExtendService lessonExtendService , ModLessonPartAnswerService answerService , CPLoginLogService loginLogService , FileProcess fileProcess) { _configuration = configuration; _logs = logs; _menu = new WebMenu(); _security = security; _menuService = menuService; _userService = userService; _roleService = roleService; _langService = langService; _lessionService = lessonService; _lessionPartService = lessonPartService; _lessionExtendService = lessonExtendService; _loginLogService = loginLogService; _answerService = answerService; _fileProcess = fileProcess; _currentLang = StartUp.CurrentLang; _currentUser = StartUp.CurrentUser; }
public CPAccountsController(IHostingEnvironment environment) { _hostingEnvironment = environment; _userService = new CPUserService(); _loginLogService = new CPLoginLogService(); _roleService = new CPRoleService(); _ilogs = new Logs(_hostingEnvironment.WebRootPath); }
public CPAccountsController(IHostingEnvironment environment, CPUserService userService, CPLoginLogService loginLogService, CPRoleService roleService) { _hostingEnvironment = environment; _userService = userService; _loginLogService = loginLogService; _roleService = roleService; _ilogs = new Logs(_hostingEnvironment.WebRootPath); }
private static ClaimsPrincipal GetCurrentUser(this HttpContext context) { string token = context.GetValue(Cookies.DefaultLogin, false); if (string.IsNullOrEmpty(token)) { return(null); } else { // neeus co cache var cache = CacheExtends.GetDataFromCache <ClaimsPrincipal>(token); if (cache != null) { return(cache); } // ko co cache var logs = new CPLoginLogService(); string email = logs.GetEmailFromDb(token); if (string.IsNullOrEmpty(email)) { return(null); } else { var account = new CPUserService(); var user = account.GetItemByEmail(email); if (user == null) { return(null); } else { var role = new CPRoleService(); var irole = role.GetItemByID(user.RoleID); if (role == null) { return(null); } var claims = new List <Claim> { new Claim(ClaimTypes.Email, user.Email), new Claim(ClaimTypes.Name, user.Name), new Claim(ClaimTypes.Role, irole.Code), new Claim("RoleID", irole.ID.ToString()) }; var claimsIdentity = new ClaimsIdentity(claims, Cookies.DefaultLogin); var authenProperties = new AuthenticationProperties { IsPersistent = true, ExpiresUtc = DateTime.UtcNow.AddMinutes(Cookies.ExpiresLogin) }; ClaimsPrincipal claim = new ClaimsPrincipal(); claim.AddIdentity(claimsIdentity); CacheExtends.SetObjectFromCache(token, Cookies.ExpiresLogin, claim); return(claim); } } } }