benbyf

session->login($u,$p); what can the $u be?

Recommended Posts

benbyf    506

quick question, can the $username in login() be email OR username, or anything else?

Share this post


Link to post
Share on other sites
adrian    7,670
6 minutes ago, benbyf said:

quick question, can the $username in login() be email OR username, or anything else?

Two options:

https://processwire.com/talk/topic/1716-integrating-a-member-visitor-login-form/?page=4#comment-89599

https://processwire.com/talk/topic/1716-integrating-a-member-visitor-login-form/?page=4#comment-89616

You should read about the pros and cons of each.

  • Like 1

Share this post


Link to post
Share on other sites
benbyf    506

Great options @adrian.

Strangely, I only asked as when login in with login() on my site it already allows either, which i thought was strange.

Share this post


Link to post
Share on other sites
adrian    7,670
2 hours ago, benbyf said:

Strangely, I only asked as when login in with login() on my site it already allows either, which i thought was strange.

Something sounds wrong there - are you sure you don't have something else that is handling the email to username check? I don't see anything in the login method to handle an email: https://github.com/processwire/processwire/blob/35df716082b779de0e53a3fcf7996403c49c9f8a/wire/core/Session.php#L704 and it doesn't work for me.

Share this post


Link to post
Share on other sites
benbyf    506

@adrian Could it be that if the name and email are the same but the sanitizer is changing @ to - and thus making them equivalent?

Share this post


Link to post
Share on other sites
benbyf    506

@adrian so i'm right in saying if the name is stored as e.g. yourname-web.com

then both yourname-web.com and yourname@web.com log me in.

Share this post


Link to post
Share on other sites
adrian    7,670
1 minute ago, benbyf said:

@adrian so i'm right in saying if the name is stored as e.g. yourname-web.com

then both yourname-web.com and yourname@web.com log me in.

That makes sense for sure. When I sent you those other links, I assumed that the usernames would be different to the email address.

  • Like 1

Share this post


Link to post
Share on other sites
suntrop    27
On 1/13/2017 at 2:42 PM, benbyf said:

ok, well something to bare in mind and maybe something that needs remedying or not. @ryan?

Would be nice to know, if you can use this as a feature :-) It would make a custom front-end login with email easier (if you make sure email-address updates are reflected to the username as well).

  • Like 1

Share this post


Link to post
Share on other sites
benbyf    506

