Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login Form No Longer Popping Up #1143

Closed
slip13420 opened this issue Sep 3, 2021 · 10 comments
Closed

Login Form No Longer Popping Up #1143

slip13420 opened this issue Sep 3, 2021 · 10 comments

Comments

@slip13420
Copy link

slip13420 commented Sep 3, 2021

So this is a weird one. Using the example of setting the page to Single Site Mode, and Integrate Silex with your infrastructure, I was able to have login-form.html pop-up sometimes. However it now never pops up. Not sure what I'm doing wrong. If I however manually browse to lgin-form.html, it redirects to /ce/custom-service/login_callback fine and then I'm able to login to the app. Index.js looks like this...

'use strict';

var serveStatic = require('serve-static')
const path = require('path');
const { SilexServer, Config } = require('silex-website-builder');
const CustomProvider = require('./custom-hosting-provider');


const config = new Config();

// provide only our custom hosting to user when they want to publish
config.publisherOptions.skipHostingSelection = true;
config.publisherOptions.enableHostingUnifile = false;

// disable other services
config.ceOptions.enableSftp = false;

const silex = new SilexServer(config);

// add our custom service
const CustomService = require('./custom-service');
silex.unifile.use(new CustomService());

// add our custom hosting provider
silex.publishRouter.addHostingProvider(new CustomProvider(silex.unifile))

// serve modified html
silex.app.use('/', serveStatic(path.resolve('./dist/')));

// define a form to get the user login and password
silex.app.use('/login-form.html', (req, res) => res.sendFile(__dirname + '/login-form.html'));

silex.start(function() {
  console.log('server started');
});

Any help appreciated!

@lexoyo
Copy link
Member

lexoyo commented Sep 4, 2021 via email

@slip13420
Copy link
Author

Ok, thanks I'll have a look. The issue I don't understand though is if I load up in Incognito mode, I still get no login form. Being incognito would mean I'm for sure not logged in. I'll check the network calls.

@slip13420
Copy link
Author

Digging through this a little more I see the session is not logged in and I never see the login page.

Screenshot_20210909_140808

@slip13420
Copy link
Author

I'll add the custom service code as well to see if that helps.

const { FsConnector } = require('unifile');
const save_dir = "/opt/website/";

/**
 * Service connector extends the local filesystem connector (unifile-fs)
 * The root URL will depend on the user name, i.e. in ${ rootUrl }/${ session.user }/
 */
class CustomService extends FsConnector {
  // **
  // extend Fs service
  constructor(config) {
    super(config);
    // change fs infos
    this.name = 'custom-service';
    this.infos.name = 'custom-service';
    this.infos.displayName = 'File System';
    this.infos.description = 'File System Connector';
  }

  // **
  //Auth commands
  getInfos(session) {
    return Object.assign({
      isLoggedIn: !!session.user,
      isOAuth: false,
      username: session.user
    }, this.infos);
  }
  // In this example the form will set a user in the session
  // The form is one specific form for this example
  getAuthorizeURL(session) { return Promise.resolve('/login-form.html') }

  // check authentication
  // and create a root folder for the user
  login(session, loginInfos) {
    if(loginInfos.password === 'password') {
      // store the user
      session.user = loginInfos.user;
      // create the user's directory if it does not exist already
      return this.mkdir(session, '')
      .then(() => this.mkdir(session, 'Website'))
      .catch((e) => session);
    }
    // logout if pass is not correct
    session.user = null;
    return Promise.resolve(session);
  }
  // **
  //Filesystem commands: prepend the user to all paths
  readdir(session, path) { return super.readdir(session, `${ save_dir }${ session.user }/${ path }`) }
  stat(session, path) { return super.stat(session, `${ save_dir }${ session.user }/${ path }`) }
  mkdir(session, path) { return super.mkdir(session, `${ save_dir }${ session.user }/${ path }`) }
  writeFile(session, path, data) { return super.writeFile(session, `${ save_dir }${ session.user }/${ path }`, data) }
  createWriteStream(session, path) { return super.createWriteStream(session, `${ save_dir }${ session.user }/${ path }`) }
  readFile(session, path) { return super.readFile(session, `${ save_dir }${ session.user }/${ path }`) }
  createReadStream(session, path) { return super.createReadStream(session, `${ save_dir }${ session.user }/${ path }`) }
  rename(session, src, dest) { return super.rename(session, src, dest) }
  unlink(session, path) { return super.unlink(session, `${ save_dir }${ session.user }/${ path }`) }
  rmdir(session, path) { return super.rmdir(session, `${ save_dir }${ session.user }/${ path }`) }
  batch(session, actions, message) { return super.batch(session, actions, message) }
}
// export for use in index.js
module.exports = CustomService;

@slip13420
Copy link
Author

Ok, after more testing the issue is it only pops up after you have logged in once. What I mean is if you go incognito or use a browser you haven't used before, you have to manually got to /login-form.html and login first. Then each subsequent load of the page brings up the login form popup correctly. Any ideas?

@lexoyo
Copy link
Member

lexoyo commented Sep 24, 2021

Hi @slip13420
sorry for the delay, are you still working on it?

Ok, after more testing the issue is it only pops up after you have logged in once. What I mean is if you go incognito or use a browser you haven't used before, you have to manually got to /login-form.html and login first. Then each subsequent load of the page brings up the login form popup correctly. Any ideas?

ok i think i understand

the login popin is opened when the user click on your service in the file explorer (https://cloud-explorer.org/)

and then when the file explorer opens up, it tries to reconnect to the last visited service and may open the popup again

maybe what you need is to make sure the user is logged in before opening silex (maybe open another login page which redirects to silex?) or after silex has loaded (add a script to silex html page?)

let me know if i can help

@lexoyo
Copy link
Member

lexoyo commented Sep 24, 2021

also feel free to join the chat if it is easier (not sure)
https://gitter.im/silex-website-builder/community

@lexoyo
Copy link
Member

lexoyo commented Oct 23, 2021

hello @slip13420
any news on this?

@slip13420
Copy link
Author

Sorry man, got hung up on a different project and had to put this one aside for a bit. Probably getting back to it in a week or so.

@lexoyo
Copy link
Member

lexoyo commented Feb 25, 2022

no prob @slip13420 :)
have a nice weekend !

@lexoyo lexoyo closed this as completed Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants