Posts Tagged with use

Displaying 1-10 of 10 results.
Resolved: SSH: connect to host 'ip address' port 22: connection refused
posted by admin on July 21, 2017
I try to connect with SSH

$ ssh root@123.123.123.123

and get error like

SSH: connect to host 'ip address' port 22: connection refused
Read more
Resolved: Odnoklassniki OK api apiok users.getInfo all fields without errors
posted by admin on April 17, 2017
I try to get all allowed fields from user by id, and got some error

{
error_code:100
error_msg:PARAM : Invalid parameter fields value : [accessible,age,allows_anonym_access,allows_messaging_only_for_friends,birthday,blocked,blocks,can_vcall,can_vmail,capabilities,common_friends_count,current_location,current_status,current_status_date,current_status_date_ms,current_status_id,current_status_track_id,email,feed_subscription,first_name,friend,friend_invitation,gender,has_email,has_service_invisible,invited_by_friend,is_activated,last_name,last_online,last_online_ms,location,login,modified_ms,name,notifications_subscription,online,photo_id,pic1024x768,pic128max,pic128x128,pic180min,pic190x190,pic224x224,pic240min,pic288x288,pic320min,pic50x50,pic600x600,pic640x480,pic_1,pic_2,pic_3,pic_4,pic_5,pic_base,pic_full,pic_max,premium,presents,private,ref,registered_date,registered_date_ms,relationship,show_lock,uid,url_chat,url_chat_mobile,url_profile,url_profile_mobile,vip]
error_data:null
}

All fields I got from apiok official page

[{
accessible:Boolean
age:Integer
allows_anonym_access:Boolean
allows_messaging_only_for_friends:Boolean
birthday:String
blocked:Boolean
blocks:Boolean
can_vcall:Boolean
can_vmail:Boolean
capabilities:String
common_friends_count:Integer
current_location:{
altitude:Float
cellId:Integer
city:String
country:String
ipAddress:String
latitude:Float
longitude:Float
}
current_status:String
current_status_date:Date
current_status_date_ms:Long
current_status_id:String
current_status_track_id:String
email:String
feed_subscription:Boolean
first_name:String
friend:Boolean
friend_invitation:Boolean
gender:String
has_email:Boolean
has_service_invisible:Boolean
invited_by_friend:Boolean
is_activated:Boolean
last_name:String
last_online:String
last_online_ms:Long
locale:String
location:{
city:String
country:String
countryCode:String
countryName:String
}
login:String
modified_ms:Long
name:String
notifications_subscription:Boolean
online:String
photo_id:String
pic1024x768:String
pic128max:String
pic128x128:String
pic180min:String
pic190x190:String
pic224x224:String
pic240min:String
pic288x288:String
pic320min:String
pic50x50:String
pic600x600:String
pic640x480:String
pic_1:String
pic_2:String
pic_3:String
pic_4:String
pic_5:String
pic_base:String
pic_full:String
pic_max:String
premium:Boolean
presents:[{}]
private:Boolean
ref:String
registered_date:Date
registered_date_ms:Long
relations:[{}]
relationship:{}
show_lock:Boolean
uid:String
url_chat:String
url_chat_mobile:String
url_profile:String
url_profile_mobile:String
vip:Boolean
}]
Read more
Resolved: Yii2 Error Exception: Class 'Custom class' not found
posted by admin on February 15, 2017
I use in migration classes custom helper class Table, and in migration up process got an error like
Command:

./yii migrate

Result until error

Yii Migration Tool (based on Yii v2.0.11.2)

Total 2 new migrations to be applied:
m170213_124818_init
m170214_092410_domain

Apply the above migrations? (yes|no) [no]:yes
*** applying m170213_124818_init


Error Message:

Exception: Class 'yii\helpers\Table' not found (/var/www/html/basic/migrations/m170213_124818_init.php:10)


My class is in root directory in helpers directory

<?php
namespace yii\helpers;
class Table
{
public static $user = 'user';
public static $role = 'role';
public static $status = 'status';
public static $domain = 'domain';
}


In migration class

<?php
use yii\db\Migration;
use yii\helpers;

class m170213_124818_init extends Migration
{
public function safeUp()
{
/** User Create*/
$this->createTable('{{%'.helpers\Table::$user.'}}', [
'id' => $this->primaryKey(10)->notNull()->unsigned(),
. . .
], 'ENGINE=InnoDB');
}
}


How to resolve itRead more
Resolved: Yii2 Helper folder, helper namespace, helper class
posted by admin on February 14, 2017
In yii1 I created helpers folder in public and move all my helper classes and autoload them from main.php setting file

// autoloading model and component classes
'import'=>array(
...
'application.helper.*',
),

I have three questions

  1. Where create helpers classes folder
  2. How to create helpers classes
  3. How to autoload or use helpers classes
Read more
Resolved: Ubuntu Linux remove directory from root var/www directory problem
posted by admin on February 7, 2017
I try to remove folder but terminal gave error
Command and error

rm -rf /var/www/website.dev
rm: cannot remove '/var/www/website.dev': Permission denied

I try to did it before this command and the same situation

sudo chmod -R 777 /var/www/website.dev

I try to make my user superuser but still without result

sudo adduser <username> www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rwX /var/www
Read more
Resolved: Javascript body onclick function event
posted by admin on December 15, 2016
I have a function and onmousemove event in body attribute.
JS

function mouseShowHandler(e){

e = e || window.event


if (e.pageX == null && e.clientX != null ) {

var html = document.documentElement

var body = document.body

e.pageX = e.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)

e.pageY = e.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)



}
xx=e.pageX
yy=e.pageY
}