using both at the moment to login, email and username created by PW out of the email.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By benbyf
      Is there a way to restrict logins for users so that one user can't be loggedin in two places at the same time?
      e.g. auto logout user after inactivity (of say 15 minutes..?), or logout action and disallow login if user still "logged in" somewhere?
    • By noelboss
      This module hooks into the login method to provide the possibility to login with the user's email address. This is my first module and it's very simple. Please provide feedback if you have any suggestions. Thanks
      The module can be found in the module repository:
      https://modules.processwire.com/modules/login-with-email/
      or on github:
      https://github.com/noelboss/LoginWithEmail
       
    • By Martin Muzatko
      Hello there!
      I want to create a user front-end (user can register/login/logout via templates)
      I'm working based on the intermediate site profile. So _init.php is loaded first, then the template file and then _main.php.
      I integrated the custom login as described here, and changed it to my needs. ( I don't want to redirect the user, if the form is filled in successfully)
      The problem I face, is that $user->isLoggedin() lags behind $session->login().
      Which means that whenever I do a login, I DO get the information that the login was successful ($session->login(...) instanceof User). I COULD use that information on _main.php to show a profile in the upper right corner.
      However I don't want to set a variable in the template and ask for it in _main.php. Are there any alternatives? Is a redirect really required to complete the session handling? Why? I have the same problem for the logout. The user is still displayed as logged in, when he opens the logout page.
      Thanks in advance.
      Best,
      Martin
    • By louisstephens
      I hope this is the correct place to post this. I currently am building a "dashboard" that displays some stats etc, but also handles login/logout with a form. Currently, when a user uses the form on the homepage, they redirected (if the credentials are correct) to the backend of processwire.
      However, I was hoping to direct the user back to the dashboard and display an alert (for now until I get a library to handle this). I got it somewhat working if I dont redirect the user. However, if I refresh the page, the alert still "pops up". Does anyone know of a way to redirect to the home page, but then display an alert?
      My Code to login:
      <?php if($input->post->user && $input->post->pass) { $user = $sanitizer->username($input->post->user); $pass = $input->post->pass; if($session->login($user, $pass)) { // login successful $session->redirect($dash); } } ?>  
    • By flydev
      OAuth2Login for ProcessWire
      A Module which give you ability to login an existing user using your favorite thrid-party OAuth2 provider (i.e. Facebook, GitHub, Google, LinkedIn, etc.)..
      You can login from the backend to the backend directly or render a form on the frontend and redirect the user to a choosen page.
      Built on top of ThePhpLeague OAuth2-Client lib.
      Registration is not handled by this module but planned.
       
      Howto Install
      Install the module following this procedure:
       - http://modules.processwire.com/modules/oauth2-login/
       - https://github.com/flydev-fr/OAuth2Login
      Next step, in order to use a provider, you need to use Composer to install each provider
      ie: to install Google, open a terminal, go to your root directory of pw and type the following command-line: composer require league/oauth2-google
      Tested providers/packages :
          Google :  league/oauth2-google     Facebook: league/oauth2-facebook     Github: league/oauth2-github     LinkedIn: league/oauth2-linkedin
      More third-party providers are available there. You should be able to add a provider by simply adding it to the JSON config file.

      Howto Use It
      First (and for testing purpose), you should create a new user in ProcessWire that reflect your real OAuth2 account information. The important informations are, Last Name, First Name and Email. The module will compare existing users by firstname, lastname and email; If the user match the informations, then he is logged in.
      ie, if my Google fullname is John Wick, then in ProcessWire, I create a new user  Wick-John  with email  johnwick@mydomain.com
      Next step, go to your favorite provider and create an app in order to get the ClientId and ClientSecret keys. Ask on the forum if you have difficulties getting there.
      Once you got the keys for a provider, just paste it into the module settings and save it. One or more button should appear bellow the standard login form.
      The final step is to make your JSON configuration file.
      In this sample, the JSON config include all tested providers, you can of course edit it to suit your needs :
      { "providers": { "google": { "className": "Google", "packageName": "league/oauth2-google", "helpUrl": "https://console.developers.google.com/apis/credentials" }, "facebook": { "className": "Facebook", "packageName": "league/oauth2-facebook", "helpUrl": "https://developers.facebook.com/apps/", "options": { "graphApiVersion": "v2.10", "scope": "email" } }, "github": { "className": "Github", "packageName": "league/oauth2-github", "helpUrl": "https://github.com/settings/developers", "options": { "scope": "user:email" } }, "linkedin": { "className": "LinkedIn", "packageName": "league/oauth2-linkedin", "helpUrl": "https://www.linkedin.com/secure/developer" } } }  
      Backend Usage
      In ready.php, call the module :
      if($page->template == 'admin') { $oauth2mod = $modules->get('Oauth2Login'); if($oauth2mod) $oauth2mod->hookBackend(); }  
      Frontend Usage
      Small note: At this moment the render method is pretty simple. It output a InputfieldForm with InputfieldSubmit(s) into wrapped in a ul:li tag. Feedbacks and ideas welcome!
      For the following example, I created a page login and a template login which contain the following code :
      <?php namespace ProcessWire; if(!$user->isLoggedin()) { $options = array( 'buttonClass' => 'my_button_class', 'buttonValue' => 'Login with {provider}', // {{provider}} keyword 'prependMarkup' => '<div class="wrapper">', 'appendMarkup' => '</div>' ); $redirectUri = str_lreplace('//', '/', $config->urls->httpRoot . $page->url); $content = $modules->get('Oauth2Login')->config( array( 'redirect_uri' => $redirectUri, 'success_uri' => $page->url ) )->render($options); }

       
      Screenshot