Author Topic: Auto login after account activation  (Read 7591 times)

0 Members and 1 Guest are viewing this topic.

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Auto login after account activation
« on: October 05, 2009, 05:31:08 PM »
Does anyone have idea how to set that users will be automatically logged in when they active their account?

Offline impss

  • Sr. Member
  • ****
  • Posts: 382
    • View Profile
    • Cusstom.net
Re: Auto login after account activation
« Reply #1 on: October 06, 2009, 03:57:55 AM »

In register.php


Find:
Code: [Select]
    $activationkey = trim($HTTP_GET_VARS['activationkey']);
    $sql = "SELECT ".get_user_table_field("", "user_name").get_user_table_field(", ", "user_email").get_user_table_field(", ", "user_activationkey")."
            FROM ".USERS_TABLE."
            WHERE ".get_user_table_field("", "user_activationkey")." = '$activationkey'";

Replace with:
Code: [Select]
    $activationkey = trim($HTTP_GET_VARS['activationkey']);
//Start Auto-login After Activation
    $sql = "SELECT ".get_user_table_field("", "user_name").get_user_table_field(", ", "user_password").get_user_table_field(", ", "user_email").get_user_table_field(", ", "user_activationkey")."
            FROM ".USERS_TABLE."
            WHERE ".get_user_table_field("", "user_activationkey")." = '$activationkey'";
//End Auto-login After Activation

Find:
Code: [Select]
        $site_email->set_body("activation_success", $config['language_dir']);
        $site_email->send_email();
      }

After Add:
Code: [Select]
  //Start Auto-login After Activation
  if ($site_sess->login($row['user_name'], $row['user_password'], 1, 1, 1)) {
    redirect("index.php");
  }
  //End Auto-login After Activation

In includes / sessions.php

Find:
Code: [Select]
  function login($user_name = "", $user_password = "", $auto_login = 0, $set_auto_login = 1) {
Replace With:
Code: [Select]
  function login($user_name = "", $user_password = "", $auto_login = 0, $set_auto_login = 1, $activate= 0) {
Find:
Code: [Select]
    $user_password = md5($user_password);
Replace with:
Code: [Select]
//Start Auto-login After Activation
    $user_password = ($activate == 0) ? md5($user_password) : $user_password;
//End Auto-login After Activation

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Auto login after account activation
« Reply #2 on: October 06, 2009, 04:16:44 AM »
And in case gallery doesn't have activation, in register.php find:
        $msg $lang['register_success_none'];


insert below:
//Start Auto-login After Activation
        
if ($site_sess->login($user_name$user_password111))
        {
          
$msg .= '<meta http-equiv="refresh" content="10;url='.$site_sess->url(ROOT_PATH."index.php").'">';
        }
//End Auto-login After Activation

It should redirect to index page after 10 seconds.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Auto login after account activation
« Reply #3 on: October 06, 2009, 11:32:40 AM »
Thx guys!

One thing... how safe is to modify this? I mean if I register with public computer and browser save your url with activation link. Will other user be able to log in if he enters that url even if I log off that computer?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Auto login after account activation
« Reply #4 on: October 06, 2009, 03:22:00 PM »
Yes, that's a good point.

if you replace
    $sql "SELECT ".get_user_table_field("""user_name").get_user_table_field(", ""user_email").get_user_table_field(", ""user_activationkey")."
            FROM "
.USERS_TABLE."
            WHERE "
.get_user_table_field("""user_activationkey")." = '$activationkey'";
    
$row $site_db->query_firstrow($sql);
    if (!
$row) {
      
$msg $lang['invalid_activationkey'];
    }


with:
    $sql "SELECT ".get_user_table_field("""user_name").get_user_table_field(", ""user_email").get_user_table_field(", ""user_activationkey").get_user_table_field(", ""user_level")."
            FROM "
.USERS_TABLE."
            WHERE "
.get_user_table_field("""user_activationkey")." = '$activationkey'";
    
$row $site_db->query_firstrow($sql);
    if (!
$row) {
      
$msg $lang['invalid_activationkey'];
    }
    elseif (
$row['user_level'] != USER_AWAITING)
    {
      
redirect("index.php");
    }


Then only first visit via activation link will log you in, all others will simply redirect to home page. And also, replace
$site_sess->login($user_name$user_password111)
with:
$site_sess->login($user_name$user_password011)
it will log you in without "auto login"
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Auto login after account activation
« Reply #5 on: October 07, 2009, 05:03:34 PM »
Thanks for helping me, but I think this isn't working.

Even only with impss's code it doesn't :( This one is working ;)

Can someone else please try it, maybe there is something wrong with my modificated 4images?

v@no, where should I change this:
Code: [Select]
$site_sess->login($user_name, $user_password, 0, 1, 1)
Edited:

I think this is the right one:

Code: [Select]
//Start Auto-login After Activation
    $sql = "SELECT ".get_user_table_field("", "user_name").get_user_table_field(", ", "user_password").get_user_table_field(", ", "user_email").get_user_table_field(", ", "user_activationkey").get_user_table_field(", ", "user_level")."
            FROM ".USERS_TABLE."
            WHERE ".get_user_table_field("", "user_activationkey")." = '$activationkey'";
//End Auto-login After Activation

Code: [Select]
if ($site_sess->login($row['user_name'], $row['user_password'], 0, 1, 1)) {
Correct?
« Last Edit: October 07, 2009, 05:21:04 PM by Lucifix »

Offline V@nо

  • Addicted member
  • ******
  • Posts: 1.223
    • View Profile
Re: Auto login after account activation
« Reply #6 on: October 07, 2009, 05:23:06 PM »
v@no, where should I change this:
Code: [Select]
$site_sess->login($user_name, $user_password, 0, 1, 1)
in the code you just added.
But, I didn't realize imps' code a little different, in their code you'll need replace
	
  if (
$site_sess->login($row['user_name'], $row['user_password'], 111)) {

with
	
  if (
$site_sess->login($row['user_name'], $row['user_password'], 011)) {


to remove auto login
Your first three "must do" before you ask a question:
If I asked you to PM me, I meant PM to my primary account, this account doesn't accept PMs.

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Auto login after account activation
« Reply #7 on: October 07, 2009, 05:33:27 PM »
Yup it's working just fine :) Thx!

Maybe someone should post this in topic Mods & Plugins (Releases & Support)