4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: Lucifix on October 05, 2009, 05:31:08 PM

Title: Auto login after account activation
Post by: Lucifix 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?
Title: Re: Auto login after account activation
Post by: impss 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
Title: Re: Auto login after account activation
Post by: V@no 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_password, 1, 1, 1))
        {
          $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.
Title: Re: Auto login after account activation
Post by: Lucifix 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?
Title: Re: Auto login after account activation
Post by: V@no 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_password, 1, 1, 1)
with:
$site_sess->login($user_name, $user_password, 0, 1, 1)
it will log you in without "auto login"
Title: Re: Auto login after account activation
Post by: Lucifix 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?
Title: Re: Auto login after account activation
Post by: V@nо 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'], 1, 1, 1)) {

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


to remove auto login
Title: Re: Auto login after account activation
Post by: Lucifix 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)