Yii Framework Forum: login - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

login login as homepage Rate Topic: -----

#1 User is offline   Elizabeth Arriaga 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 09-October 17

Posted 11 October 2017 - 08:59 AM

Hello! I am starting with yii framework I am programming in version 1.9 and what I try to do is that my main page is the login, and when a user is logged in I redirect to the project forms with their permissions of each user

this is my login code:
<?php
/* @var $this SiteController */
/* @var $model LoginForm */
/* @var $form CActiveForm  */



?>
<style>

body h1{
  
  
  font-style:oblique;
  font-weight:bold;
  font-size:4em;
  font-color:#C49AFF;
  font-family:'Helvetica','Verdana','Monaco',sans-serif;
}

body{
	top: -20px;
	left: -20px;
	right: -40px;
	bottom: -40px;
	width: auto;
	height: auto;
	
	background-image: url(fondo.jpg);
	background-size: cover;
	
	
}



</style>
<font color="White">
<h1>Login</h1>


<div class="form-horizontal">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'login-form',
	'enableClientValidation'=>true,
	'clientOptions'=>array(
		'validateOnSubmit'=>true,
	),
	'action' => array("site/login"),
    )); ?>

	

<div class="control-group">
		<?php echo $form->labelEx($model,'username', array('class'=>'control-label')); ?>
		<div class="controls">
			<?php echo $form->textField($model,'username'); ?>
	    	<?php echo $form->error($model,'username'); ?>
		</div>
	</div>
	<div class="control-group">
		<?php echo $form->labelEx($model,'password', array('class'=>'control-label')); ?>
		<div class="controls">
			<?php echo $form->passwordField($model,'password'); ?>
			<?php echo $form->error($model,'password'); ?>
		</div>
		
	</div>

	

	<div class="control-group ">
		<div class="controls">
         	<?php echo CHtml::submitButton('Login', array('class'=>'btn btn-primary')) ?>
		     <a href="#" class="facebook_connect radius button facebook"><i class="fa fa-facebook-square"></i>			
		</div>
	</div>

<?php $this->endWidget(); ?>
</div><!-- form -->


and this is my SiteController:
public function actionLogin()
	{
		
		$model=new LoginForm;

		// if it is ajax validation request
		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}

		// collect user input data
		if(isset($_POST['LoginForm']))
		{
			$model->attributes=$_POST['LoginForm'];
			// validate user input and redirect to the previous page if valid
			if($model->validate() && $model->login());
				$this->redirect(Yii::app()->user->returnUrl);
		}
		// display the login form
		$this->render('login',array('model'=>$model));
	}

In advance thanks for the help
0

#2 User is offline   Fabrizio Caldarelli 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,059
  • Joined: 21-March 13
  • Location:Rome, Italy

Posted 11 October 2017 - 09:32 AM

What's the question?
Yii2 by example: my book about Yii2
https://www.packtpub...nt/yii2-example
0

#3 User is offline   Elizabeth Arriaga 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 09-October 17

Posted 12 October 2017 - 05:27 PM

how can I do so that by clicking the login button I redirected to a form or another page?
0

#4 User is offline   dragan.zivkovic 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 13-September 12

Posted 16 October 2017 - 05:35 AM

All you need is to set redirection url (one that you want user to redirect). Something like :

if($model->validate() && $model->login());
    $this->redirect('controller/action');
}

1

#5 User is offline   Elizabeth Arriaga 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 09-October 17

Posted 17 October 2017 - 02:29 PM

thank you very much :D
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users