public function Run()
 {
     $username = '******';
     $pwd = '123456';
     $login = new LoginService();
     $registerNonce = $login->GetRegisterNonce();
     $this->AssertEquals(strlen($registerNonce->_nonce), 6, 'register nonce is not correct');
     /*
     $register = $login->Register($this->AddQuote($username)
     							, $this->AddQuote($pwd) 
     							, $this->AddQuote('*****@*****.**')
     							, $this->AddQuote($registerNonce->_sessionId)
     							, $this->AddQuote($registerNonce->_nonce));
     
     $this->AssertEquals($register->_returnCode, Constant\ErrorCode::OK, 'Register not successfully');
     
     
     
     $nonce = $login->GetNonce($this->AddQuote($username));
     	    $this->AssertEquals(strlen($nonce->_nonce), 6, 'Login not successfully');	
     	    
     $cnonce = "abcdef";
     
     $pwdfromclient = md5($nonce->_nonce.$cnonce.$decrypt);
     
     $result = $login->Login($username,$pwdfromclient,$cnonce);
     $this->AssertEquals($result->_returnCode, Constant\ErrorCode::OK, 'Login not successfully');		
     */
 }
Example #2
0
 /**
  *  Use Singleton pattern here
  *  @return object The instance of the class itself.
  */
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #3
0
 public function filterUserInfo($filterChain)
 {
     $productId = Yii::app()->user->getState('product');
     if (true != Yii::app()->user->isGuest && empty($productId)) {
         LoginService::setUserInfo();
     }
     $filterChain->run();
 }
Example #4
0
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $identity = new UserIdentity($this->username, $this->password);
         if (0 == $this->isapi) {
             $identity->authenticate();
         } else {
             $identity->apiAuthenticate();
         }
         switch ($identity->errorCode) {
             case UserIdentity::ERROR_NONE:
                 $accessableProducts = TestUserService::getAccessableProduct($identity->getId());
                 if (empty($accessableProducts)) {
                     $this->addError('username', Yii::t('LoginForm', 'no accessable product'));
                 } else {
                     $duration = 0;
                     if ($this->rememberMe) {
                         // keep login state duration
                         $duration = LoginForm::DURATION;
                     }
                     Yii::app()->user->login($identity, $duration);
                     UserLogService::createUserLog(array('created_by' => Yii::app()->user->id, 'created_at' => date(CommonService::DATE_FORMAT), 'ip' => $_SERVER['REMOTE_ADDR']));
                     LoginService::setLanguageCookie($this->language);
                 }
                 break;
             case UserIdentity::ERROR_USERNAME_INVALID:
                 $this->addError('username', Yii::t('LoginForm', 'username is incorrect'));
                 break;
             case UserIdentity::ERROR_CONNECT:
                 $this->addError('username', Yii::t('LoginForm', 'ldap connect failed'));
                 break;
             case UserIdentity::ERROR_USER_DISABLED:
                 $this->addError('username', Yii::t('LoginForm', 'user disabled'));
                 break;
             case UserIdentity::ERROR_LDAP_MISS:
                 $this->addError('username', Yii::t('LoginForm', 'ldap module disabled'));
                 break;
             case UserIdentity::ERROR_USER_NOT_FOUND:
                 $this->addError('username', Yii::t('LoginForm', 'user not found') . '&nbsp;<a href="' . Yii::app()->createUrl('site/permission') . '">' . Yii::t('LoginForm', 'permission tips') . '</a>');
                 break;
             default:
                 // UserIdentity::ERROR_PASSWORD_INVALID {
                 $this->addError('password', Yii::t('LoginForm', 'password is incorrect'));
                 break;
         }
     }
 }
Example #5
0
 public static function login($params)
 {
     $resultInfo = array();
     $model = new LoginForm();
     $model->attributes = $params;
     $model->username = trim($model->username);
     if ($model->validate()) {
         $setInfoResult = LoginService::setUserInfo();
         if (!empty($setInfoResult)) {
             $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
             $resultInfo['detail']['username'] = $setInfoResult;
         } else {
             $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
         }
     } else {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $model->getErrors();
     }
     return $resultInfo;
 }