HTML

...
<body onmousemove="mouseShowHandler(event)">
...

It is working fine, But I want to event handler to my script file, and remove from bodyRead more
Resolved: Hosting iPage.com MySQL connection error: SQLSTATE[HY000] [2002] Connection refused
posted by admin on November 11, 2016
I am trying to run my Yii 1 website and connect to DB, which is not in my hosting iPage.com and have this error:

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Connection refused

For example, my MySQL config in iPage.com working fine
protected/config/database.php

<?php
return array(
'connectionString' => 'mysql:host=*******.ipagemysql.com;dbname=somename',
'emulatePrepare' => true,
'username' => 'someuser',
'password' => 'somepassword',
'charset' => 'utf8',
);

Another server connection and error
protected/config/database.php

<?php
return array(
'connectionString' => 'mysql:host=anotherhostname;dbname=somename',
'emulatePrepare' => true,
'username' => 'someuser',
'password' => 'somepassword',
'charset' => 'utf8',
);

Error:

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Connection refused
Read more
Wiki: Yii 1.1 Аутентификация и авторизация. Authentication and authorization. UserIdentitywiki
posted by admin on March 24, 2016
1. Определение класса Identity. Defining Class Identity
Edit your components/UserIdentity.php

class UserIdentity extends CUserIdentity
{
private $_id;
public function authenticate()
{
$record=User::model()->findByAttributes(array('username'=>$this->username));
if($record===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if(!CPasswordHelper::verifyPassword($this->password,$record->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$record->id;
$this->setState('title', $record->title);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}

public function getId()
{
return $this->_id;
}
}


2. controllers/SiteController.php, add

class SiteController extends Controller
{
...
public function filters()
{
return array(
'accessControl',
);
}
...
}


3.Check models/LoginForm.php

<?php

/**
* LoginForm class.
* LoginForm is the data structure for keeping
* user login form data. It is used by the 'login' action of 'SiteController'.
*/
class LoginForm extends CFormModel
{
public $username;
public $password;
public $rememberMe;

private $_identity;

/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
public function rules()
{
return array(
// username and password are required
array('username, password', 'required'),
// rememberMe needs to be a boolean
array('rememberMe', 'boolean'),
// password needs to be authenticated
array('password', 'authenticate'),
);
}

/**
* Declares attribute labels.
*/
public function attributeLabels()
{
return array(
'rememberMe'=>'Remember me next time',
);
}

/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute,$params)
{
if(!$this->hasErrors())
{
$this->_identity=new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate())
$this->addError('password','Incorrect username or password.');
}
}

/**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
return false;
}
}


4. Create models/User.php
4.1. Activate GII module
Go to config/main.php and uncomment the following rows

'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'o55is88oois',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),


4.2. Go to GII module

http://avaim.ru/index.php?r=gii


4.3. Generate your User.php model, from your users table

4.4. Add to User.php

public function validatePassword($password)
{
return CPasswordHelper::verifyPassword($password,$this->password);
}

public function hashPassword($password)
{
return CPasswordHelper::hashPassword($password);
}


5. Insert user to your users table and enjoy
For example, insert into your users table row
Username: admin
Password HASH: $2y$13$imm.m0q9qN/IrWF4AtmH4ejHyS3d.ElmkayY3vQ69DTApgEY4ne36

6. Login to your website
Go to your_website/index.php?r=site/login and login
Username: admin
Password HASH: 123

Enjoy ;)Read more
Wiki: Yii 1.1: More information to Yii::app() user - id, userrole etc.wiki
posted by admin on March 2, 2016
By default, the expression Yii::app()->user returns a CWebUser application component which represents the information that are closely related with the current user. Some information can be persistent throughout the current user session. For example, CWebUser already comes with a name property that stores the username of the current user.

In order to store more information, we need to modify the identity class used together with CWebUser. Each application may have one or several identity classes which are mainly responsible to provide ways of performing user authentication.

Here we use the UserIdentity class included in the testdrive application as an example, assuming our goal is to add the ID and the last login time of the user to CWebUser. We would modify UserIdentity as follows,


class UserIdentity extends CUserIdentity
{
private $_id;

public function authenticate()
{
$user=User::model()->findByAttributes(array('username'=>$this->username));
if($user===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if($user->password!==md5($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$user->id;
$this->setState('userrole', $user->userrole_id);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}

public function getId()
{
return $this->_id;
}
}


In the above, during authentication we retrieve the ID and the last login time information of the authenticated user. We save the ID in a private variable $_id and save lastLoginTime in a state by calling setState(). The reason that we use different approaches to save id and lastLoginTime is because id is a pre-defined property that is recognized by CWebUser. If we want to store more information, we should use setState(), like we do with lastLoginTime.

We also override the getId() method to return the private variable $_id. The parent implementation is to return the username.

That's all we need. Now if we want to retrieve the id or lastLoginTime information in our code, we can do the following:

$id=Yii::app()->user->id;
$userrole=Yii::app()->user->userrole;
Read more
Resolved: Русский текст в транслит на PHP(Rus to Lat)
posted by admin on December 25, 2015
The last segment is actually the friendly title of the blog article. The problem is when I try to pass that segment to the database, the cyrillic fonts turn into something like %D1%8A%D0%B4%D1%80%D0%BE%D1%81%D1%8 and couldn't match the database record. In the address bar in my browser it looks normal (мъдростта-на-вековете) but if I choose 'copy url location' the last segment again turns into these strange characters.

Please help to convert cyrillic to english letters(lat)Read more