コード例 #1
0
        public ServiceStub <UserServiceStub> Login([FromBody] LogOnViewModel model)
        {
            ServiceStub <UserServiceStub> result = new ServiceStub <UserServiceStub>();

            if (ModelState.IsValid)
            {
                string deviceId = model.DeviceId;

                //model.Password = AESEncryptionLibrary.EncryptText(model.Password, "M013i1)!9TpD"); //for debugging only, please comment on production
                ActiveDirectoryUtil AdModel = new ActiveDirectoryUtil();
                AdModel.Login(model.UserName, model.Password, model.RememberMe);
                if (AdModel.IsAuthenticated)
                {
                    Request.Headers.Add("token", MD5EncryptionLibrary.MD5Hash(model.UserName));
                    UserServiceStub user = new UserServiceStub()
                    {
                        username = model.UserName,
                        roles    = AdModel.Roles
                    };

                    List <UserServiceStub> users = new List <UserServiceStub>();
                    users.Add(user);

                    result.status  = 200;
                    result.message = "Authorized";
                    result.total   = users.Count;
                    result.data    = users;
                    return(result);
                }
                else
                {
                    result.status  = 400;
                    result.message = "Username or password is invalid/not registered";
                    result.total   = 0;
                    result.data    = new List <UserServiceStub>();
                    return(result);
                }
            }
            else
            {
                result.status  = 400;
                result.message = "Username / password / device id cannot be empty";
                result.total   = 0;
                result.data    = new List <UserServiceStub>();
                return(result);
            }
        }
コード例 #2
0
        private WikiController CreateWikiController(BrowserCacheAttribute attribute)
        {
            // Settings
            ApplicationSettings appSettings = new ApplicationSettings()
            {
                Installed = true, UseBrowserCache = true
            };
            UserContextStub userContext = new UserContextStub()
            {
                IsLoggedIn = false
            };

            // PageService
            PageViewModelCache pageViewModelCache = new PageViewModelCache(appSettings, CacheMock.RoadkillCache);
            ListCache          listCache          = new ListCache(appSettings, CacheMock.RoadkillCache);
            SiteCache          siteCache          = new SiteCache(appSettings, CacheMock.RoadkillCache);
            SearchServiceMock  searchService      = new SearchServiceMock(appSettings, _repositoryMock, _pluginFactory);
            PageHistoryService historyService     = new PageHistoryService(appSettings, _repositoryMock, userContext, pageViewModelCache, _pluginFactory);
            PageService        pageService        = new PageService(appSettings, _repositoryMock, searchService, historyService, userContext, listCache, pageViewModelCache, siteCache, _pluginFactory);

            // WikiController
            SettingsService settingsService = new SettingsService(appSettings, _repositoryMock);
            UserServiceStub userManager     = new UserServiceStub();
            WikiController  wikiController  = new WikiController(appSettings, userManager, pageService, userContext, settingsService);

            // Create a page that the request is for
            Page page = new Page()
            {
                Title = "title", ModifiedOn = _pageModifiedDate
            };

            _repositoryMock.AddNewPage(page, "text", "user", _pageCreatedDate);

            // Update the BrowserCacheAttribute
            attribute.ApplicationSettings = appSettings;
            attribute.Context             = userContext;
            attribute.PageService         = pageService;

            return(wikiController);
        }