Ejemplo n.º 1
0
        public async Task <IActionResult> ViewApp([FromRoute] string id, ViewAppViewModel model, int page = 1)
        {
            var currentUser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                await model.Recover(currentUser, await _dbContext.Apps.FindAsync(model.AppId), _coreApiService, _appsContainer, _siteService, _eventService, _channelService, _recordsService, page);

                return(View(model));
            }
            var target = await _dbContext.Apps.FindAsync(id);

            if (target == null)
            {
                return(NotFound());
            }
            else if (target.CreatorId != currentUser.Id)
            {
                return(new UnauthorizedResult());
            }
            target.AppName             = model.AppName;
            target.AppDescription      = model.AppDescription;
            target.AppCategory         = model.AppCategory;
            target.AppPlatform         = model.AppPlatform;
            target.EnableOAuth         = model.EnableOAuth;
            target.ForceInputPassword  = model.ForceInputPassword;
            target.ForceConfirmation   = model.ForceConfirmation;
            target.DebugMode           = model.DebugMode;
            target.PrivacyStatementUrl = model.PrivacyStatementUrl;
            target.LicenseUrl          = model.LicenseUrl;
            target.AppDomain           = model.AppDomain;
            target.AppFailCallbackUrl  = model.AppFailCallbackUrl;
            //Permissions
            bool permissionAdded = false;

            target.ViewOpenId          = _ChangePermission(target.ViewOpenId, model.ViewOpenId, ref permissionAdded);
            target.ViewPhoneNumber     = _ChangePermission(target.ViewPhoneNumber, model.ViewPhoneNumber, ref permissionAdded);
            target.ChangePhoneNumber   = _ChangePermission(target.ChangePhoneNumber, model.ChangePhoneNumber, ref permissionAdded);
            target.ConfirmEmail        = _ChangePermission(target.ConfirmEmail, model.ConfirmEmail, ref permissionAdded);
            target.ChangeBasicInfo     = _ChangePermission(target.ChangeBasicInfo, model.ChangeBasicInfo, ref permissionAdded);
            target.ChangePassword      = _ChangePermission(target.ChangePassword, model.ChangePassword, ref permissionAdded);
            target.ChangeGrantInfo     = _ChangePermission(target.ChangeGrantInfo, model.ChangeGrantInfo, ref permissionAdded);
            target.ViewAuditLog        = _ChangePermission(target.ViewAuditLog, model.ViewAuditLog, ref permissionAdded);
            target.ManageSocialAccount = _ChangePermission(target.ManageSocialAccount, model.ManageSocialAccount, ref permissionAdded);
            if (permissionAdded)
            {
                var token = await _appsContainer.AccessToken(target.AppId, target.AppSecret);

                await _coreApiService.DropGrantsAsync(token);
            }
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(ViewApp), new { id = target.AppId, JustHaveUpdated = true }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ViewApp(ViewAppViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                await model.Recover(cuser, await _dbContext.Apps.FindAsync(model.AppId), _coreApiService, _ossApiService, _appsContainer);

                return(View(model));
            }
            var target = await _dbContext.Apps.FindAsync(model.AppId);

            if (target == null)
            {
                return(NotFound());
            }
            else if (target.CreatorId != cuser.Id)
            {
                return(new UnauthorizedResult());
            }
            bool permissionChanged = false;

            target.AppName             = model.AppName;
            target.AppDescription      = model.AppDescription;
            target.EnableOAuth         = model.EnableOAuth;
            target.ForceInputPassword  = model.ForceInputPassword;
            target.ForceConfirmation   = model.ForceConfirmation;
            target.DebugMode           = model.DebugMode;
            target.PrivacyStatementUrl = model.PrivacyStatementUrl;
            target.LicenseUrl          = model.LicenseUrl;
            target.AppDomain           = model.AppDomain;
            //Permissions
            target.ViewOpenId        = _ChangePermission(target.ViewOpenId, model.ViewOpenId, ref permissionChanged);
            target.ViewPhoneNumber   = _ChangePermission(target.ViewPhoneNumber, model.ViewPhoneNumber, ref permissionChanged);
            target.ChangePhoneNumber = _ChangePermission(target.ChangePhoneNumber, model.ChangePhoneNumber, ref permissionChanged);
            target.ConfirmEmail      = _ChangePermission(target.ConfirmEmail, model.ConfirmEmail, ref permissionChanged);
            target.ChangeBasicInfo   = _ChangePermission(target.ChangeBasicInfo, model.ChangeBasicInfo, ref permissionChanged);
            target.ChangePassword    = _ChangePermission(target.ChangePassword, model.ChangePassword, ref permissionChanged);
            target.ChangeGrantInfo   = _ChangePermission(target.ChangeGrantInfo, model.ChangeGrantInfo, ref permissionChanged);
            if (permissionChanged)
            {
                var token = await _appsContainer.AccessToken(target.AppId, target.AppSecret);

                await _coreApiService.DropGrantsAsync(token);
            }
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(ViewApp), new { id = target.AppId, JustHaveUpdated = true }));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> ViewApp(ViewAppViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                await model.Recover(cuser, await _dbContext.Apps.FindAsync(model.AppId), _dbContext);

                return(View(model));
            }
            var _target = await _dbContext.Apps.FindAsync(model.AppId);

            if (_target == null)
            {
                return(NotFound());
            }
            else if (_target.CreaterId != cuser.Id)
            {
                return(new UnauthorizedResult());
            }
            _target.AppName             = model.AppName;
            _target.AppDescription      = model.AppDescription;
            _target.EnableOAuth         = model.EnableOAuth;
            _target.ForceInputPassword  = model.ForceInputPassword;
            _target.ForceConfirmation   = model.ForceConfirmation;
            _target.DebugMode           = model.DebugMode;
            _target.PrivacyStatementUrl = model.PrivacyStatementUrl;
            _target.LicenseUrl          = model.LicenseUrl;
            _target.AppDomain           = model.AppDomain;
            _dbContext.AppPermissions.RemoveRange(_dbContext.AppPermissions.Where(t => t.AppId == _target.AppId));
            foreach (var key in HttpContext.Request.Form.Keys)
            {
                if (key.StartsWith("PermissionStatus") && HttpContext.Request.Form[key] == "on")
                {
                    var pId = Convert.ToInt32(key.Substring("PermissionStatus".Length));
                    _dbContext.AppPermissions.Add(new AppPermission
                    {
                        AppId        = _target.AppId,
                        PermissionId = pId
                    });
                }
            }
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(ViewApp), new { id = _target.AppId, JustHaveUpdated = true }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> ViewApp(ViewAppViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                await model.Recover(cuser, await _dbContext.Apps.FindAsync(model.AppId), _dbContext);

                return(View(model));
            }
            var target = await _dbContext.Apps.FindAsync(model.AppId);

            if (target == null)
            {
                return(NotFound());
            }
            else if (target.CreaterId != cuser.Id)
            {
                return(new UnauthorizedResult());
            }
            target.AppName             = model.AppName;
            target.AppDescription      = model.AppDescription;
            target.EnableOAuth         = model.EnableOAuth;
            target.ForceInputPassword  = model.ForceInputPassword;
            target.ForceConfirmation   = model.ForceConfirmation;
            target.DebugMode           = model.DebugMode;
            target.PrivacyStatementUrl = model.PrivacyStatementUrl;
            target.LicenseUrl          = model.LicenseUrl;
            target.AppDomain           = model.AppDomain;
            target.ViewOpenId          = model.ViewOpenId;
            target.ViewPhoneNumber     = model.ViewPhoneNumber;
            target.ChangePhoneNumber   = model.ChangePhoneNumber;
            target.ConfirmEmail        = model.ConfirmEmail;
            target.ChangeBasicInfo     = model.ChangeBasicInfo;
            target.ChangePassword      = model.ChangePassword;
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(ViewApp), new { id = target.AppId, JustHaveUpdated = true }));
        }