Example #6
0
 /**
  * This is login function
  * 
  * @param string $sessionId
  * @param string $username
  * @param string $auth
  * @return array
  */
 public function login($sessionId, $username, $auth)
 {
     $timeout = time();
     $session = Yii::app()->getSession();
     $session->close();
     $session->setSessionID($sessionId);
     $session->open();
     $code = API::ERROR_USER_AUTH_FAILED;
     $info = Yii::t('API', 'user authenticate failed error info');
     $rand = $session->get(API::API_RAND_KEY);
     $user = TestUser::model()->findByAttributes(array('username' => $username));
     if (null !== $user) {
         if ($auth == $this->encrypt($username, $user->password, $rand)) {
             $code = API::ERROR_NONE;
             $info = '';
             $identity = new UserIdentity($username, $user->password);
             $identity->errorCode = UserIdentity::ERROR_NONE;
             $identity->setState('id', $user->id);
             $identity->setState('username', $username);
             Yii::app()->user->login($identity, 0);
             $timeout += $session->getTimeout();
             LoginService::setUserInfo();
             /*
              * CWebUser::login() function will call sesssion_regenrate_id() function
              * I dont konw why to do that right now and store the data to old session
              */
             $data = $_SESSION;
             $session->close();
             $session->setSessionID($sessionId);
             $session->open();
             foreach ($data as $key => $val) {
                 $_SESSION[$key] = $val;
             }
         }
     }
     return array($code, $info, $timeout);
 }
Example #7
0
<?php

/**
*   Demo of DataApi
*   
*       set your information in Config.php such as USERNAME, PASSWORD ... before use
*
*       especially, you can modify this Demo on your need!
*
*   @author Baidu Holmes
*/
require_once 'ProfileService.php';
require_once 'LoginService.php';
require_once 'ReportService.php';
require_once 'Config.php';
$loginService = new LoginService();
//preLogin
if (!$loginService->PreLogin()) {
    exit;
}
//doLogin
$ret = $loginService->DoLogin();
if ($ret) {
    $ucid = $ret['ucid'];
    $st = $ret['st'];
} else {
    exit;
}
//call get_trans_info method of profile service
$parameter = array();
if (QUERY_TRANS_TYPE == 'url') {
Example #8
0
 /**
  * Displays the login page
  */
 public function actionLogin()
 {
     $this->layout = '//layouts/blank';
     $model = new LoginForm();
     if (isset($_GET['language'])) {
         $model->language = $_GET['language'];
     } else {
         $cookies = Yii::app()->request->getCookies();
         if (!empty($cookies['language'])) {
             $model->language = $cookies['language']->value;
         }
     }
     // collect user input data
     if (isset($_POST['LoginForm'])) {
         $model->attributes = $_POST['LoginForm'];
         $result = LoginService::login($_POST['LoginForm']);
         if ($result['status'] == 'success') {
             $returnUrl = Yii::app()->user->returnUrl;
             $this->redirect($returnUrl);
         } else {
             $model->addErrors($result['detail']);
         }
     }
     $this->render('login', array('model' => $model));
 }
function isLogin($session)
{
    $loginService = new LoginService();
    return $loginService->isSessionKeyValid($session);
}
<?php

require '../base/Config.php';
Config::init();
$service = new LoginService();
$service->init();
if (isset($_POST["username"]) === false || isset($_POST["password"]) === false || isset($_POST["game"]) === false) {
    $service->error("login", 1);
}
$username = $_POST["username"];
$password = $_POST["password"];
$game = $_POST["game"];
if (!is_numeric($game)) {
    $service->error("login", 2);
}
error_log($username . "-" . $password . "-" . $game);
if ($service->login($username, $password, $game)) {
    $token_service = new TokenService();
    $token_service->init();
    $length = 16;
    $token = Common::createToken($length);
    $account = $username . "_enjoymi";
    $token_service->writeToken($account, $game, $token);
    $service->error("login", "0," . $account . "," . $token);
} else {
    $service->error("login", 4);
}
        }
</script>
</head>
<body>
<?php 
session_start();
if (isset($_GET['logout'])) {
    unset($_SESSION['admin']);
}
global $msg;
if (isset($_POST['txtAdminName'])) {
    require_once '../inc/BusinessLayer.inc.php';
    $username = $_POST['txtAdminName'];
    $password = $_POST['txtPassword'];
    try {
        $service = new LoginService();
        $result = $service->getRow($username, $password);
        if ($result) {
            $_SESSION["admin"] = $result;
            header("Location: Main.php");
        } else {
            $msg = 'User name or password is incorrect!';
        }
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}
?>
<div id="body_wrapper">
<div id="wrapper">
<div id="header">
 /**
  * 聊天室主页面
  */
 public function index()
 {
     $user = LoginService::checkLogin();
     $this->out['user'] = $user;
 }