Get me outta here!

BLOG @ Erman Gülhan

Clean Code Driven Software Developer

Menu

Skip to content
  • Home
  • Contact

Monthly Archives: December 2014

How to set non-selected text in bootstrap-multiselect plugin

December 19, 2014 by admin

You need to set nonSelectedText to do this. Take a look the following example:

Html Javascript bootstrapmultiselectnonselectedtext Leave a comment

How to provide login mechanism with minimal code changes using Yii Framework

December 8, 2014 by admin

Hi all.

I’m going to tell how to provide login mechanism to your sites by using Yii Framework.

Requirements

  • Yii Framework 1.x (I used version 1.1.15: https://github.com/yiisoft/yii/releases/download/1.1.15/yii-1.1.15.022a51.tar.gz)
  • A web application created by Yii (http://www.yiiframework.com/doc/guide/1.1/en/quickstart.first-app)

1) Authentication

Modify protected/components/UserIdentity.php as the following:

class UserIdentity extends CUserIdentity
{
	/* ... */
	public function authenticate()
	{
		$user=User::model()->find(array(
			'condition'=>'username=:uname',
			'params'=>array(':uname'=>$this->username),
		));

		/**
		 * NOTE: You should hash your passwords via CPasswordHelper::hashPassword($this->password)
		 * before saving to DB
		 */
		if($user && CPasswordHelper::verifyPassword($this->password,$user->password))
			$this->errorCode=self::ERROR_NONE;
		else
			$this->errorCode=self::ERROR_PASSWORD_INVALID;

		return !$this->errorCode;
	}
	/* ... */
}

2) Controllers

2.1) Base controller

Modify protected/components/Controller.php as the following:

class Controller extends CController
{
	/* ... */
	public function filters()
	{
		return array('accessControl');
	}

	public function accessRules()
	{
		return array(
			array('allow','users'=>array('@')),
			array('deny','users'=>array('?'))
		);
	}
	/* ... */
}

2.2) SiteController

Modify protected/controllers/SiteController.php as the following:

class SiteController extends Controller
{
	/* ... */

	public function accessRules()
	{
		return array(
			array('allow','users'=>array('@')),
			array('allow','actions'=>array('login','logout'),'users'=>array('*')),
			array('deny','users'=>array('*')),
		);
	}

	/* ... */
}

2.3) Other controllers

You should remove accessRules and filters functions from other controllers.

If you want to use filters in your other controllers, you should use it like the following way:

public function filters()
{
	return array_merge(parent::filters(),array(
		'postOnly + delete',
	));
}

 

That’s all. Happy coding!

Php Yii Framework access-controlaccess-rulesloginyiiyii-filters Leave a comment

Post navigation

Recent Posts

  • How to Restart Supervisor Workers
  • How to Set Raw, html text for checkbox – radio labels when used symfony form builder
  • Wamp Server Yüklerken Eksik VCRUNTIME140.dll ve MSVCR110.dll Dosyaları Hatası
  • How to use alias table name with CDbCriteria using Yii Framework
  • How to set timezone to Europe/Istanbul on Linux servers

Recent Comments

    Archives

    • August 2019
    • May 2019
    • May 2017
    • October 2015
    • September 2015
    • July 2015
    • April 2015
    • March 2015
    • February 2015
    • December 2014
    • November 2014
    • October 2014
    • September 2014
    • August 2014
    • July 2014
    • June 2014
    • May 2014
    • April 2014
    • March 2014
    • February 2014
    • January 2014
    • December 2013
    • November 2013
    • October 2013
    • September 2013
    • August 2013
    • July 2013
    • June 2013
    • May 2013
    • February 2013
    • January 2013
    • December 2012
    • November 2012
    • April 2012
    • March 2012
    • January 2012

    Categories

    • android
    • Apache
    • CodeIgniter
    • Common
    • debian
    • Elasticsearch
    • git
    • Html
    • Javascript
    • JQuery
    • Linux
    • mysql
    • Php
    • Postgresql
    • Regex
    • Shell
    • SQL
    • Svn
    • symfony
    • twig
    • Uncategorized
    • Vim
    • Yii Framework

    Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
    Proudly powered by WordPress | Theme: Something Fishy by Caroline Moore.