Jump to content
4.4.3
Sign in to follow this  
Stinger2015

Авторизация с другой страницы

Recommended Posts

Stinger2015

Суть проблемы следующая, я использовал для входа с другой страницы следующую функцию.

 

function doLogin( $username, $password, $rememberMe=true, $anonymous=false )
{
    
    $login = new \IPS\Login( \IPS\Http\Url::internal('') );
    $login->forms();
    
    try{
        $member = $login->authenticateStandard(array(
            'auth'     => $username,
            'password' => $password,
        )); 
    }
    
    
    catch( \IPS\Login\Exception $e )
    {
        return false;
    }
    
    if ( $anonymous and !\IPS\Settings::i()->disable_anonymous )
    {
        \IPS\Session::i()->setAnon();
        \IPS\Request::i()->setCookie( 'anon_login', 1 );
    }
    
    \IPS\Session::i()->setMember( $member );
    
    if ( $rememberMe )
    {
        $expire = new \IPS\DateTime;
        $expire->add( new \DateInterval( 'P7D' ) );
        \IPS\Request::i()->setCookie( 'member_id', $member->member_id, $expire );
        \IPS\Request::i()->setCookie( 'login_key', $member->member_login_key, $expire );

        if ( $anonymous and !\IPS\Settings::i()->disable_anonymous )
        {
            \IPS\Request::i()->setCookie( 'anon_login', 1, $expire );
        }
    }

   $member->memberSync( 'onLogin', array( \IPS\Login::getDestination() ) ); 
  
   return $member;
}

Так вот после перехода на 4.3.x - функция не работает! Буду благодарен за вашу помощь.

Share this post


Link to post
Share on other sites
anufmikh
function doLogin( $username, $password, $rememberMe = TRUE, $anonymous = TRUE )
{
	$method = \IPS\Login\Handler::load( 1 );
	$login = new \IPS\Login( \IPS\Http\Url::internal( '' ) );

	try
	{
		$member = $method->authenticateUsernamePassword( $login, $username, $password );
	}
	catch( \IPS\Login\Exception $e )
	{
		return FALSE;
	}

	return $member;
}

 

Share this post


Link to post
Share on other sites
Stinger2015

Большое спасибо anufmikh, что хотел помочь , решилось таким путём.

function doLogin( $username, $password ){
	
	$member_login = \IPS\Member::load( $username, 'name' );
	
		if ( $member_login->member_id ){
			
		$member = \IPS\Login\Handler::findMethod( 'IPS\Login\Handler\Standard' )->authenticatePasswordForMember( $member_login, $password);	
				
			if ( $member ){
				
			$device = \IPS\Member\Device::loadOrCreate( $member_login );
			$device->updateAfterAuthentication( TRUE );
			
			return "ok";
			
			}
			else
			{
				
			return "incorrect_password";
				
			}
	
		}
		else
		{
			
		return "user_not_exist";	
			
		}
	
	}

 

Edited by Stinger2015

Share this post


Link to post
Share on other sites
Stinger2015

Теперь проблема следующая, при входе, не удаётся получить вот это:

\IPS\Dispatcher\Build::i();
$lang = \IPS\Lang::load( \IPS\Lang::defaultLanguage() );
$member = \IPS\Member::loggedIn();
$member_id = $member->member_id;
$name = $member->name;
$photo = $member->photo;
$group_id = $member->member_group_id;
$group_name = $member->groupName;
$email_ipb = $member->email;
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $group_name );    

 

Это всё удаётся получить если зайти на форум и обновить страницу  БАНАЛЬНО)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...