We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43198
    • 20 Posts
    Hello,

    I'am searching for a solution to login at frontend via emaillink.

    I want to link to a member access resource with only one click to a link.

    Is it possible?
    And how it is?

    Thanks for help

    Bye
    Chris
      • 3749
      • 24,544 Posts
      It's definitely possible, though you have to be careful about security.

      If you install the Subscribe extra, you can include its unsubscribe.class.php file and use its utility functions in a snippet to generate a secure URL that sends them to a validation page. On that page, you can use another snippet that includes the unsubscribe class file again and use its functions to validate the user. Once you've validated the user, you can just do this:

      $pageId = 12; /* ID of the page you're ultimately sending them to */
      $user->addSessionContext('web');
      $url = $modx->makeUrl($pageId, "", "", "full");
      $modx->sendRedirect($url);
      return;


      Of course, you're free to create your own system for validating the user based on a hash sent as a parameter in the link, but I'd advise against using the user's password in that system. The Subscribe extra uses a hash involving the ID of the user's profile and their email, so if someone cracks it, the information can't be used to gain access to MODX.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 40706
        • 128 Posts
        To Log in an specific User, do your security things get the correct userid or username

        $modx->user = $modx->getObject('modUser', array('username' => $username )); 
        $modx->user->addSessionContext($modx->context->get('key'));