Two Login Function in a app

I want to create two login in my app

One will be the login which comes with every app

and second one i want to create should ask for only username and should login if the username is valid.

So i created a form login with a model class in which the username is stored.

now i want to know how to do the validation?

Can someone help me.

yes for this you can use same controller and model but just use different view file and another function in controller.

just do same code as you have done in UserIdentity.php file ( if you using that file for authentication )

and same code as original login function …

it takes little modification in code but most things remain same.

Yes i have used the same model file… but different controller and diff view file…

Now i want to know the action to be given to validate it in controller

yes i am telling that function in controller will be mixture of UserIdentity file and your login function in controller.

so are u saying to use the useridentity code inside my controller action?

like…





public function actionLogin()

{

    $model=new PsmsUserAccInfo('login');





    if(isset($_POST['PsmsUserAccInfo']))

    {

        $model->attributes=$_POST['PsmsUserAccInfo'];

        if($model->validate())

        {

            $user=PsmsUserAccInfo::model()->findByAttributes(array('username'=>$this->username));

		if ($user===null) { // No user found!

		                   $this->_id='user Null';


			$this->errorCode=self::ERROR_USERNAME_INVALID;

		                    } 

		$this->_id = $user->id;

		}

		return !$this->errorCode;

	}

           

            return;

        }

    }

    $this->render('login',array('model'=>$model));

}

you can use code like ,


 public function yourNewFunction()

   {

       ..

       ..

       $record=Employee::model()->findByAttributes(array('E_EMAIL'=>$this->username));

       ..

       ..

       if($record->username!== $this->username)

               {        

                       $this->_id=$this->username;

                       $this->errorCode=self::ERROR_PASSWORD_INVALID;

               }

	         else if($record['STATUS']!=='Active')           //      extra code for user status

               {        

			   	$err = "You have been Inactive by Admin.";

			        $this->errorCode = $err;

               }

              ...

              ...


public function actionLogin()

{

    $model=new PsmsUserAccInfo('login');


    if(isset($_POST['PsmsUserAccInfo']))

    {

        $model->attributes=$_POST['PsmsUserAccInfo'];

        if($model->validate())

        {

          $user = PsmsUserAccInfo::model()->findByAttributes(array('username'=>$this->username));

		      if ($user->username!== $this->username) 

			  			{ 

		                   $this->_id=$this->username;

							$this->errorCode=self::ERROR_USERNAME_INVALID;

								}

            return;

        }

    }

    $this->render('login',array('model'=>$model));

}

Property "PsmsEmpInfoController.username" is not defined.

please use,


print_r($_POST['PsmsUserAccInfo']);

and see what data posted.

For checking i replaced the action with the above print command and got

Array ( [username] => emil ) as output

Where have you defined the actionLogin function? It seems you have defined it in PsmsEmpInfoController class.

Because of which


 $user = PsmsUserAccInfo::model()->findByAttributes(array('username'=>$this->username));

gives the exception.

$this refers to the instance of the class in which the method is defined. You have got your code mixed up in the wrong classes

yes i have defined inside PsmsEmpInfoController… whr else should i define it??

Ok i changed my new action from PsmsEmpInfoController to siteController even when i know that there is gona be no big difference.

But now what i think is… i should make duplicate of LoginForm model and useridentity for my usage.

Is that the only way to proceed??

Guys can someone plssss help me…

You can use the same loginForm, just use a different scenario.

Take a look here about it.

Yes i have made different login scenario form and connected with the userlogin db.

Chck my coding here

My Coding

The error is:


   if ($user->username!== $this->username) 



It should be:


   if ($user->username!== $model->username) 

It’s Giving a error

[b]

Property "SiteController.username" is not defined. [/b]

Also 2 lines forward there is:


$this->_id=$this->username;



The same stuff. $this in this case is the controller, the model is in $model, so wherever you have $this->username you have to change to $model->username.

After changing the coding to


if(isset($_POST['PsmsUserAccInfo']))

    {

		

        $model->attributes=$_POST['PsmsUserAccInfo'];

        if($model->validate())

        {

          $user = PsmsUserAccInfo::model()->findByAttributes(array('username'=>$model->username));

		  print_r($user);

		      if ($user->username!== $model->username) 

			  			{ 

						

		                   $model->_id=$model->username;

							$this->errorCode=self::ERROR_USERNAME_INVALID;

								}

            return;

        }

    }

    $this->render('login1',array('model'=>$model));

}

	

Error

[b] Property "PsmsUserAccInfo._id" is not defined.

[/b]