Esempio n. 1
0
        public async Task <IActionResult> CallLabServerAsync([FromServices] ILabService labService, int labId, int userId)
        {
            // Retrieve lab data
            var lab = await labService.GetLabAsync(labId, HttpContext.RequestAborted);

            if (lab == null)
            {
                AddStatusMessage(_localizer["CallLabServerAsync:NotFound"], StatusMessageTypes.Error);
                return(await RenderViewAsync());
            }

            // Build authentication string
            var user = await _userService.GetUserAsync(userId, HttpContext.RequestAborted);

            var group = user.GroupId == null ? null : await _userService.GetGroupAsync(user.GroupId ?? -1);

            var authData = new UserLoginRequest
            {
                UserId          = userId,
                UserDisplayName = user.DisplayName,
                GroupId         = group?.Id,
                GroupName       = group?.DisplayName,
                AdminMode       = true
            };
            string authString = new CryptoService(lab.ApiCode).Encrypt(authData.Serialize());

            // Build final URL
            string url = lab.ServerBaseUrl.TrimEnd().TrimEnd('/') + "/auth/login?code=" + authString;

            // Forward to server
            return(Redirect(url));
        }
Esempio n. 2
0
        public async Task <IActionResult> CallLabServerAsync(int labId)
        {
            // Retrieve group ID
            var currentUser = await GetCurrentUserAsync();

            if (currentUser?.GroupId == null)
            {
                AddStatusMessage(_localizer["CallLabServerAsync:NoGroup"], StatusMessageTypes.Error);
                return(await RenderViewAsync());
            }

            // Retrieve lab data
            var lab = await _labService.GetLabAsync(labId, HttpContext.RequestAborted);

            if (lab == null)
            {
                AddStatusMessage(_localizer["CallLabServerAsync:LabNotFound"], StatusMessageTypes.Error);
                return(await RenderViewAsync());
            }

            // Check whether lab is accessible by given group
            DateTime now          = DateTime.Now;
            var      labExecution = await _labExecutionService.GetLabExecutionAsync(currentUser.GroupId.Value, labId, HttpContext.RequestAborted);

            if (labExecution == null || now < labExecution.PreStart)
            {
                AddStatusMessage(_localizer["CallLabServerAsync:LabNotActive"], StatusMessageTypes.Error);
                return(await RenderViewAsync());
            }

            // Build authentication string
            var authData = new UserLoginRequest
            {
                UserId          = currentUser.Id,
                UserDisplayName = currentUser.DisplayName,
                GroupId         = currentUser.GroupId,
                GroupName       = currentUser.Group?.DisplayName,
                AdminMode       = false
            };
            string authString = new CryptoService(lab.ApiCode).Encrypt(authData.Serialize());

            // Build final URL
            string url = lab.ServerBaseUrl.TrimEnd().TrimEnd('/') + "/auth/login?code=" + authString;

            // Forward to server
            return(Redirect(url));
        }